<s> """<STR_LIT>""" <EOL> import sys as _sys <EOL> __all__ = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> pyver = float ( '<STR_LIT>' % _sys . version_info [ : <NUM_LIT:2> ] ) <EOL> try : <EOL> any <EOL> except NameError : <EOL> def any ( iterable ) : <EOL> for element in iterable : <EOL> if element : <EOL> return True <EOL> return False <EOL> try : <EOL> from collections import OrderedDict <EOL> except ImportError : <EOL> OrderedDict = None <EOL> try : <EOL> basestring <EOL> except NameError : <EOL> basestring = str <EOL> class _RouteClassAttributeToGetattr ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , fget = None ) : <EOL> self . fget = fget <EOL> def __get__ ( self , instance , ownerclass = None ) : <EOL> if instance is None : <EOL> raise AttributeError ( ) <EOL> return self . fget ( instance ) <EOL> def __set__ ( self , instance , value ) : <EOL> raise AttributeError ( "<STR_LIT>" ) <EOL> def __delete__ ( self , instance ) : <EOL> raise AttributeError ( "<STR_LIT>" ) <EOL> def _is_descriptor ( obj ) : <EOL> """<STR_LIT>""" <EOL> return ( <EOL> hasattr ( obj , '<STR_LIT>' ) or <EOL> hasattr ( obj , '<STR_LIT>' ) or <EOL> hasattr ( obj , '<STR_LIT>' ) ) <EOL> def _is_dunder ( name ) : <EOL> """<STR_LIT>""" <EOL> return ( name [ : <NUM_LIT:2> ] == name [ - <NUM_LIT:2> : ] == '<STR_LIT>' and <EOL> name [ <NUM_LIT:2> : <NUM_LIT:3> ] != '<STR_LIT:_>' and <EOL> name [ - <NUM_LIT:3> : - <NUM_LIT:2> ] != '<STR_LIT:_>' and <EOL> len ( name ) > <NUM_LIT:4> ) <EOL> def _is_sunder ( name ) : <EOL> """<STR_LIT>""" <EOL> return ( name [ <NUM_LIT:0> ] == name [ - <NUM_LIT:1> ] == '<STR_LIT:_>' and <EOL> name [ <NUM_LIT:1> : <NUM_LIT:2> ] != '<STR_LIT:_>' and <EOL> name [ - <NUM_LIT:2> : - <NUM_LIT:1> ] != '<STR_LIT:_>' and <EOL> len ( name ) > <NUM_LIT:2> ) <EOL> def _make_class_unpicklable ( cls ) : <EOL> """<STR_LIT>""" <EOL> def _break_on_call_reduce ( self , protocol = None ) : <EOL> raise TypeError ( '<STR_LIT>' % self ) <EOL> cls . __reduce_ex__ = _break_on_call_reduce <EOL> cls . __module__ = '<STR_LIT>' <EOL> class _EnumDict ( dict ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> super ( _EnumDict , self ) . __init__ ( ) <EOL> self . _member_names = [ ] <EOL> def __setitem__ ( self , key , value ) : <EOL> """<STR_LIT>""" <EOL> if pyver >= <NUM_LIT> and key == '<STR_LIT>' : <EOL> return <EOL> if _is_sunder ( key ) : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> elif _is_dunder ( key ) : <EOL> pass <EOL> elif key in self . _member_names : <EOL> raise TypeError ( '<STR_LIT>' % key ) <EOL> elif not _is_descriptor ( value ) : <EOL> if key in self : <EOL> raise TypeError ( '<STR_LIT>' % self [ key ] ) <EOL> self . _member_names . append ( key ) <EOL> super ( _EnumDict , self ) . __setitem__ ( key , value ) <EOL> Enum = None <EOL> class EnumMeta ( type ) : <EOL> """<STR_LIT>""" <EOL> @ classmethod <EOL> def __prepare__ ( metacls , cls , bases ) : <EOL> return _EnumDict ( ) <EOL> def __new__ ( metacls , cls , bases , classdict ) : <EOL> if type ( classdict ) is dict : <EOL> original_dict = classdict <EOL> classdict = _EnumDict ( ) <EOL> for k , v in original_dict . items ( ) : <EOL> classdict [ k ] = v <EOL> member_type , first_enum = metacls . _get_mixins_ ( bases ) <EOL> __new__ , save_new , use_args = metacls . _find_new_ ( classdict , member_type , <EOL> first_enum ) <EOL> members = dict ( ( k , classdict [ k ] ) for k in classdict . _member_names ) <EOL> for name in classdict . _member_names : <EOL> del classdict [ name ] <EOL> __order__ = classdict . get ( '<STR_LIT>' ) <EOL> if __order__ is None : <EOL> if pyver < <NUM_LIT> : <EOL> __order__ = [ name for ( name , value ) in sorted ( members . items ( ) , key = lambda item : item [ <NUM_LIT:1> ] ) ] <EOL> else : <EOL> __order__ = classdict . _member_names <EOL> else : <EOL> del classdict [ '<STR_LIT>' ] <EOL> if pyver < <NUM_LIT> : <EOL> __order__ = __order__ . replace ( '<STR_LIT:U+002C>' , '<STR_LIT:U+0020>' ) . split ( ) <EOL> aliases = [ name for name in members if name not in __order__ ] <EOL> __order__ += aliases <EOL> invalid_names = set ( members ) & set ( [ '<STR_LIT>' ] ) <EOL> if invalid_names : <EOL> raise ValueError ( '<STR_LIT>' % ( <EOL> '<STR_LIT:U+002CU+0020>' . join ( invalid_names ) , ) ) <EOL> enum_class = super ( EnumMeta , metacls ) . __new__ ( metacls , cls , bases , classdict ) <EOL> enum_class . _member_names_ = [ ] <EOL> if OrderedDict is not None : <EOL> enum_class . _member_map_ = OrderedDict ( ) <EOL> else : <EOL> enum_class . _member_map_ = { } <EOL> enum_class . _member_type_ = member_type <EOL> enum_class . _value2member_map_ = { } <EOL> if __new__ is None : <EOL> __new__ = enum_class . __new__ <EOL> for member_name in __order__ : <EOL> value = members [ member_name ] <EOL> if not isinstance ( value , tuple ) : <EOL> args = ( value , ) <EOL> else : <EOL> args = value <EOL> if member_type is tuple : <EOL> args = ( args , ) <EOL> if not use_args or not args : <EOL> enum_member = __new__ ( enum_class ) <EOL> if not hasattr ( enum_member , '<STR_LIT>' ) : <EOL> enum_member . _value_ = value <EOL> else : <EOL> enum_member = __new__ ( enum_class , * args ) <EOL> if not hasattr ( enum_member , '<STR_LIT>' ) : <EOL> enum_member . _value_ = member_type ( * args ) <EOL> value = enum_member . _value_ <EOL> enum_member . _name_ = member_name <EOL> enum_member . __objclass__ = enum_class <EOL> enum_member . __init__ ( * args ) <EOL> for name , canonical_member in enum_class . _member_map_ . items ( ) : <EOL> if canonical_member . value == enum_member . _value_ : <EOL> enum_member = canonical_member <EOL> break <EOL> else : <EOL> enum_class . _member_names_ . append ( member_name ) <EOL> enum_class . _member_map_ [ member_name ] = enum_member <EOL> try : <EOL> enum_class . _value2member_map_ [ value ] = enum_member <EOL> except TypeError : <EOL> pass <EOL> unpicklable = False <EOL> if '<STR_LIT>' not in classdict : <EOL> if member_type is not object : <EOL> methods = ( '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ) <EOL> if not any ( m in member_type . __dict__ for m in methods ) : <EOL> _make_class_unpicklable ( enum_class ) <EOL> unpicklable = True <EOL> for name in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> class_method = getattr ( enum_class , name ) <EOL> obj_method = getattr ( member_type , name , None ) <EOL> enum_method = getattr ( first_enum , name , None ) <EOL> if name not in classdict and class_method is not enum_method : <EOL> if name == '<STR_LIT>' and unpicklable : <EOL> continue <EOL> setattr ( enum_class , name , enum_method ) <EOL> if pyver < <NUM_LIT> : <EOL> if issubclass ( enum_class , int ) : <EOL> setattr ( enum_class , '<STR_LIT>' , getattr ( int , '<STR_LIT>' ) ) <EOL> elif pyver < <NUM_LIT> : <EOL> if issubclass ( enum_class , int ) : <EOL> for method in ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ) : <EOL> setattr ( enum_class , method , getattr ( int , method ) ) <EOL> if Enum is not None : <EOL> if save_new : <EOL> setattr ( enum_class , '<STR_LIT>' , enum_class . __dict__ [ '<STR_LIT>' ] ) <EOL> setattr ( enum_class , '<STR_LIT>' , Enum . __dict__ [ '<STR_LIT>' ] ) <EOL> return enum_class <EOL> def __call__ ( cls , value , names = None , module = None , type = None ) : <EOL> """<STR_LIT>""" <EOL> if names is None : <EOL> return cls . __new__ ( cls , value ) <EOL> return cls . _create_ ( value , names , module = module , type = type ) <EOL> def __contains__ ( cls , member ) : <EOL> return isinstance ( member , cls ) and member . name in cls . _member_map_ <EOL> def __delattr__ ( cls , attr ) : <EOL> if attr in cls . _member_map_ : <EOL> raise AttributeError ( <EOL> "<STR_LIT>" % cls . __name__ ) <EOL> super ( EnumMeta , cls ) . __delattr__ ( attr ) <EOL> def __dir__ ( self ) : <EOL> return ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] + <EOL> self . _member_names_ ) <EOL> @ property <EOL> def __members__ ( cls ) : <EOL> """<STR_LIT>""" <EOL> return cls . _member_map_ . copy ( ) <EOL> def __getattr__ ( cls , name ) : <EOL> """<STR_LIT>""" <EOL> if _is_dunder ( name ) : <EOL> raise AttributeError ( name ) <EOL> try : <EOL> return cls . _member_map_ [ name ] <EOL> except KeyError : <EOL> raise AttributeError ( name ) <EOL> def __getitem__ ( cls , name ) : <EOL> return cls . _member_map_ [ name ] <EOL> def __iter__ ( cls ) : <EOL> return ( cls . _member_map_ [ name ] for name in cls . _member_names_ ) <EOL> def __reversed__ ( cls ) : <EOL> return ( cls . _member_map_ [ name ] for name in reversed ( cls . _member_names_ ) ) <EOL> def __len__ ( cls ) : <EOL> return len ( cls . _member_names_ ) <EOL> def __repr__ ( cls ) : <EOL> return "<STR_LIT>" % cls . __name__ <EOL> def __setattr__ ( cls , name , value ) : <EOL> """<STR_LIT>""" <EOL> member_map = cls . __dict__ . get ( '<STR_LIT>' , { } ) <EOL> if name in member_map : <EOL> raise AttributeError ( '<STR_LIT>' ) <EOL> super ( EnumMeta , cls ) . __setattr__ ( name , value ) <EOL> def _create_ ( cls , class_name , names = None , module = None , type = None ) : <EOL> """<STR_LIT>""" <EOL> metacls = cls . __class__ <EOL> if type is None : <EOL> bases = ( cls , ) <EOL> else : <EOL> bases = ( type , cls ) <EOL> classdict = metacls . __prepare__ ( class_name , bases ) <EOL> __order__ = [ ] <EOL> if isinstance ( names , basestring ) : <EOL> names = names . replace ( '<STR_LIT:U+002C>' , '<STR_LIT:U+0020>' ) . split ( ) <EOL> if isinstance ( names , ( tuple , list ) ) and isinstance ( names [ <NUM_LIT:0> ] , basestring ) : <EOL> names = [ ( e , i + <NUM_LIT:1> ) for ( i , e ) in enumerate ( names ) ] <EOL> for item in names : <EOL> if isinstance ( item , basestring ) : <EOL> member_name , member_value = item , names [ item ] <EOL> else : <EOL> member_name , member_value = item <EOL> classdict [ member_name ] = member_value <EOL> __order__ . append ( member_name ) <EOL> if not isinstance ( item , basestring ) : <EOL> classdict [ '<STR_LIT>' ] = '<STR_LIT:U+0020>' . join ( __order__ ) <EOL> enum_class = metacls . __new__ ( metacls , class_name , bases , classdict ) <EOL> if module is None : <EOL> try : <EOL> module = _sys . _getframe ( <NUM_LIT:2> ) . f_globals [ '<STR_LIT>' ] <EOL> except ( AttributeError , ValueError ) : <EOL> pass <EOL> if module is None : <EOL> _make_class_unpicklable ( enum_class ) <EOL> else : <EOL> enum_class . __module__ = module <EOL> return enum_class <EOL> @ staticmethod <EOL> def _get_mixins_ ( bases ) : <EOL> """<STR_LIT>""" <EOL> if not bases or Enum is None : <EOL> return object , Enum <EOL> member_type = first_enum = None <EOL> for base in bases : <EOL> if ( base is not Enum and <EOL> issubclass ( base , Enum ) and <EOL> base . _member_names_ ) : <EOL> raise TypeError ( "<STR_LIT>" ) <EOL> if not issubclass ( base , Enum ) : <EOL> raise TypeError ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> if not issubclass ( bases [ <NUM_LIT:0> ] , Enum ) : <EOL> member_type = bases [ <NUM_LIT:0> ] <EOL> first_enum = bases [ - <NUM_LIT:1> ] <EOL> else : <EOL> for base in bases [ <NUM_LIT:0> ] . __mro__ : <EOL> if issubclass ( base , Enum ) : <EOL> if first_enum is None : <EOL> first_enum = base <EOL> else : <EOL> if member_type is None : <EOL> member_type = base <EOL> return member_type , first_enum <EOL> if pyver < <NUM_LIT> : <EOL> @ staticmethod <EOL> def _find_new_ ( classdict , member_type , first_enum ) : <EOL> """<STR_LIT>""" <EOL> __new__ = classdict . get ( '<STR_LIT>' , None ) <EOL> if __new__ : <EOL> return None , True , True <EOL> N__new__ = getattr ( None , '<STR_LIT>' ) <EOL> O__new__ = getattr ( object , '<STR_LIT>' ) <EOL> if Enum is None : <EOL> E__new__ = N__new__ <EOL> else : <EOL> E__new__ = Enum . __dict__ [ '<STR_LIT>' ] <EOL> for method in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> for possible in ( member_type , first_enum ) : <EOL> try : <EOL> target = possible . __dict__ [ method ] <EOL> except ( AttributeError , KeyError ) : <EOL> target = getattr ( possible , method , None ) <EOL> if target not in [ <EOL> None , <EOL> N__new__ , <EOL> O__new__ , <EOL> E__new__ , <EOL> ] : <EOL> if method == '<STR_LIT>' : <EOL> classdict [ '<STR_LIT>' ] = target <EOL> return None , False , True <EOL> if isinstance ( target , staticmethod ) : <EOL> target = target . __get__ ( member_type ) <EOL> __new__ = target <EOL> break <EOL> if __new__ is not None : <EOL> break <EOL> else : <EOL> __new__ = object . __new__ <EOL> if __new__ is object . __new__ : <EOL> use_args = False <EOL> else : <EOL> use_args = True <EOL> return __new__ , False , use_args <EOL> else : <EOL> @ staticmethod <EOL> def _find_new_ ( classdict , member_type , first_enum ) : <EOL> """<STR_LIT>""" <EOL> __new__ = classdict . get ( '<STR_LIT>' , None ) <EOL> save_new = __new__ is not None <EOL> if __new__ is None : <EOL> for method in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> for possible in ( member_type , first_enum ) : <EOL> target = getattr ( possible , method , None ) <EOL> if target not in ( <EOL> None , <EOL> None . __new__ , <EOL> object . __new__ , <EOL> Enum . __new__ , <EOL> ) : <EOL> __new__ = target <EOL> break <EOL> if __new__ is not None : <EOL> break <EOL> else : <EOL> __new__ = object . __new__ <EOL> if __new__ is object . __new__ : <EOL> use_args = False <EOL> else : <EOL> use_args = True <EOL> return __new__ , save_new , use_args <EOL> temp_enum_dict = { } <EOL> temp_enum_dict [ '<STR_LIT>' ] = "<STR_LIT>" <EOL> def __new__ ( cls , value ) : <EOL> if type ( value ) is cls : <EOL> value = value . value <EOL> try : <EOL> if value in cls . _value2member_map_ : <EOL> return cls . _value2member_map_ [ value ] <EOL> except TypeError : <EOL> for member in cls . _member_map_ . values ( ) : <EOL> if member . value == value : <EOL> return member <EOL> raise ValueError ( "<STR_LIT>" % ( value , cls . __name__ ) ) <EOL> temp_enum_dict [ '<STR_LIT>' ] = __new__ <EOL> del __new__ <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % ( <EOL> self . __class__ . __name__ , self . _name_ , self . _value_ ) <EOL> temp_enum_dict [ '<STR_LIT>' ] = __repr__ <EOL> del __repr__ <EOL> def __str__ ( self ) : <EOL> return "<STR_LIT>" % ( self . __class__ . __name__ , self . _name_ ) <EOL> temp_enum_dict [ '<STR_LIT>' ] = __str__ <EOL> del __str__ <EOL> def __dir__ ( self ) : <EOL> added_behavior = [ m for m in self . __class__ . __dict__ if m [ <NUM_LIT:0> ] != '<STR_LIT:_>' ] <EOL> return ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:name>' , '<STR_LIT:value>' ] + added_behavior ) <EOL> temp_enum_dict [ '<STR_LIT>' ] = __dir__ <EOL> del __dir__ <EOL> def __format__ ( self , format_spec ) : <EOL> if self . _member_type_ is object : <EOL> cls = str <EOL> val = str ( self ) <EOL> else : <EOL> cls = self . _member_type_ <EOL> val = self . value <EOL> return cls . __format__ ( val , format_spec ) <EOL> temp_enum_dict [ '<STR_LIT>' ] = __format__ <EOL> del __format__ <EOL> if pyver < <NUM_LIT> : <EOL> def __cmp__ ( self , other ) : <EOL> if type ( other ) is self . __class__ : <EOL> if self is other : <EOL> return <NUM_LIT:0> <EOL> return - <NUM_LIT:1> <EOL> return NotImplemented <EOL> raise TypeError ( "<STR_LIT>" % ( self . __class__ . __name__ , other . __class__ . __name__ ) ) <EOL> temp_enum_dict [ '<STR_LIT>' ] = __cmp__ <EOL> del __cmp__ <EOL> else : <EOL> def __le__ ( self , other ) : <EOL> raise TypeError ( "<STR_LIT>" % ( self . __class__ . __name__ , other . __class__ . __name__ ) ) <EOL> temp_enum_dict [ '<STR_LIT>' ] = __le__ <EOL> del __le__ <EOL> def __lt__ ( self , other ) : <EOL> raise TypeError ( "<STR_LIT>" % ( self . __class__ . __name__ , other . __class__ . __name__ ) ) <EOL> temp_enum_dict [ '<STR_LIT>' ] = __lt__ <EOL> del __lt__ <EOL> def __ge__ ( self , other ) : <EOL> raise TypeError ( "<STR_LIT>" % ( self . __class__ . __name__ , other . __class__ . __name__ ) ) <EOL> temp_enum_dict [ '<STR_LIT>' ] = __ge__ <EOL> del __ge__ <EOL> def __gt__ ( self , other ) : <EOL> raise TypeError ( "<STR_LIT>" % ( self . __class__ . __name__ , other . __class__ . __name__ ) ) <EOL> temp_enum_dict [ '<STR_LIT>' ] = __gt__ <EOL> del __gt__ <EOL> def __eq__ ( self , other ) : <EOL> if type ( other ) is self . __class__ : <EOL> return self is other <EOL> return NotImplemented <EOL> temp_enum_dict [ '<STR_LIT>' ] = __eq__ <EOL> del __eq__ <EOL> def __ne__ ( self , other ) : <EOL> if type ( other ) is self . __class__ : <EOL> return self is not other <EOL> return NotImplemented <EOL> temp_enum_dict [ '<STR_LIT>' ] = __ne__ <EOL> del __ne__ <EOL> def __hash__ ( self ) : <EOL> return hash ( self . _name_ ) <EOL> temp_enum_dict [ '<STR_LIT>' ] = __hash__ <EOL> del __hash__ <EOL> def __reduce_ex__ ( self , proto ) : <EOL> return self . __class__ , ( self . _value_ , ) <EOL> temp_enum_dict [ '<STR_LIT>' ] = __reduce_ex__ <EOL> del __reduce_ex__ <EOL> @ _RouteClassAttributeToGetattr <EOL> def name ( self ) : <EOL> return self . _name_ <EOL> temp_enum_dict [ '<STR_LIT:name>' ] = name <EOL> del name <EOL> @ _RouteClassAttributeToGetattr <EOL> def value ( self ) : <EOL> return self . _value_ <EOL> temp_enum_dict [ '<STR_LIT:value>' ] = value <EOL> del value <EOL> Enum = EnumMeta ( '<STR_LIT>' , ( object , ) , temp_enum_dict ) <EOL> del temp_enum_dict <EOL> class IntEnum ( int , Enum ) : <EOL> """<STR_LIT>""" <EOL> def unique ( enumeration ) : <EOL> """<STR_LIT>""" <EOL> duplicates = [ ] <EOL> for name , member in enumeration . __members__ . items ( ) : <EOL> if name != member . name : <EOL> duplicates . append ( ( name , member . name ) ) <EOL> if duplicates : <EOL> duplicate_names = '<STR_LIT:U+002CU+0020>' . join ( <EOL> [ "<STR_LIT>" % ( alias , name ) for ( alias , name ) in duplicates ] <EOL> ) <EOL> raise ValueError ( '<STR_LIT>' % <EOL> ( enumeration , duplicate_names ) <EOL> ) <EOL> return enumeration <EOL> class OrderedEnum ( Enum ) : <EOL> """<STR_LIT>""" <EOL> def __ge__ ( self , other ) : <EOL> if self . __class__ is other . __class__ : <EOL> return self . value >= other . value <EOL> return NotImplemented <EOL> def __gt__ ( self , other ) : <EOL> if self . __class__ is other . __class__ : <EOL> return self . value > other . value <EOL> return NotImplemented <EOL> def __le__ ( self , other ) : <EOL> if self . __class__ is other . __class__ : <EOL> return self . value <= other . value <EOL> return NotImplemented <EOL> def __lt__ ( self , other ) : <EOL> if self . __class__ is other . __class__ : <EOL> return self . value < other . value <EOL> return NotImplemented </s>
