<s> """<STR_LIT>""" <EOL> import datetime <EOL> from collections import MutableMapping , namedtuple <EOL> from bson . py3compat import string_type <EOL> from bson . binary import ( ALL_UUID_REPRESENTATIONS , <EOL> PYTHON_LEGACY , <EOL> UUID_REPRESENTATION_NAMES ) <EOL> _RAW_BSON_DOCUMENT_MARKER = <NUM_LIT> <EOL> def _raw_document_class ( document_class ) : <EOL> """<STR_LIT>""" <EOL> marker = getattr ( document_class , '<STR_LIT>' , None ) <EOL> return marker == _RAW_BSON_DOCUMENT_MARKER <EOL> _options_base = namedtuple ( <EOL> '<STR_LIT>' , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> class CodecOptions ( _options_base ) : <EOL> """<STR_LIT>""" <EOL> def __new__ ( cls , document_class = dict , <EOL> tz_aware = False , uuid_representation = PYTHON_LEGACY , <EOL> unicode_decode_error_handler = "<STR_LIT:strict>" , <EOL> tzinfo = None ) : <EOL> if not ( issubclass ( document_class , MutableMapping ) or <EOL> _raw_document_class ( document_class ) ) : <EOL> raise TypeError ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> if not isinstance ( tz_aware , bool ) : <EOL> raise TypeError ( "<STR_LIT>" ) <EOL> if uuid_representation not in ALL_UUID_REPRESENTATIONS : <EOL> raise ValueError ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> if not isinstance ( unicode_decode_error_handler , ( string_type , None ) ) : <EOL> raise ValueError ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> if tzinfo is not None : <EOL> if not isinstance ( tzinfo , datetime . tzinfo ) : <EOL> raise TypeError ( <EOL> "<STR_LIT>" ) <EOL> if not tz_aware : <EOL> raise ValueError ( <EOL> "<STR_LIT>" ) <EOL> return tuple . __new__ ( <EOL> cls , ( document_class , tz_aware , uuid_representation , <EOL> unicode_decode_error_handler , tzinfo ) ) <EOL> def __repr__ ( self ) : <EOL> document_class_repr = ( <EOL> '<STR_LIT>' if self . document_class is dict <EOL> else repr ( self . document_class ) ) <EOL> uuid_rep_repr = UUID_REPRESENTATION_NAMES . get ( self . uuid_representation , <EOL> self . uuid_representation ) <EOL> return ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % <EOL> ( document_class_repr , self . tz_aware , uuid_rep_repr , <EOL> self . unicode_decode_error_handler , <EOL> self . tzinfo ) ) <EOL> DEFAULT_CODEC_OPTIONS = CodecOptions ( ) <EOL> def _parse_codec_options ( options ) : <EOL> """<STR_LIT>""" <EOL> return CodecOptions ( <EOL> document_class = options . get ( <EOL> '<STR_LIT>' , DEFAULT_CODEC_OPTIONS . document_class ) , <EOL> tz_aware = options . get ( <EOL> '<STR_LIT>' , DEFAULT_CODEC_OPTIONS . tz_aware ) , <EOL> uuid_representation = options . get ( <EOL> '<STR_LIT>' , DEFAULT_CODEC_OPTIONS . uuid_representation ) , <EOL> unicode_decode_error_handler = options . get ( <EOL> '<STR_LIT>' , <EOL> DEFAULT_CODEC_OPTIONS . unicode_decode_error_handler ) , <EOL> tzinfo = options . get ( '<STR_LIT>' , DEFAULT_CODEC_OPTIONS . tzinfo ) ) </s>
