<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import , print_function <EOL> import sys <EOL> import textwrap <EOL> def alias ( * aliases ) : <EOL> """<STR_LIT>""" <EOL> def decorator ( cls ) : <EOL> caller = sys . _getframe ( <NUM_LIT:1> ) <EOL> globals_dict = caller . f_globals <EOL> for alias in aliases : <EOL> globals_dict [ alias ] = cls <EOL> return cls <EOL> return decorator <EOL> class _DocsPageFormatter ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , clsname , clsdict ) : <EOL> self . _clsname = clsname <EOL> self . _clsdict = clsdict <EOL> @ property <EOL> def page_str ( self ) : <EOL> """<STR_LIT>""" <EOL> tmpl = '<STR_LIT>' <EOL> components = ( <EOL> self . _ms_name , self . _page_title , self . _intro_text , <EOL> self . _member_defs <EOL> ) <EOL> return tmpl % components <EOL> @ property <EOL> def _intro_text ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> cls_docstring = self . _clsdict [ '<STR_LIT>' ] <EOL> except KeyError : <EOL> cls_docstring = '<STR_LIT>' <EOL> return textwrap . dedent ( cls_docstring ) . strip ( ) <EOL> def _member_def ( self , member ) : <EOL> """<STR_LIT>""" <EOL> member_docstring = textwrap . dedent ( member . docstring ) . strip ( ) <EOL> member_docstring = textwrap . fill ( <EOL> member_docstring , width = <NUM_LIT> , initial_indent = '<STR_LIT:U+0020>' * <NUM_LIT:4> , <EOL> subsequent_indent = '<STR_LIT:U+0020>' * <NUM_LIT:4> <EOL> ) <EOL> return '<STR_LIT>' % ( member . name , member_docstring ) <EOL> @ property <EOL> def _member_defs ( self ) : <EOL> """<STR_LIT>""" <EOL> members = self . _clsdict [ '<STR_LIT>' ] <EOL> member_defs = [ <EOL> self . _member_def ( member ) for member in members <EOL> if member . name is not None <EOL> ] <EOL> return '<STR_LIT:\n>' . join ( member_defs ) <EOL> @ property <EOL> def _ms_name ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _clsdict [ '<STR_LIT>' ] <EOL> @ property <EOL> def _page_title ( self ) : <EOL> """<STR_LIT>""" <EOL> title_underscore = '<STR_LIT:=>' * ( len ( self . _clsname ) + <NUM_LIT:4> ) <EOL> return '<STR_LIT>' % ( self . _clsname , title_underscore ) <EOL> class MetaEnumeration ( type ) : <EOL> """<STR_LIT>""" <EOL> def __new__ ( meta , clsname , bases , clsdict ) : <EOL> meta . _add_enum_members ( clsdict ) <EOL> meta . _collect_valid_settings ( clsdict ) <EOL> meta . _generate_docs_page ( clsname , clsdict ) <EOL> return type . __new__ ( meta , clsname , bases , clsdict ) <EOL> @ classmethod <EOL> def _add_enum_members ( meta , clsdict ) : <EOL> """<STR_LIT>""" <EOL> enum_members = clsdict [ '<STR_LIT>' ] <EOL> for member in enum_members : <EOL> member . add_to_enum ( clsdict ) <EOL> @ classmethod <EOL> def _collect_valid_settings ( meta , clsdict ) : <EOL> """<STR_LIT>""" <EOL> enum_members = clsdict [ '<STR_LIT>' ] <EOL> valid_settings = [ ] <EOL> for member in enum_members : <EOL> valid_settings . extend ( member . valid_settings ) <EOL> clsdict [ '<STR_LIT>' ] = valid_settings <EOL> @ classmethod <EOL> def _generate_docs_page ( meta , clsname , clsdict ) : <EOL> """<STR_LIT>""" <EOL> clsdict [ '<STR_LIT>' ] = ( <EOL> _DocsPageFormatter ( clsname , clsdict ) . page_str <EOL> ) <EOL> class EnumerationBase ( object ) : <EOL> """<STR_LIT>""" <EOL> __members__ = ( ) <EOL> __ms_name__ = '<STR_LIT>' <EOL> @ classmethod <EOL> def validate ( cls , value ) : <EOL> """<STR_LIT>""" <EOL> if value not in cls . _valid_settings : <EOL> raise ValueError ( <EOL> "<STR_LIT>" % ( value , cls . __name__ ) <EOL> ) <EOL> Enumeration = MetaEnumeration ( <EOL> '<STR_LIT>' , ( object , ) , dict ( EnumerationBase . __dict__ ) <EOL> ) <EOL> class XmlEnumeration ( Enumeration ) : <EOL> """<STR_LIT>""" <EOL> __members__ = ( ) <EOL> __ms_name__ = '<STR_LIT>' <EOL> @ classmethod <EOL> def from_xml ( cls , xml_val ) : <EOL> """<STR_LIT>""" <EOL> return cls . _xml_to_member [ xml_val ] <EOL> @ classmethod <EOL> def to_xml ( cls , enum_val ) : <EOL> """<STR_LIT>""" <EOL> cls . validate ( enum_val ) <EOL> return cls . _member_to_xml [ enum_val ] <EOL> class EnumMember ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , name , value , docstring ) : <EOL> self . _name = name <EOL> if isinstance ( value , int ) : <EOL> value = EnumValue ( name , value , docstring ) <EOL> self . _value = value <EOL> self . _docstring = docstring <EOL> def add_to_enum ( self , clsdict ) : <EOL> """<STR_LIT>""" <EOL> self . register_name ( clsdict ) <EOL> @ property <EOL> def docstring ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _docstring <EOL> @ property <EOL> def name ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _name <EOL> def register_name ( self , clsdict ) : <EOL> """<STR_LIT>""" <EOL> if self . name is None : <EOL> return <EOL> clsdict [ self . name ] = self . value <EOL> @ property <EOL> def valid_settings ( self ) : <EOL> """<STR_LIT>""" <EOL> return ( self . _value , ) <EOL> @ property <EOL> def value ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _value <EOL> class EnumValue ( int ) : <EOL> """<STR_LIT>""" <EOL> def __new__ ( cls , member_name , int_value , docstring ) : <EOL> return super ( EnumValue , cls ) . __new__ ( cls , int_value ) <EOL> def __init__ ( self , member_name , int_value , docstring ) : <EOL> super ( EnumValue , self ) . __init__ ( ) <EOL> self . _member_name = member_name <EOL> self . _docstring = docstring <EOL> @ property <EOL> def __doc__ ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _docstring . strip ( ) <EOL> def __str__ ( self ) : <EOL> """<STR_LIT>""" <EOL> return "<STR_LIT>" . format ( self . _member_name , self ) <EOL> class ReturnValueOnlyEnumMember ( EnumMember ) : <EOL> """<STR_LIT>""" <EOL> @ property <EOL> def valid_settings ( self ) : <EOL> """<STR_LIT>""" <EOL> return ( ) <EOL> class XmlMappedEnumMember ( EnumMember ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , name , value , xml_value , docstring ) : <EOL> super ( XmlMappedEnumMember , self ) . __init__ ( name , value , docstring ) <EOL> self . _xml_value = xml_value <EOL> def add_to_enum ( self , clsdict ) : <EOL> """<STR_LIT>""" <EOL> super ( XmlMappedEnumMember , self ) . add_to_enum ( clsdict ) <EOL> self . register_xml_mapping ( clsdict ) <EOL> def register_xml_mapping ( self , clsdict ) : <EOL> """<STR_LIT>""" <EOL> member_to_xml = self . _get_or_add_member_to_xml ( clsdict ) <EOL> member_to_xml [ self . value ] = self . xml_value <EOL> xml_to_member = self . _get_or_add_xml_to_member ( clsdict ) <EOL> xml_to_member [ self . xml_value ] = self . value <EOL> @ property <EOL> def xml_value ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _xml_value <EOL> @ staticmethod <EOL> def _get_or_add_member_to_xml ( clsdict ) : <EOL> """<STR_LIT>""" <EOL> if '<STR_LIT>' not in clsdict : <EOL> clsdict [ '<STR_LIT>' ] = dict ( ) <EOL> return clsdict [ '<STR_LIT>' ] <EOL> @ staticmethod <EOL> def _get_or_add_xml_to_member ( clsdict ) : <EOL> """<STR_LIT>""" <EOL> if '<STR_LIT>' not in clsdict : <EOL> clsdict [ '<STR_LIT>' ] = dict ( ) <EOL> return clsdict [ '<STR_LIT>' ] </s>
