


snake_case							:       Dict     			=      '''ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'''






def 							__lowercase   ( __lowerCAmelCase							:				bytes   ):
							# Make sure the supplied data is a bytes-like object
							if not isinstance(__lowerCAmelCase					,    __lowerCAmelCase   ):
														a__             =     F'a bytes-like object is required, not \'{data.__class__.__name__}\''
														raise TypeError(__lowerCAmelCase   )

							a__             =     ''.join(bin(__lowerCAmelCase   )[2:].zfill(8   ) for byte in data   )

							a__             =     len(__lowerCAmelCase   ) % 6 != 0

							if padding_needed:
														# The padding that will be added later
														a__             =     b'=' * ((6 - len(__lowerCAmelCase   ) % 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(__lowerCAmelCase   ) % 6)
							else:
														a__             =     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(__lowerCAmelCase   )					,    6   )   ).encode()
							    + padding
							)






def 							__lowercase   ( __lowerCAmelCase							:				str   ):
							# Make sure encoded_data is either a string or a bytes-like object
							if not isinstance(__lowerCAmelCase					,    __lowerCAmelCase   ) and not isinstance(__lowerCAmelCase					,    __lowerCAmelCase   ):
														a__             =     (
														    'argument should be a bytes-like object or ASCII string, '
														    F'not \'{encoded_data.__class__.__name__}\''
														)
														raise TypeError(__lowerCAmelCase   )

							# 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(__lowerCAmelCase					,    __lowerCAmelCase   ):
														try:
																					a__             =     encoded_data.decode('utf-8'   )
														except UnicodeDecodeError:
																					raise ValueError('base64 encoded data should only contain ASCII characters'   )

							a__             =     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(__lowerCAmelCase   ) % 4 == 0 and padding < 3, "Incorrect padding"

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

														a__             =     ''.join(
														    bin(B64_CHARSET.index(__lowerCAmelCase   )   )[2:].zfill(6   ) for char in encoded_data   )[: -padding * 2]
							else:
														a__             =     ''.join(
														    bin(B64_CHARSET.index(__lowerCAmelCase   )   )[2:].zfill(6   ) for char in encoded_data   )

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

							return bytes(__lowerCAmelCase   )


if __name__ == "__main__":
						import doctest

						doctest.testmod()








import sys

from .dependency_versions_table import deps
from .utils.versions import require_version, require_version_core


# define which module versions we always want to check at run time
# (usually the ones defined in `install_requires` in setup.py)
#
# order specific notes:
# - tqdm must be checked before tokenizers

snake_case							:       List[str]     			=      '''python tqdm regex requests packaging filelock numpy tokenizers'''.split()
if sys.version_info < (3, 7):
						pkgs_to_check_at_runtime.append('''dataclasses''')
if sys.version_info < (3, 8):
						pkgs_to_check_at_runtime.append('''importlib_metadata''')

for pkg in pkgs_to_check_at_runtime:
						if pkg in deps:
												if pkg == "tokenizers":
																		# must be loaded here, or else tqdm check may fail
																		from .utils import is_tokenizers_available

																		if not is_tokenizers_available():
																								continue  # not required, check version only if installed

												require_version_core(deps[pkg])
						else:
												raise ValueError(f"""can't find {pkg} in {deps.keys()}, check dependency_versions_table.py""")






def 							__lowercase   ( __lowerCAmelCase							:				Optional[Any]					,    __lowerCAmelCase							:				Tuple=None   ):
							require_version(deps[pkg]					,    __lowerCAmelCase   )




