






"""simple docstring"""





import io
import os
import unicodedata
from typing import Any, Dict, List, Optional, Tuple

import sentencepiece as spm

from ...tokenization_utils import PreTrainedTokenizer
from ...utils import logging


UpperCamelCase_	:				List[str]										= logging.get_logger(__name__)

UpperCamelCase_	:				Optional[Any]										= """▁"""

UpperCamelCase_	:				int										= {"""vocab_file""": """vocab.txt""", """sentencepiece_model_ckpt""": """sentencepiece.bpe.model"""}

UpperCamelCase_	:				Optional[int]										= {
    """sentencepiece_model_file""": """sentencepiece.bpe.model""",
    """vocab_file""": """vocab.txt""",
}

UpperCamelCase_	:				List[str]										= {
    """vocab_file""": {
        """ernie-m-base""": """https://huggingface.co/susnato/ernie-m-base_pytorch/blob/main/vocab.txt""",
        """ernie-m-large""": """https://huggingface.co/susnato/ernie-m-base_pytorch/blob/main/vocab.txt""",
    },
    """sentencepiece_model_file""": {
        """ernie-m-base""": """https://huggingface.co/susnato/ernie-m-base_pytorch/blob/main/sentencepiece.bpe.model""",
        """ernie-m-large""": """https://huggingface.co/susnato/ernie-m-base_pytorch/blob/main/sentencepiece.bpe.model""",
    },
}

UpperCamelCase_	:				Optional[int]										= {
    """ernie-m-base""": 514,
    """ernie-m-large""": 514,
}

UpperCamelCase_	:				Dict										= {
    """ernie-m-base""": {"""do_lower_case""": False},
    """ernie-m-large""": {"""do_lower_case""": False},
}


class      _lowercase (     lowerCAmelCase						):
      _a   :     List[str]								=   ["input_ids"]

      _a   :     int								=   VOCAB_FILES_NAMES
      _a   :     Tuple								=   PRETRAINED_INIT_CONFIGURATION
      _a   :     Union[str, Any]								=   PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
      _a   :     Dict								=   PRETRAINED_VOCAB_FILES_MAP
      _a   :     Optional[int]								=   RESOURCE_FILES_NAMES


      def __init__(    self				:	int							,   a				:	Tuple							,   a				:	List[str]=None							,   a				:	Any=False							,   a				:	Any="utf8"							,   a				:	int="[UNK]"							,   a				:	Union[str, Any]="[SEP]"							,   a				:	Optional[int]="[PAD]"							,   a				:	str="[CLS]"							,   a				:	int="[MASK]"							,   a				:	Optional[Dict[str, Any]] = None							,   **a				:	List[Any]							,   ):





            """simple docstring"""







            __snake_case      :    List[str]  			={} if sp_model_kwargs is None else sp_model_kwargs
            super().__init__(
                do_lower_case=a							,   unk_token=a							,   sep_token=a							,   pad_token=a							,   cls_token=a							,   mask_token=a							,   vocab_file=a							,   encoding=a							,   sp_model_kwargs=self.sp_model_kwargs							,   **a							,   )
            __snake_case      :    int  			=do_lower_case
            __snake_case      :    str  			=sentencepiece_model_ckpt
            __snake_case      :    Tuple  			=spm.SentencePieceProcessor(**self.sp_model_kwargs						)
            self.sp_model.Load(a						)

            # to mimic paddlenlp.transformers.ernie_m.tokenizer.ErnieMTokenizer functioning
            if vocab_file is not None:
                  __snake_case      :    Optional[int]  			=self.load_vocab(filepath=a						)
            else:
                  __snake_case      :    Union[str, Any]  			={self.sp_model.id_to_piece(a						): id for id in range(self.sp_model.get_piece_size()						)}
            __snake_case      :    Tuple  			={v: k for k, v in self.vocab.items()}


      def _UpperCamelCase						(    self				:	str							,   a				:	Dict						):





            """simple docstring"""







            if text is None:
                  return None

            __snake_case      :    Any  			=self.tokenize(a						)
            __snake_case			,				__snake_case      :    Union[str, Any]  			='''''', []

            for i, ch in enumerate(a						):
                  if ch in self.SP_CHAR_MAPPING:
                        __snake_case      :    Any  			=self.SP_CHAR_MAPPING.get(a						)
                  else:
                        __snake_case      :    int  			=unicodedata.normalize('''NFKC'''							,   a						)
                  if self.is_whitespace(a						):
                        continue
                  normalized_text += ch
                  char_mapping.extend([i] * len(a						)						)

            __snake_case			,				__snake_case			,				__snake_case      :    List[Any]  			=normalized_text, [], 0

            if self.do_lower_case:
                  __snake_case      :    str  			=text.lower()

            for token in split_tokens:
                  if token[:1] == "▁":
                        __snake_case      :    str  			=token[1:]
                  __snake_case      :    str  			=text[offset:].index(a						) + offset
                  __snake_case      :    List[Any]  			=start + len(a						)

                  token_mapping.append((char_mapping[start], char_mapping[end - 1] + 1)						)
                  __snake_case      :    str  			=end
            return token_mapping


      @property
      def _UpperCamelCase						(    self				:	str						):





            """simple docstring"""







            return len(self.vocab						)


      def _UpperCamelCase						(    self				:	List[str]						):





            """simple docstring"""







            return dict(self.vocab							,   **self.added_tokens_encoder						)


      def __getstate__(    self				:	Any						):





            """simple docstring"""







            __snake_case      :    Optional[Any]  			=self.__dict__.copy()
            __snake_case      :    List[str]  			=None
            return state


      def __setstate__(    self				:	List[Any]							,   a				:	Any						):





            """simple docstring"""







            __snake_case      :    int  			=d

            # for backward compatibility
            if not hasattr(self							,   '''sp_model_kwargs'''						):
                  __snake_case      :    str  			={}

            __snake_case      :    List[Any]  			=spm.SentencePieceProcessor(**self.sp_model_kwargs						)
            self.sp_model.Load(self.sentencepiece_model_ckpt						)


      def _UpperCamelCase						(    self				:	Tuple							,   a				:	Tuple						):





            """simple docstring"""







            return "".join((self.SP_CHAR_MAPPING.get(a							,   a						) for c in text)						)


      def _UpperCamelCase						(    self				:	Union[str, Any]							,   a				:	Optional[int]							,   a				:	int=False							,   a				:	Any=6_4							,   a				:	List[Any]=0.1						):





            """simple docstring"""







            if self.sp_model_kwargs.get('''enable_sampling'''						) is True:
                  __snake_case      :    int  			=True
            if self.sp_model_kwargs.get('''alpha'''						) is not None:
                  __snake_case      :    str  			=self.sp_model_kwargs.get('''alpha'''						)
            if self.sp_model_kwargs.get('''nbest_size'''						) is not None:
                  __snake_case      :    Optional[Any]  			=self.sp_model_kwargs.get('''nbest_size'''						)

            if not enable_sampling:
                  __snake_case      :    List[str]  			=self.sp_model.EncodeAsPieces(a						)
            else:
                  __snake_case      :    List[Any]  			=self.sp_model.SampleEncodeAsPieces(a							,   a							,   a						)
            __snake_case      :    Any  			=[]
            for pi, piece in enumerate(a						):
                  if piece == SPIECE_UNDERLINE:
                        if not pieces[pi + 1].startswith(a						) and pi != 0:
                              new_pieces.append(a						)
                              continue
                        else:
                              continue
                  __snake_case      :    Union[str, Any]  			=0
                  for i, chunk in enumerate(a						):
                        if chunk == SPIECE_UNDERLINE:
                              continue
                        if self.is_ch_char(a						) or self.is_punct(a						):
                              if i > lst_i and piece[lst_i:i] != SPIECE_UNDERLINE:
                                    new_pieces.append(piece[lst_i:i]						)
                              new_pieces.append(a						)
                              __snake_case      :    Dict  			=i + 1
                        elif chunk.isdigit() and i > 0 and not piece[i - 1].isdigit():
                              if i > lst_i and piece[lst_i:i] != SPIECE_UNDERLINE:
                                    new_pieces.append(piece[lst_i:i]						)
                              __snake_case      :    str  			=i
                        elif not chunk.isdigit() and i > 0 and piece[i - 1].isdigit():
                              if i > lst_i and piece[lst_i:i] != SPIECE_UNDERLINE:
                                    new_pieces.append(piece[lst_i:i]						)
                              __snake_case      :    Union[str, Any]  			=i
                  if len(a						) > lst_i:
                        new_pieces.append(piece[lst_i:]						)
            return new_pieces


      def _UpperCamelCase						(    self				:	int							,   a				:	Union[str, Any]						):





            """simple docstring"""







            __snake_case      :    Union[str, Any]  			=''''''.join(a						).replace(a							,   ''' '''						).strip()
            return out_string


      def _UpperCamelCase						(    self				:	str							,   a				:	Optional[Any]						):





            """simple docstring"""







            __snake_case      :    List[Any]  			=self.convert_ids_to_tokens(a						)
            __snake_case      :    Any  			=''''''.join(a						).replace(a							,   ''' '''						).strip()
            return out_string


      def _UpperCamelCase						(    self				:	List[Any]							,   a				:	Optional[Any]						):





            """simple docstring"""







            return self.vocab.get(a							,   self.vocab.get(self.unk_token						)						)


      def _UpperCamelCase						(    self				:	Union[str, Any]							,   a				:	Union[str, Any]						):





            """simple docstring"""







            return self.reverse_vocab.get(a							,   self.unk_token						)


      def _UpperCamelCase						(    self				:	Any							,   a				:	Union[str, Any]							,   a				:	Optional[int]=None						):





            """simple docstring"""







            if token_ids_a is None:
                  return [self.cls_token_id] + token_ids_a + [self.sep_token_id]
            __snake_case      :    Tuple  			=[self.cls_token_id]
            __snake_case      :    List[str]  			=[self.sep_token_id]
            return _cls + token_ids_a + _sep + _sep + token_ids_a + _sep


      def _UpperCamelCase						(    self				:	Any							,   a				:	List[Any]							,   a				:	List[str]=None						):





            """simple docstring"""







            if offset_mapping_a is None:
                  return [(0, 0)] + offset_mapping_a + [(0, 0)]

            return [(0, 0)] + offset_mapping_a + [(0, 0), (0, 0)] + offset_mapping_a + [(0, 0)]


      def _UpperCamelCase						(    self				:	str							,   a				:	Union[str, Any]							,   a				:	Union[str, Any]=None							,   a				:	Optional[int]=False						):





            """simple docstring"""







            if already_has_special_tokens:
                  if token_ids_a is not None:
                        raise ValueError(
                            '''You should not supply a second sequence if the provided sequence of '''
                            '''ids is already formatted with special tokens for the model.'''						)
                  return [1 if x in [self.sep_token_id, self.cls_token_id] else 0 for x in token_ids_a]

            if token_ids_a is not None:
                  return [1] + ([0] * len(a						)) + [1, 1] + ([0] * len(a						)) + [1]
            return [1] + ([0] * len(a						)) + [1]


      def _UpperCamelCase						(    self				:	List[Any]							,   a				:	List[int]							,   a				:	Optional[List[int]] = None						):





            """simple docstring"""







            if token_ids_a is None:
                  # [CLS] X [SEP]
                  return (len(a						) + 2) * [0]

            # [CLS] A [SEP] [SEP] B [SEP]
            return [0] * (len(a						) + 1) + [1] * (len(a						) + 3)


      def _UpperCamelCase						(    self				:	Any							,   a				:	List[Any]						):





            """simple docstring"""







            if "\u4e00" <= char <= "\u9fff":
                  return True
            return False


      def _UpperCamelCase						(    self				:	str							,   a				:	Optional[Any]						):





            """simple docstring"""







            if ("a" <= char <= "z") or ("A" <= char <= "Z"):
                  return True
            return False


      def _UpperCamelCase						(    self				:	Dict							,   a				:	Optional[int]						):





            """simple docstring"""







            if char in ",;:.?!~，；：。？！《》【】":
                  return True
            return False


      def _UpperCamelCase						(    self				:	Tuple							,   a				:	Tuple						):





            """simple docstring"""







            if char == " " or char == "\t" or char == "\n" or char == "\r":
                  return True
            if len(a						) == 1:
                  __snake_case      :    List[str]  			=unicodedata.category(a						)
                  if cat == "Zs":
                        return True
            return False


      def _UpperCamelCase						(    self				:	Any							,   a				:	Optional[Any]						):





            """simple docstring"""







            __snake_case      :    str  			={}
            with io.open(a							,   '''r'''							,   encoding='''utf-8'''						) as f:
                  for index, line in enumerate(a						):
                        __snake_case      :    Any  			=line.rstrip('''\n'''						)
                        __snake_case      :    Union[str, Any]  			=int(a						)

            return token_to_idx







      def _UpperCamelCase						(    self				:	int							,   a				:	str							,   a				:	Optional[str] = None						):





            """simple docstring"""







            __snake_case      :    str  			=0
            if os.path.isdir(a						):
                  __snake_case      :    int  			=os.path.join(
                      a							,   (filename_prefix + '''-''' if filename_prefix else '''''') + VOCAB_FILES_NAMES['''vocab_file''']						)
            else:
                  __snake_case      :    Dict  			=(filename_prefix + '''-''' if filename_prefix else '''''') + save_directory
            with open(a							,   '''w'''							,   encoding='''utf-8'''						) as writer:
                  for token, token_index in sorted(self.vocab.items()							,   key=lambda a						: kv[1]						):
                        if index != token_index:
                              logger.warning(
                                  f'''Saving vocabulary to {vocab_file}: vocabulary indices are not consecutive.'''
                                  ''' Please check that the vocabulary is not corrupted!'''						)
                              __snake_case      :    int  			=token_index
                        writer.write(token + '''\n'''						)
                        index += 1

            __snake_case      :    Union[str, Any]  			=os.path.join(a							,   '''sentencepiece.bpe.model'''						)
            with open(a							,   '''wb'''						) as fi:
                  __snake_case      :    Dict  			=self.sp_model.serialized_model_proto()
                  fi.write(a						)

            return (vocab_file,)










"""simple docstring"""





from __future__ import annotations

import json

import requests
from bsa import BeautifulSoup
from fake_useragent import UserAgent

UpperCamelCase_	:				Tuple										= {"""UserAgent""": UserAgent().random}



def     __lowercase					(    a :				str )					->					dict:
      __snake_case      :    Union[str, Any]  			=script.contents[0]
      __snake_case      :    List[str]  			=json.loads(data[data.find('''{"config"''' ) : -1] )
      return info["entry_data"]["ProfilePage"][0]["graphql"]["user"]


class      _lowercase :


      def __init__(    self				:	int							,   a				:	Dict						):





            """simple docstring"""







            __snake_case      :    Dict  			=f'''https://www.instagram.com/{username}/'''
            __snake_case      :    str  			=self.get_json()


      def _UpperCamelCase						(    self				:	Union[str, Any]						):





            """simple docstring"""







            __snake_case      :    List[str]  			=requests.get(self.url							,   headers=a						).text
            __snake_case      :    int  			=BeautifulSoup(a							,   '''html.parser'''						).find_all('''script'''						)
            try:
                  return extract_user_profile(scripts[4]						)
            except (json.decoder.JSONDecodeError, KeyError):
                  return extract_user_profile(scripts[3]						)


      def __repr__(    self				:	int						):





            """simple docstring"""







            return f'''{self.__class__.__name__}(\'{self.username}\')'''


      def __str__(    self				:	Any						):





            """simple docstring"""







            return f'''{self.fullname} ({self.username}) is {self.biography}'''


      @property
      def _UpperCamelCase						(    self				:	Union[str, Any]						):





            """simple docstring"""







            return self.user_data["username"]


      @property
      def _UpperCamelCase						(    self				:	Dict						):





            """simple docstring"""







            return self.user_data["full_name"]


      @property
      def _UpperCamelCase						(    self				:	List[Any]						):





            """simple docstring"""







            return self.user_data["biography"]


      @property
      def _UpperCamelCase						(    self				:	Dict						):





            """simple docstring"""







            return self.user_data["business_email"]


      @property
      def _UpperCamelCase						(    self				:	Optional[int]						):





            """simple docstring"""







            return self.user_data["external_url"]


      @property
      def _UpperCamelCase						(    self				:	Dict						):





            """simple docstring"""







            return self.user_data["edge_followed_by"]["count"]


      @property
      def _UpperCamelCase						(    self				:	int						):





            """simple docstring"""







            return self.user_data["edge_follow"]["count"]


      @property
      def _UpperCamelCase						(    self				:	Tuple						):





            """simple docstring"""







            return self.user_data["edge_owner_to_timeline_media"]["count"]


      @property
      def _UpperCamelCase						(    self				:	Dict						):





            """simple docstring"""







            return self.user_data["profile_pic_url_hd"]


      @property
      def _UpperCamelCase						(    self				:	str						):





            """simple docstring"""







            return self.user_data["is_verified"]







      @property
      def _UpperCamelCase						(    self				:	Dict						):





            """simple docstring"""







            return self.user_data["is_private"]



def     __lowercase					(    a :				str = "github" )					->					None:
      import os

      if os.environ.get('''CI''' ):
            return  # test failing on GitHub Actions
      __snake_case      :    Union[str, Any]  			=InstagramUser(a )
      assert instagram_user.user_data
      assert isinstance(instagram_user.user_data       ,		a )
      assert instagram_user.username == username
      if username != "github":
            return
      assert instagram_user.fullname == "GitHub"
      assert instagram_user.biography == "Built for developers."
      assert instagram_user.number_of_posts > 150
      assert instagram_user.number_of_followers > 120_000
      assert instagram_user.number_of_followings > 15
      assert instagram_user.email == "support@github.com"
      assert instagram_user.website == "https://github.com/readme"
      assert instagram_user.profile_picture_url.startswith('''https://instagram.''' )
      assert instagram_user.is_verified is True
      assert instagram_user.is_private is False


if __name__ == "__main__":
    import doctest

    doctest.testmod()
    UpperCamelCase_	:				Optional[int]										= InstagramUser("""github""")
    print(instagram_user)
    print(F'''{instagram_user.number_of_posts = }''')
    print(F'''{instagram_user.number_of_followers = }''')
    print(F'''{instagram_user.number_of_followings = }''')
    print(F'''{instagram_user.email = }''')
    print(F'''{instagram_user.website = }''')
    print(F'''{instagram_user.profile_picture_url = }''')
    print(F'''{instagram_user.is_verified = }''')
    print(F'''{instagram_user.is_private = }''')


