

from importlib import import_module

from .logging import get_logger


__A      		=     get_logger(__name__)



class   lowercase_   :



      def __init__(      self				:    List[Any]      , A__				:    Any      , A__				:    str=None		)   ->					str:
        _snake_case						=							attrs or []
        if module is not None:
          for key in module.__dict__:
            if key in attrs or not key.startswith('''__'''		):
              setattr(self      , A__      , getattr(A__      , A__		)		)
        _snake_case						=							module._original_module if isinstance(A__      , _PatchedModuleObj		) else module



class   lowercase_   :
      UpperCamelCase_      :		Tuple										=    []



      def __init__(      self				:    Any      , A__				:    Optional[int]      , A__				:    str      , A__				:    Optional[Any]      , A__				:    int=None		)   ->					Tuple:
        _snake_case						=							obj
        _snake_case						=							target
        _snake_case						=							new
        _snake_case						=							target.split('''.'''		)[0]
        _snake_case						=							{}
        _snake_case						=							attrs or []



      def __enter__(      self				:    List[str]		)   ->					int:
        *_snake_case,					_snake_case						=							self.target.split('''.'''		)

        # Patch modules:
        # it's used to patch attributes of submodules like "os.path.join";
        # in this case we need to patch "os" and "os.path"

        for i in range(len(A__		)		):
          try:
            _snake_case						=							import_module('''.'''.join(submodules[: i + 1]		)		)
          except ModuleNotFoundError:
            continue
          # We iterate over all the globals in self.obj in case we find "os" or "os.path"
          for attr in self.obj.__dir__():
            _snake_case						=							getattr(self.obj      , A__		)
            # We don't check for the name of the global, but rather if its value *is* "os" or "os.path".
            # This allows to patch renamed modules like "from os import path as ospath".
            if obj_attr is submodule or (
                (isinstance(A__      , _PatchedModuleObj		) and obj_attr._original_module is submodule)
            ):
              _snake_case						=							obj_attr
              # patch at top level
              setattr(self.obj      , A__      , _PatchedModuleObj(A__      , attrs=self.attrs		)		)
              _snake_case						=							getattr(self.obj      , A__		)
              # construct lower levels patches
              for key in submodules[i + 1 :]:
                setattr(A__      , A__      , _PatchedModuleObj(getattr(A__      , A__      , A__		)      , attrs=self.attrs		)		)
                _snake_case						=							getattr(A__      , A__		)
              # finally set the target attribute
              setattr(A__      , A__      , self.new		)

        # Patch attribute itself:
        # it's used for builtins like "open",
        # and also to patch "os.path.join" we may also need to patch "join"
        # itself if it was imported as "from os.path import join".

        if submodules:  # if it's an attribute of a submodule like "os.path.join"
          try:
            _snake_case						=							getattr(import_module('''.'''.join(A__		)		)      , A__		)
          except (AttributeError, ModuleNotFoundError):
            return
          # We iterate over all the globals in self.obj in case we find "os.path.join"
          for attr in self.obj.__dir__():
            # We don't check for the name of the global, but rather if its value *is* "os.path.join".
            # This allows to patch renamed attributes like "from os.path import join as pjoin".
            if getattr(self.obj      , A__		) is attr_value:
              _snake_case						=							getattr(self.obj      , A__		)
              setattr(self.obj      , A__      , self.new		)
        elif target_attr in globals()["__builtins__"]:  # if it'a s builtin like "open"
          _snake_case						=							globals()['''__builtins__'''][target_attr]
          setattr(self.obj      , A__      , self.new		)
        else:
          raise RuntimeError(f"""Tried to patch attribute {target_attr} instead of a submodule."""		)



      def __exit__(      self				:    Tuple      , *A__				:    Dict		)   ->					Dict:
        for attr in list(self.original		):
          setattr(self.obj      , A__      , self.original.pop(A__		)		)



      def 						UpperCamelCase_		(      self				:    Tuple		)   ->					Union[str, Any]:
        self.__enter__()
        self._active_patches.append(self		)







      def 						UpperCamelCase_		(      self				:    Tuple		)   ->					int:
        try:
          self._active_patches.remove(self		)
        except ValueError:
          # If the patch hasn't been started this will fail
          return None

        return self.__exit__()




from typing import List, Optional, Tuple

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_herbert import HerbertTokenizer


__A      		=     logging.get_logger(__name__)

__A      		=     {'''vocab_file''': '''vocab.json''', '''merges_file''': '''merges.txt''', '''tokenizer_file''': '''tokenizer.json'''}

__A      		=     {
    '''vocab_file''': {
        '''allegro/herbert-base-cased''': '''https://huggingface.co/allegro/herbert-base-cased/resolve/main/vocab.json'''
    },
    '''merges_file''': {
        '''allegro/herbert-base-cased''': '''https://huggingface.co/allegro/herbert-base-cased/resolve/main/merges.txt'''
    },
}

__A      		=     {'''allegro/herbert-base-cased''': 5_14}
__A      		=     {}



class   lowercase_   (  __lowercase					):
      UpperCamelCase_      :		Any										=    VOCAB_FILES_NAMES
      UpperCamelCase_      :		Optional[int]										=    PRETRAINED_VOCAB_FILES_MAP
      UpperCamelCase_      :		List[str]										=    PRETRAINED_INIT_CONFIGURATION
      UpperCamelCase_      :		Dict										=    PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
      UpperCamelCase_      :		Optional[Any]										=    HerbertTokenizer



      def __init__(      self				:    Tuple      , A__				:    str=None      , A__				:    Optional[Any]=None      , A__				:    Union[str, Any]=None      , A__				:    Optional[int]="<s>"      , A__				:    Optional[int]="<unk>"      , A__				:    str="<pad>"      , A__				:    List[Any]="<mask>"      , A__				:    Dict="</s>"      , **A__				:    Optional[int]      , )   ->					Optional[int]:
        super().__init__(
            A__      , A__      , tokenizer_file=A__      , cls_token=A__      , unk_token=A__      , pad_token=A__      , mask_token=A__      , sep_token=A__      , **A__      , )



      def 						UpperCamelCase_		(      self				:    str      , A__				:    List[int]      , A__				:    Optional[List[int]] = None		)   ->					List[int]:
        _snake_case						=							[self.cls_token_id]
        _snake_case						=							[self.sep_token_id]
        if token_ids_a is None:
          return cls + token_ids_a + sep

        return cls + token_ids_a + sep + token_ids_a + sep



      def 						UpperCamelCase_		(      self				:    Tuple      , A__				:    List[int]      , A__				:    Optional[List[int]] = None      , A__				:    bool = False		)   ->					List[int]:
        if already_has_special_tokens:
          return super().get_special_tokens_mask(
              token_ids_a=A__      , token_ids_a=A__      , already_has_special_tokens=A__		)

        if token_ids_a is None:
          return [1] + ([0] * len(A__		)) + [1]
        return [1] + ([0] * len(A__		)) + [1] + ([0] * len(A__		)) + [1]



      def 						UpperCamelCase_		(      self				:    Any      , A__				:    List[int]      , A__				:    Optional[List[int]] = None		)   ->					List[int]:
        _snake_case						=							[self.sep_token_id]
        _snake_case						=							[self.cls_token_id]

        if token_ids_a is None:
          return len(cls + token_ids_a + sep		) * [0]
        return len(cls + token_ids_a + sep		) * [0] + len(token_ids_a + sep		) * [1]







      def 						UpperCamelCase_		(      self				:    Union[str, Any]      , A__				:    str      , A__				:    Optional[str] = None		)   ->					Tuple[str]:
        _snake_case						=							self._tokenizer.model.save(A__      , name=A__		)
        return tuple(A__		)

