



snake_case__					:     Union[str, Any]    		=   """ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"""



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

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

	__lowercase		       =			len(_SCREAMING_SNAKE_CASE   ) % 6 != 0

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



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

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

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

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

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

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

	return bytes(_SCREAMING_SNAKE_CASE   )


if __name__ == "__main__":
	import doctest

	doctest.testmod()








from __future__ import annotations

from collections.abc import Callable
from typing import Generic, TypeVar

snake_case__					:     Union[str, Any]    		=   TypeVar("""T""")
snake_case__					:     Optional[int]    		=   TypeVar("""U""")

class   _A   ( Generic[T, U]	):


						'''simple docstring'''





						def __init__(	self	:							Optional[int]							,      lowerCamelCase	:							T | None							,      lowerCamelCase	:							U | None	):






							'''simple docstring'''



							__lowercase		       =			key
							__lowercase		       =			val
							__lowercase		       =			None
							__lowercase		       =			None



						def __repr__(	self	:							Any	):






							'''simple docstring'''



							return (
							    f"""Node: key: {self.key}, val: {self.val}, """
							    f"""has next: {bool(self.next	)}, has prev: {bool(self.prev	)}"""
							)

class   _A   ( Generic[T, U]	):


						'''simple docstring'''





						def __init__(	self	:							Dict	):






							'''simple docstring'''



							__lowercase		       =			DoubleLinkedListNode(lowerCamelCase							,      lowerCamelCase	)
							__lowercase		       =			DoubleLinkedListNode(lowerCamelCase							,      lowerCamelCase	)
							__lowercase       ,    __lowercase		       =			self.rear, self.head



						def __repr__(	self	:							Optional[Any]	):






							'''simple docstring'''



							__lowercase		       =			["DoubleLinkedList"]
							__lowercase		       =			self.head
							while node.next is not None:
								rep.append(str(lowerCamelCase	)	)
								__lowercase		       =			node.next
							rep.append(str(self.rear	)	)
							return ",\n    ".join(lowerCamelCase	)



						def     _snake_case	(	self	:							Union[str, Any]							,      lowerCamelCase	:							DoubleLinkedListNode[T, U]	):






							'''simple docstring'''



							__lowercase		       =			self.rear.prev

							# All nodes other than self.head are guaranteed to have non-None previous
							assert previous is not None

							__lowercase		       =			node
							__lowercase		       =			previous
							__lowercase		       =			node
							__lowercase		       =			self.rear



						def     _snake_case	(	self	:							Optional[int]							,      lowerCamelCase	:							DoubleLinkedListNode[T, U]	):






							'''simple docstring'''



							if node.prev is None or node.next is None:
								return None

							__lowercase		       =			node.next
							__lowercase		       =			node.prev
							__lowercase		       =			None
							__lowercase		       =			None
							return node

class   _A   ( Generic[T, U]	):


						'''simple docstring'''





						_snake_case			:     dict[Callable[[T], U], LRUCache[T, U]]      							=      {}



						def __init__(	self	:							List[Any]							,      lowerCamelCase	:							int	):






							'''simple docstring'''



							__lowercase		       =			DoubleLinkedList()
							__lowercase		       =			capacity
							__lowercase		       =			0
							__lowercase		       =			0
							__lowercase		       =			0
							__lowercase		       =			{}



						def __repr__(	self	:							Optional[Any]	):






							'''simple docstring'''



							return (
							    f"""CacheInfo(hits={self.hits}, misses={self.miss}, """
							    f"""capacity={self.capacity}, current size={self.num_keys})"""
							)



						def __contains__(	self	:							Dict							,      lowerCamelCase	:							T	):






							'''simple docstring'''



							return key in self.cache



						def     _snake_case	(	self	:							List[Any]							,      lowerCamelCase	:							T	):






							'''simple docstring'''



							if key in self.cache:
								self.hits += 1
								__lowercase		       =			self.cache[key]
								__lowercase		       =			self.list.remove(self.cache[key]	)
								assert node == value_node

								# node is guaranteed not None because it is in self.cache
								assert node is not None
								self.list.add(lowerCamelCase	)
								return node.val
							self.miss += 1
							return None



						def     _snake_case	(	self	:							Union[str, Any]							,      lowerCamelCase	:							T							,      lowerCamelCase	:							U	):






							'''simple docstring'''



							if key not in self.cache:
								if self.num_keys >= self.capacity:
									# delete first node (oldest) when over capacity
									__lowercase		       =			self.list.head.next

									# guaranteed to have a non-None first node when num_keys > 0
									# explain to type checker via assertions
									assert first_node is not None
									assert first_node.key is not None
									assert (
									    self.list.remove(lowerCamelCase	) is not None
									)  # node guaranteed to be in list assert node.key is not None

									del self.cache[first_node.key]
									self.num_keys -= 1
								__lowercase		       =			DoubleLinkedListNode(lowerCamelCase							,      lowerCamelCase	)
								self.list.add(self.cache[key]	)
								self.num_keys += 1

							else:
								# bump node to the end of the list, update value
								__lowercase		       =			self.list.remove(self.cache[key]	)
								assert node is not None  # node guaranteed to be in list
								__lowercase		       =			value
								self.list.add(lowerCamelCase	)



						@classmethod
						def     _snake_case	(	cls	:							Union[str, Any]							,      lowerCamelCase	:							int = 128	):






							'''simple docstring'''



							def cache_decorator_inner(lowerCamelCase	:							Callable[[T], U]	) -> Callable[..., U]:
								def cache_decorator_wrapper(*lowerCamelCase	:							T	) -> U:
									if func not in cls.decorator_function_to_instance_map:
										__lowercase		       =			LRUCache(lowerCamelCase	)

									__lowercase		       =			cls.decorator_function_to_instance_map[func].get(args[0]	)
									if result is None:
										__lowercase		       =			func(*lowerCamelCase	)
										cls.decorator_function_to_instance_map[func].put(args[0]							,      lowerCamelCase	)
									return result

								def cache_info() -> LRUCache[T, U]:
									return cls.decorator_function_to_instance_map[func]

								setattr(lowerCamelCase							,      "cache_info"							,      lowerCamelCase	)  # noqa: B010

								return cache_decorator_wrapper

							return cache_decorator_inner


if __name__ == "__main__":
	import doctest

	doctest.testmod()



