





'''simple docstring'''







_lowercase       						=			"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"

def    __UpperCamelCase	(	a    : bytes     ) ->bytes:
 # Make sure the supplied data is a bytes-like object
 if not isinstance(UpperCAmelCase__					,   UpperCAmelCase__     ):
  snake_case				=			f"""a bytes-like object is required, not \'{data.__class__.__name__}\'"""
  raise TypeError(UpperCAmelCase__     )

 snake_case				=			"""""".join(bin(UpperCAmelCase__     )[2:].zfill(8     ) for byte in data     )

 snake_case				=			len(UpperCAmelCase__     ) % 6 != 0

 if padding_needed:
  # The padding that will be added later
  snake_case				=			b"""=""" * ((6 - len(UpperCAmelCase__     ) % 6) // 2)

  # Append binary_stream with arbitrary binary digits (0's by default) to make its
  # length a multiple of 6.
  binary_stream += "0" * (6 - len(UpperCAmelCase__     ) % 6)
 else:
  snake_case				=			b""""""

 # Encode every 6 binary digits to their corresponding Base64 character
 return (
     "".join(
         B64_CHARSET[int(binary_stream[index : index + 6]					,   2     )]
         for index in range(0					,   len(UpperCAmelCase__     )					,   6     )     ).encode()
     + padding
 )

def    __UpperCamelCase	(	a    : str     ) ->bytes:
 # Make sure encoded_data is either a string or a bytes-like object
 if not isinstance(UpperCAmelCase__					,   UpperCAmelCase__     ) and not isinstance(UpperCAmelCase__					,   UpperCAmelCase__     ):
  snake_case				=			(
      """argument should be a bytes-like object or ASCII string, """
      f"""not \'{encoded_data.__class__.__name__}\'"""
  )
  raise TypeError(UpperCAmelCase__     )

 # In case encoded_data is a bytes-like object, make sure it contains only
 # ASCII characters so we convert it to a string object
 if isinstance(UpperCAmelCase__					,   UpperCAmelCase__     ):
  try:
   snake_case				=			encoded_data.decode('''utf-8'''     )
  except UnicodeDecodeError:
   raise ValueError('''base64 encoded data should only contain ASCII characters'''     )

 snake_case				=			encoded_data.count('''='''     )

 # Check if the encoded string contains non base64 characters
 if padding:
  assert all(
      char in B64_CHARSET for char in encoded_data[:-padding]     ), "Invalid base64 character(s) found."
 else:
  assert all(
      char in B64_CHARSET for char in encoded_data     ), "Invalid base64 character(s) found."

 # Check the padding
 assert len(UpperCAmelCase__     ) % 4 == 0 and padding < 3, "Incorrect padding"

 if padding:
  # Remove padding if there is one
  snake_case				=			encoded_data[:-padding]

  snake_case				=			"""""".join(
      bin(B64_CHARSET.index(UpperCAmelCase__     )     )[2:].zfill(6     ) for char in encoded_data     )[: -padding * 2]
 else:
  snake_case				=			"""""".join(
      bin(B64_CHARSET.index(UpperCAmelCase__     )     )[2:].zfill(6     ) for char in encoded_data     )

 snake_case				=			[
     int(binary_stream[index : index + 8]					,   2     )
     for index in range(0					,   len(UpperCAmelCase__     )					,   8     )
 ]

 return bytes(UpperCAmelCase__     )


if __name__ == "__main__":
   import doctest

   doctest.testmod()








'''simple docstring'''







import os
from tempfile import TemporaryDirectory
from unittest import TestCase

import pytest
from absl.testing import parameterized

from datasets import config
from datasets.arrow_reader import HF_GCP_BASE_URL
from datasets.builder import DatasetBuilder
from datasets.dataset_dict import IterableDatasetDict
from datasets.iterable_dataset import IterableDataset
from datasets.load import dataset_module_factory, import_main_class
from datasets.utils.file_utils import cached_path


_lowercase       						=			[
    {'dataset': 'wikipedia', 'config_name': '20220301.de'},
    {'dataset': 'wikipedia', 'config_name': '20220301.en'},
    {'dataset': 'wikipedia', 'config_name': '20220301.fr'},
    {'dataset': 'wikipedia', 'config_name': '20220301.frr'},
    {'dataset': 'wikipedia', 'config_name': '20220301.it'},
    {'dataset': 'wikipedia', 'config_name': '20220301.simple'},
    {'dataset': 'snli', 'config_name': 'plain_text'},
    {'dataset': 'eli5', 'config_name': 'LFQA_reddit'},
    {'dataset': 'wiki40b', 'config_name': 'en'},
    {'dataset': 'wiki_dpr', 'config_name': 'psgs_w100.nq.compressed'},
    {'dataset': 'wiki_dpr', 'config_name': 'psgs_w100.nq.no_index'},
    {'dataset': 'wiki_dpr', 'config_name': 'psgs_w100.multiset.no_index'},
    {'dataset': 'natural_questions', 'config_name': 'default'},
]

def    __UpperCamelCase	(	a    : Dict=True     ) ->str:
 if with_config:
  return [
      {
          "testcase_name": d["dataset"] + "/" + d["config_name"],
          "dataset": d["dataset"],
          "config_name": d["config_name"],
      }
      for d in DATASETS_ON_HF_GCP
  ]
 else:
  return [
      {"testcase_name": dataset, "dataset": dataset} for dataset in {d["dataset"] for d in DATASETS_ON_HF_GCP}
  ]
@parameterized.named_parameters(list_datasets_on_hf_gcp_parameters(with_config=__a					)					)
class 			_lowercase						(       __a					):
     _UpperCAmelCase										=					None
     _UpperCAmelCase										=					None







     def     UpperCamelCase			( self    ,   A__    ,   A__    ) ->	str:
      with TemporaryDirectory() as tmp_dir:
       snake_case				=			dataset_module_factory(A__    ,   cache_dir=A__    )

       snake_case				=			import_main_class(dataset_module.module_path    ,   dataset=A__    )

       snake_case				=			builder_cls(
           cache_dir=A__    ,   config_name=A__    ,   hash=dataset_module.hash    ,   )

       snake_case				=			'''/'''.join(
           [
               HF_GCP_BASE_URL,
               builder_instance._relative_data_dir(with_hash=A__    ).replace(os.sep    ,   '''/'''    ),
               config.DATASET_INFO_FILENAME,
           ]    )
       snake_case				=			cached_path(A__    ,   cache_dir=A__    )
       self.assertTrue(os.path.exists(A__    )    )




@pytest.mark.integration
def    __UpperCamelCase	(	a    : List[str]     ) ->Any:
 snake_case				=			tmp_path_factory.mktemp('''test_hf_gcp'''     ) / '''test_wikipedia_simple'''
 snake_case				=			dataset_module_factory('''wikipedia'''					,   cache_dir=a     )
 snake_case				=			import_main_class(dataset_module.module_path     )
 snake_case				=			builder_cls(
     cache_dir=a					,   config_name='''20220301.frr'''					,   hash=dataset_module.hash					,   )
 # use the HF cloud storage, not the original download_and_prepare that uses apache-beam
 snake_case				=			None
 builder_instance.download_and_prepare()
 snake_case				=			builder_instance.as_dataset()
 assert ds






@pytest.mark.integration
def    __UpperCamelCase	(	a    : Any     ) ->Union[str, Any]:
 snake_case				=			dataset_module_factory('''wikipedia'''					,   cache_dir=a     )
 snake_case				=			import_main_class(dataset_module.module_path					,   dataset=a     )
 snake_case				=			builder_cls(
     cache_dir=a					,   config_name='''20220301.frr'''					,   hash=dataset_module.hash					,   )
 snake_case				=			builder_instance.as_streaming_dataset()
 assert ds
 assert isinstance(a					,   a     )
 assert "train" in ds
 assert isinstance(ds['''train''']					,   a     )
 assert next(iter(ds['''train''']     )     )

