<s> try : <EOL> from uuid import UUID <EOL> except ImportError : <EOL> pass <EOL> from bson . py3compat import PY3 , binary_type <EOL> """<STR_LIT>""" <EOL> BINARY_SUBTYPE = <NUM_LIT:0> <EOL> """<STR_LIT>""" <EOL> FUNCTION_SUBTYPE = <NUM_LIT:1> <EOL> """<STR_LIT>""" <EOL> OLD_BINARY_SUBTYPE = <NUM_LIT:2> <EOL> """<STR_LIT>""" <EOL> OLD_UUID_SUBTYPE = <NUM_LIT:3> <EOL> """<STR_LIT>""" <EOL> UUID_SUBTYPE = <NUM_LIT:4> <EOL> """<STR_LIT>""" <EOL> JAVA_LEGACY = <NUM_LIT:5> <EOL> """<STR_LIT>""" <EOL> CSHARP_LEGACY = <NUM_LIT:6> <EOL> """<STR_LIT>""" <EOL> ALL_UUID_SUBTYPES = ( OLD_UUID_SUBTYPE , UUID_SUBTYPE , JAVA_LEGACY , CSHARP_LEGACY ) <EOL> MD5_SUBTYPE = <NUM_LIT:5> <EOL> """<STR_LIT>""" <EOL> USER_DEFINED_SUBTYPE = <NUM_LIT> <EOL> """<STR_LIT>""" <EOL> class Binary ( binary_type ) : <EOL> """<STR_LIT>""" <EOL> _type_marker = <NUM_LIT:5> <EOL> def __new__ ( cls , data , subtype = BINARY_SUBTYPE ) : <EOL> if not isinstance ( data , binary_type ) : <EOL> raise TypeError ( "<STR_LIT>" <EOL> "<STR_LIT>" % ( binary_type . __name__ , ) ) <EOL> if not isinstance ( subtype , int ) : <EOL> raise TypeError ( "<STR_LIT>" ) <EOL> if subtype >= <NUM_LIT> or subtype < <NUM_LIT:0> : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> self = binary_type . __new__ ( cls , data ) <EOL> self . __subtype = subtype <EOL> return self <EOL> @ property <EOL> def subtype ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . __subtype <EOL> def __getnewargs__ ( self ) : <EOL> data = super ( Binary , self ) . __getnewargs__ ( ) [ <NUM_LIT:0> ] <EOL> if PY3 and not isinstance ( data , binary_type ) : <EOL> data = data . encode ( '<STR_LIT>' ) <EOL> return data , self . __subtype <EOL> def __eq__ ( self , other ) : <EOL> if isinstance ( other , Binary ) : <EOL> return ( ( self . __subtype , binary_type ( self ) ) == <EOL> ( other . subtype , binary_type ( other ) ) ) <EOL> return False <EOL> def __ne__ ( self , other ) : <EOL> return not self == other <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % ( binary_type . __repr__ ( self ) , self . __subtype ) <EOL> class UUIDLegacy ( Binary ) : <EOL> """<STR_LIT>""" <EOL> def __new__ ( cls , obj ) : <EOL> if not isinstance ( obj , UUID ) : <EOL> raise TypeError ( "<STR_LIT>" ) <EOL> self = Binary . __new__ ( cls , binary_type ( obj . bytes ) , OLD_UUID_SUBTYPE ) <EOL> self . __uuid = obj <EOL> return self <EOL> def __getnewargs__ ( self ) : <EOL> return ( self . __uuid , ) <EOL> @ property <EOL> def uuid ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . __uuid <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % self . __uuid </s>
