





"""simple docstring"""




lowerCamelCase_     :						Optional[Any]						=					'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'





def 						UpperCAmelCase__		(     _UpperCAmelCase					):






  """simple docstring"""





  if not isinstance(_UpperCAmelCase ,					_UpperCAmelCase					):
    A_  :       List[Any]										=  f"""a bytes-like object is required, not '{data.__class__.__name__}'"""
    raise TypeError(_UpperCAmelCase					)

  A_  :       Optional[Any]										=  ''.join(bin(_UpperCAmelCase					)[2:].zfill(8					) for byte in data					)

  A_  :       List[str]										=  len(_UpperCAmelCase					) % 6 != 0

  if padding_needed:
    # The padding that will be added later
    A_  :       int										=  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:
    A_  :       Union[str, Any]										=  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__		(     _UpperCAmelCase					):






  """simple docstring"""





  if not isinstance(_UpperCAmelCase ,					_UpperCAmelCase					) and not isinstance(_UpperCAmelCase ,					_UpperCAmelCase					):
    A_  :       Union[str, Any]										=  (
        '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:
      A_  :       List[Any]										=  encoded_data.decode('utf-8'					)
    except UnicodeDecodeError:
      raise ValueError('base64 encoded data should only contain ASCII characters'					)

  A_  :       Any										=  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
    A_  :       Optional[Any]										=  encoded_data[:-padding]

    A_  :       Optional[Any]										=  ''.join(
        bin(B64_CHARSET.index(_UpperCAmelCase					)					)[2:].zfill(6					) for char in encoded_data					)[: -padding * 2]
  else:
    A_  :       Union[str, Any]										=  ''.join(
        bin(B64_CHARSET.index(_UpperCAmelCase					)					)[2:].zfill(6					) for char in encoded_data					)

  A_  :       Tuple										=  [
      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"""




def 						UpperCAmelCase__		(     _UpperCAmelCase					):






  """simple docstring"""





  A_  :       List[str]										=  hex_num.strip()
  if not hex_num:
    raise ValueError('No value was passed to the function'					)

  A_  :       Any										=  hex_num[0] == '-'
  if is_negative:
    A_  :       Optional[Any]										=  hex_num[1:]

  try:
    A_  :       Tuple										=  int(_UpperCAmelCase ,					16					)
  except ValueError:
    raise ValueError('Invalid value was passed to the function'					)

  A_  :       Union[str, Any]										=  ''
  while int_num > 0:
    A_  :       Optional[Any]										=  str(int_num % 2					) + bin_str
    int_num >>= 1

  return int(('-' + bin_str) if is_negative else bin_str					)


if __name__ == "__main__":
   import doctest

   doctest.testmod()