



'''simple docstring'''
import os
import zipfile

import pytest

from datasets.utils.extract import (
    BzipaExtractor,
    Extractor,
    GzipExtractor,
    LzaExtractor,
    SevenZipExtractor,
    TarExtractor,
    XzExtractor,
    ZipExtractor,
    ZstdExtractor,
)

from .utils import require_lza, require_pyazr, require_zstandard





@pytest.mark.parametrize(
    '''compression_format, is_archive''',	[
        ('''7z''', True),
        ('''bz2''', False),
        ('''gzip''', False),
        ('''lz4''', False),
        ('''tar''', True),
        ('''xz''', False),
        ('''zip''', True),
        ('''zstd''', False),
    ],	)
def  _a(  UpperCamelCase__				:						int,	UpperCamelCase__				:						int,	UpperCamelCase__				:						Dict,	UpperCamelCase__				:						Dict,	UpperCamelCase__				:						List[Any],	UpperCamelCase__				:						Dict,	UpperCamelCase__				:						Optional[Any],	UpperCamelCase__				:						Optional[int],	UpperCamelCase__				:						Dict,	UpperCamelCase__				:						Union[str, Any],	UpperCamelCase__				:						Dict,	UpperCamelCase__				:						List[str],	):




      '''simple docstring'''






      SCREAMING_SNAKE_CASE__     :				Any									={
          '''7z''': (seven_zip_file, SevenZipExtractor),
          '''bz2''': (bza_file, BzipaExtractor),
          '''gzip''': (gz_file, GzipExtractor),
          '''lz4''': (lza_file, LzaExtractor),
          '''tar''': (tar_file, TarExtractor),
          '''xz''': (xz_file, XzExtractor),
          '''zip''': (zip_file, ZipExtractor),
          '''zstd''': (zstd_file, ZstdExtractor),
      }
      SCREAMING_SNAKE_CASE__     :				List[Any]									=input_paths_and_base_extractors[compression_format]
      if input_path is None:
            SCREAMING_SNAKE_CASE__     :				Dict									=f"for '{compression_format}' compression_format, "
            if compression_format == "7z":
                  reason += require_pyazr.kwargs["reason"]
            elif compression_format == "lz4":
                  reason += require_lza.kwargs["reason"]
            elif compression_format == "zstd":
                  reason += require_zstandard.kwargs["reason"]
            pytest.skip(UpperCamelCase__							)
      assert base_extractor.is_extractable(UpperCamelCase__							)
      SCREAMING_SNAKE_CASE__     :				List[str]									=tmp_path / ('''extracted''' if is_archive else '''extracted.txt''')
      base_extractor.extract(UpperCamelCase__,	UpperCamelCase__							)
      if is_archive:
            assert output_path.is_dir()
            for file_path in output_path.iterdir():
                  assert file_path.name == text_file.name
                  SCREAMING_SNAKE_CASE__     :				List[Any]									=file_path.read_text(encoding='''utf-8'''							)
      else:
            SCREAMING_SNAKE_CASE__     :				Union[str, Any]									=output_path.read_text(encoding='''utf-8'''							)
      SCREAMING_SNAKE_CASE__     :				Dict									=text_file.read_text(encoding='''utf-8'''							)
      assert extracted_file_content == expected_file_content





@pytest.mark.parametrize(
    '''compression_format, is_archive''',	[
        ('''7z''', True),
        ('''bz2''', False),
        ('''gzip''', False),
        ('''lz4''', False),
        ('''tar''', True),
        ('''xz''', False),
        ('''zip''', True),
        ('''zstd''', False),
    ],	)
def  _a(  UpperCamelCase__				:						Dict,	UpperCamelCase__				:						List[str],	UpperCamelCase__				:						Optional[int],	UpperCamelCase__				:						int,	UpperCamelCase__				:						Dict,	UpperCamelCase__				:						Optional[Any],	UpperCamelCase__				:						List[str],	UpperCamelCase__				:						List[str],	UpperCamelCase__				:						Optional[int],	UpperCamelCase__				:						Optional[int],	UpperCamelCase__				:						Optional[Any],	UpperCamelCase__				:						List[str],	):




      '''simple docstring'''






      SCREAMING_SNAKE_CASE__     :				Any									={
          '''7z''': seven_zip_file,
          '''bz2''': bza_file,
          '''gzip''': gz_file,
          '''lz4''': lza_file,
          '''tar''': tar_file,
          '''xz''': xz_file,
          '''zip''': zip_file,
          '''zstd''': zstd_file,
      }
      SCREAMING_SNAKE_CASE__     :				Optional[int]									=input_paths[compression_format]
      if input_path is None:
            SCREAMING_SNAKE_CASE__     :				str									=f"for '{compression_format}' compression_format, "
            if compression_format == "7z":
                  reason += require_pyazr.kwargs["reason"]
            elif compression_format == "lz4":
                  reason += require_lza.kwargs["reason"]
            elif compression_format == "zstd":
                  reason += require_zstandard.kwargs["reason"]
            pytest.skip(UpperCamelCase__							)
      SCREAMING_SNAKE_CASE__     :				Dict									=Extractor.infer_extractor_format(UpperCamelCase__							)
      assert extractor_format is not None
      SCREAMING_SNAKE_CASE__     :				Tuple									=tmp_path / ('''extracted''' if is_archive else '''extracted.txt''')
      Extractor.extract(UpperCamelCase__,	UpperCamelCase__,	UpperCamelCase__							)
      if is_archive:
            assert output_path.is_dir()
            for file_path in output_path.iterdir():
                  assert file_path.name == text_file.name
                  SCREAMING_SNAKE_CASE__     :				str									=file_path.read_text(encoding='''utf-8'''							)
      else:
            SCREAMING_SNAKE_CASE__     :				Optional[int]									=output_path.read_text(encoding='''utf-8'''							)
      SCREAMING_SNAKE_CASE__     :				int									=text_file.read_text(encoding='''utf-8'''							)
      assert extracted_file_content == expected_file_content





@pytest.fixture
def  _a(  UpperCamelCase__				:						Tuple,	UpperCamelCase__				:						Any							):




      '''simple docstring'''






      import tarfile

      SCREAMING_SNAKE_CASE__     :				Any									=tmp_path / '''data_dot_dot'''
      directory.mkdir()
      SCREAMING_SNAKE_CASE__     :				Union[str, Any]									=directory / '''tar_file_with_dot_dot.tar'''
      with tarfile.TarFile(UpperCamelCase__,	'''w'''							) as f:
            f.add(UpperCamelCase__,	arcname=os.path.join('''..''',	text_file.name							)							)
      return path





@pytest.fixture
def  _a(  UpperCamelCase__				:						List[str]							):




      '''simple docstring'''






      import tarfile

      SCREAMING_SNAKE_CASE__     :				Optional[int]									=tmp_path / '''data_sym_link'''
      directory.mkdir()
      SCREAMING_SNAKE_CASE__     :				List[Any]									=directory / '''tar_file_with_sym_link.tar'''
      os.symlink('''..''',	directory / '''subdir''',	target_is_directory=UpperCamelCase__							)
      with tarfile.TarFile(UpperCamelCase__,	'''w'''							) as f:
            f.add(str(directory / '''subdir'''							),	arcname='''subdir'''							)  # str required by os.readlink on Windows and Python < 3.8
      return path





@pytest.mark.parametrize(
    '''insecure_tar_file, error_log''',	[('''tar_file_with_dot_dot''', '''illegal path'''), ('''tar_file_with_sym_link''', '''Symlink''')],	)
def  _a(  UpperCamelCase__				:						str,	UpperCamelCase__				:						int,	UpperCamelCase__				:						Optional[Any],	UpperCamelCase__				:						Tuple,	UpperCamelCase__				:						Any,	UpperCamelCase__				:						Union[str, Any]							):




      '''simple docstring'''






      SCREAMING_SNAKE_CASE__     :				Optional[int]									={
          '''tar_file_with_dot_dot''': tar_file_with_dot_dot,
          '''tar_file_with_sym_link''': tar_file_with_sym_link,
      }
      SCREAMING_SNAKE_CASE__     :				List[str]									=insecure_tar_files[insecure_tar_file]
      SCREAMING_SNAKE_CASE__     :				Tuple									=tmp_path / '''extracted'''
      TarExtractor.extract(UpperCamelCase__,	UpperCamelCase__							)
      assert caplog.text
      for record in caplog.records:
            assert record.levelname == "ERROR"
            assert error_log in record.msg







def  _a(  UpperCamelCase__				:						List[str]							):




      '''simple docstring'''






      SCREAMING_SNAKE_CASE__     :				Dict									=tmpdir / '''not_a_zip_file'''
      # From: https://github.com/python/cpython/pull/5053
      SCREAMING_SNAKE_CASE__     :				Dict									=(
          B'''\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x01\x00\x00'''
          B'''\x00\x02\x08\x06\x00\x00\x00\x99\x81\xb6\'\x00\x00\x00\x15I'''
          B'''DATx\x01\x01\n\x00\xf5\xff\x00PK\x05\x06\x00PK\x06\x06\x07'''
          B'''\xac\x01N\xc6|a\r\x00\x00\x00\x00IEND\xaeB`\x82'''
      )
      with not_a_zip_file.open('''wb'''							) as f:
            f.write(UpperCamelCase__							)
      assert zipfile.is_zipfile(str(UpperCamelCase__							)							)  # is a false positive for `zipfile`
      assert not ZipExtractor.is_extractable(UpperCamelCase__							)  # but we're right







'''simple docstring'''
from ...configuration_utils import PretrainedConfig
from ...utils import logging


a_					= logging.get_logger(__name__)

a_					= {
    'bigcode/gpt_bigcode-santacoder': 'https://huggingface.co/bigcode/gpt_bigcode-santacoder/resolve/main/config.json',
}






class      __SCREAMING_SNAKE_CASE      (			lowerCamelCase				):
 snake_case_  							=							"""gpt_bigcode"""
 snake_case_  							=							["""past_key_values"""]
 snake_case_  							=							{
     """hidden_size""": """n_embd""",
     """max_position_embeddings""": """n_positions""",
     """num_attention_heads""": """n_head""",
     """num_hidden_layers""": """n_layer""",
 }




 def __init__(      self	:							Any					,      __lowercase	:							Any=5_02_57					,      __lowercase	:							int=10_24					,      __lowercase	:							List[str]=7_68					,      __lowercase	:							Optional[int]=12					,      __lowercase	:							Dict=12					,      __lowercase	:							List[str]=None					,      __lowercase	:							int="gelu_pytorch_tanh"					,      __lowercase	:							Union[str, Any]=0.1					,      __lowercase	:							Optional[int]=0.1					,      __lowercase	:							Optional[int]=0.1					,      __lowercase	:							Optional[Any]=1e-5					,      __lowercase	:							List[str]=0.02					,      __lowercase	:							Tuple=True					,      __lowercase	:							Optional[Any]=True					,      __lowercase	:							Union[str, Any]=5_02_56					,      __lowercase	:							List[Any]=5_02_56					,      __lowercase	:							Union[str, Any]=True					,      __lowercase	:							List[str]=True					,      __lowercase	:							Dict=True					,      **__lowercase	:							List[Any]					,      )	->						Optional[int]:
       SCREAMING_SNAKE_CASE__     :				Union[str, Any]									=vocab_size
       SCREAMING_SNAKE_CASE__     :				Union[str, Any]									=n_positions
       SCREAMING_SNAKE_CASE__     :				Dict									=n_embd
       SCREAMING_SNAKE_CASE__     :				Dict									=n_layer
       SCREAMING_SNAKE_CASE__     :				Union[str, Any]									=n_head
       SCREAMING_SNAKE_CASE__     :				List[str]									=n_inner
       SCREAMING_SNAKE_CASE__     :				List[str]									=activation_function
       SCREAMING_SNAKE_CASE__     :				List[Any]									=resid_pdrop
       SCREAMING_SNAKE_CASE__     :				List[Any]									=embd_pdrop
       SCREAMING_SNAKE_CASE__     :				List[str]									=attn_pdrop
       SCREAMING_SNAKE_CASE__     :				Dict									=layer_norm_epsilon
       SCREAMING_SNAKE_CASE__     :				List[str]									=initializer_range
       SCREAMING_SNAKE_CASE__     :				List[Any]									=scale_attn_weights
       SCREAMING_SNAKE_CASE__     :				Union[str, Any]									=use_cache
       SCREAMING_SNAKE_CASE__     :				Dict									=attention_softmax_in_fpaa
       SCREAMING_SNAKE_CASE__     :				int									=scale_attention_softmax_in_fpaa
       SCREAMING_SNAKE_CASE__     :				Dict									=multi_query

       SCREAMING_SNAKE_CASE__     :				Optional[Any]									=bos_token_id
       SCREAMING_SNAKE_CASE__     :				Optional[Any]									=eos_token_id

       super().__init__(bos_token_id=__lowercase					,      eos_token_id=__lowercase					,      **__lowercase      )