






a_		:    Union[str, Any]   							=     'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'






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

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

			SCREAMING_SNAKE_CASE							=			len(_UpperCAmelCase) % 6 != 0

			if padding_needed:
						# The padding that will be added later
						SCREAMING_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:
						SCREAMING_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 					lowerCamelCase__					(_UpperCAmelCase):
			# Make sure encoded_data is either a string or a bytes-like object
			if not isinstance(_UpperCAmelCase				,							_UpperCAmelCase) and not isinstance(_UpperCAmelCase				,							_UpperCAmelCase):
						SCREAMING_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:
									SCREAMING_SNAKE_CASE							=			encoded_data.decode('utf-8')
						except UnicodeDecodeError:
									raise ValueError('base64 encoded data should only contain ASCII characters')

			SCREAMING_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
						SCREAMING_SNAKE_CASE							=			encoded_data[:-padding]

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

			SCREAMING_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()






import unittest

from transformers import is_torch_available
from transformers.testing_utils import require_torch


if is_torch_available():
							import torch

							from transformers.generation import DisjunctiveConstraint

@require_torch
class 							_UpperCamelCase					(       unittest.TestCase	):






			'''simple docstring'''

			def    lowerCAmelCase__						(							self			:							Dict   ):
							# For consistency across different places the DisjunctiveConstraint is called,
							# dc.token_ids is a list of integers. It is also initialized only by integers.

							UpperCamelCase_:				Optional[int]						=    [[1, 2, 4], [1, 2, 3, 4]]
							UpperCamelCase_:				List[str]						=    DisjunctiveConstraint(snake_case_   )
							self.assertTrue(isinstance(dc.token_ids    ,						snake_case_   )   )

							with self.assertRaises(snake_case_   ):
											DisjunctiveConstraint(torch.LongTensor([[1, 2, 4], [1, 2, 3]]   )   )

							with self.assertRaises(snake_case_   ):
											DisjunctiveConstraint([torch.LongTensor([1, 2, 4]   ), torch.LongTensor([1, 2, 3, 4, 5]   )]   )

			def    lowerCAmelCase__						(							self			:							Optional[Any]   ):
							# We can't have constraints that are complete subsets of another. This leads to a preverse
							# interpretation of "constraint fulfillment": does generating [1,2,3] fulfill the constraint?
							# It would mean that it generated [1,2] which fulfills it, but it's in the middle of potentially
							# fulfilling [1,2,3,4]. If we believe that [1,2,3] does fulfill the constraint, then the algorithm
							# will necessarily never reach [1,2,3,4], giving users a false sense of control (better to just not allow it).
							UpperCamelCase_:				Dict						=    [[1, 2], [1, 2, 3, 4]]

							with self.assertRaises(snake_case_   ):
											DisjunctiveConstraint(snake_case_   )  # fails here

			def    lowerCAmelCase__						(							self			:							int   ):
							UpperCamelCase_:				Dict						=    [[1, 2, 3], [1, 2, 4]]

							UpperCamelCase_:				Dict						=    DisjunctiveConstraint(snake_case_   )

							UpperCamelCase_, UpperCamelCase_, UpperCamelCase_:				str						=    dc.update(1   )
							UpperCamelCase_:				Union[str, Any]						=    stepped is True and completed is False and reset is False
							self.assertTrue(snake_case_   )
							self.assertTrue(not dc.completed   )
							self.assertTrue(dc.current_seq == [1]   )

							UpperCamelCase_, UpperCamelCase_, UpperCamelCase_:				Optional[int]						=    dc.update(2   )
							UpperCamelCase_:				Tuple						=    stepped is True and completed is False and reset is False
							self.assertTrue(snake_case_   )
							self.assertTrue(not dc.completed   )
							self.assertTrue(dc.current_seq == [1, 2]   )

							UpperCamelCase_, UpperCamelCase_, UpperCamelCase_:				Optional[int]						=    dc.update(3   )
							UpperCamelCase_:				Union[str, Any]						=    stepped is True and completed is True and reset is False
							self.assertTrue(snake_case_   )
							self.assertTrue(dc.completed   )  # Completed!
							self.assertTrue(dc.current_seq == [1, 2, 3]   )




			def    lowerCAmelCase__						(							self			:							List[str]   ):
							UpperCamelCase_:				Optional[int]						=    [[1, 2, 3], [1, 2, 4, 5], [1, 2, 5]]

							UpperCamelCase_:				Tuple						=    DisjunctiveConstraint(snake_case_   )

							UpperCamelCase_, UpperCamelCase_, UpperCamelCase_:				Dict						=    dc.update(1   )
							self.assertTrue(not dc.completed   )
							self.assertTrue(dc.current_seq == [1]   )

							UpperCamelCase_, UpperCamelCase_, UpperCamelCase_:				Union[str, Any]						=    dc.update(2   )
							self.assertTrue(not dc.completed   )
							self.assertTrue(dc.current_seq == [1, 2]   )

							UpperCamelCase_, UpperCamelCase_, UpperCamelCase_:				Any						=    dc.update(4   )
							self.assertTrue(not dc.completed   )
							self.assertTrue(dc.current_seq == [1, 2, 4]   )

							UpperCamelCase_, UpperCamelCase_, UpperCamelCase_:				int						=    dc.update(5   )
							self.assertTrue(dc.completed   )  # Completed!
							self.assertTrue(dc.current_seq == [1, 2, 4, 5]   )

							dc.reset()

							UpperCamelCase_, UpperCamelCase_, UpperCamelCase_:				int						=    dc.update(1   )
							self.assertTrue(not dc.completed   )
							self.assertTrue(dc.remaining() == 3   )
							self.assertTrue(dc.current_seq == [1]   )

							UpperCamelCase_, UpperCamelCase_, UpperCamelCase_:				Tuple						=    dc.update(2   )
							self.assertTrue(not dc.completed   )
							self.assertTrue(dc.remaining() == 2   )
							self.assertTrue(dc.current_seq == [1, 2]   )

							UpperCamelCase_, UpperCamelCase_, UpperCamelCase_:				List[str]						=    dc.update(5   )
							self.assertTrue(dc.completed   )  # Completed!
							self.assertTrue(dc.remaining() == 0   )
							self.assertTrue(dc.current_seq == [1, 2, 5]   )






