<s> """<STR_LIT>""" <EOL> from __future__ import ( <EOL> absolute_import , division , print_function , unicode_literals <EOL> ) <EOL> from . . exceptions import InvalidXmlError <EOL> from . . shared import Emu , Pt , RGBColor , Twips <EOL> class BaseSimpleType ( object ) : <EOL> @ classmethod <EOL> def from_xml ( cls , str_value ) : <EOL> return cls . convert_from_xml ( str_value ) <EOL> @ classmethod <EOL> def to_xml ( cls , value ) : <EOL> cls . validate ( value ) <EOL> str_value = cls . convert_to_xml ( value ) <EOL> return str_value <EOL> @ classmethod <EOL> def validate_int ( cls , value ) : <EOL> if not isinstance ( value , int ) : <EOL> raise TypeError ( <EOL> "<STR_LIT>" % type ( value ) <EOL> ) <EOL> @ classmethod <EOL> def validate_int_in_range ( cls , value , min_inclusive , max_inclusive ) : <EOL> cls . validate_int ( value ) <EOL> if value < min_inclusive or value > max_inclusive : <EOL> raise ValueError ( <EOL> "<STR_LIT>" % <EOL> ( min_inclusive , max_inclusive , value ) <EOL> ) <EOL> @ classmethod <EOL> def validate_string ( cls , value ) : <EOL> if isinstance ( value , str ) : <EOL> return value <EOL> try : <EOL> if isinstance ( value , basestring ) : <EOL> return value <EOL> except NameError : <EOL> pass <EOL> raise TypeError ( <EOL> "<STR_LIT>" % type ( value ) <EOL> ) <EOL> class BaseIntType ( BaseSimpleType ) : <EOL> @ classmethod <EOL> def convert_from_xml ( cls , str_value ) : <EOL> return int ( str_value ) <EOL> @ classmethod <EOL> def convert_to_xml ( cls , value ) : <EOL> return str ( value ) <EOL> @ classmethod <EOL> def validate ( cls , value ) : <EOL> cls . validate_int ( value ) <EOL> class BaseStringType ( BaseSimpleType ) : <EOL> @ classmethod <EOL> def convert_from_xml ( cls , str_value ) : <EOL> return str_value <EOL> @ classmethod <EOL> def convert_to_xml ( cls , value ) : <EOL> return value <EOL> @ classmethod <EOL> def validate ( cls , value ) : <EOL> cls . validate_string ( value ) <EOL> class BaseStringEnumerationType ( BaseStringType ) : <EOL> @ classmethod <EOL> def validate ( cls , value ) : <EOL> cls . validate_string ( value ) <EOL> if value not in cls . _members : <EOL> raise ValueError ( <EOL> "<STR_LIT>" % ( cls . _members , value ) <EOL> ) <EOL> class XsdAnyUri ( BaseStringType ) : <EOL> """<STR_LIT>""" <EOL> class XsdBoolean ( BaseSimpleType ) : <EOL> @ classmethod <EOL> def convert_from_xml ( cls , str_value ) : <EOL> if str_value not in ( '<STR_LIT:1>' , '<STR_LIT:0>' , '<STR_LIT:true>' , '<STR_LIT:false>' ) : <EOL> raise InvalidXmlError ( <EOL> "<STR_LIT>" <EOL> % str_value <EOL> ) <EOL> return str_value in ( '<STR_LIT:1>' , '<STR_LIT:true>' ) <EOL> @ classmethod <EOL> def convert_to_xml ( cls , value ) : <EOL> return { True : '<STR_LIT:1>' , False : '<STR_LIT:0>' } [ value ] <EOL> @ classmethod <EOL> def validate ( cls , value ) : <EOL> if value not in ( True , False ) : <EOL> raise TypeError ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % value <EOL> ) <EOL> class XsdId ( BaseStringType ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class XsdInt ( BaseIntType ) : <EOL> @ classmethod <EOL> def validate ( cls , value ) : <EOL> cls . validate_int_in_range ( value , - <NUM_LIT> , <NUM_LIT> ) <EOL> class XsdLong ( BaseIntType ) : <EOL> @ classmethod <EOL> def validate ( cls , value ) : <EOL> cls . validate_int_in_range ( <EOL> value , - <NUM_LIT> , <NUM_LIT> <EOL> ) <EOL> class XsdString ( BaseStringType ) : <EOL> pass <EOL> class XsdStringEnumeration ( BaseStringEnumerationType ) : <EOL> """<STR_LIT>""" <EOL> class XsdToken ( BaseStringType ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class XsdUnsignedInt ( BaseIntType ) : <EOL> @ classmethod <EOL> def validate ( cls , value ) : <EOL> cls . validate_int_in_range ( value , <NUM_LIT:0> , <NUM_LIT> ) <EOL> class XsdUnsignedLong ( BaseIntType ) : <EOL> @ classmethod <EOL> def validate ( cls , value ) : <EOL> cls . validate_int_in_range ( value , <NUM_LIT:0> , <NUM_LIT> ) <EOL> class ST_BrClear ( XsdString ) : <EOL> @ classmethod <EOL> def validate ( cls , value ) : <EOL> cls . validate_string ( value ) <EOL> valid_values = ( '<STR_LIT:none>' , '<STR_LIT:left>' , '<STR_LIT:right>' , '<STR_LIT:all>' ) <EOL> if value not in valid_values : <EOL> raise ValueError ( <EOL> "<STR_LIT>" % ( valid_values , value ) <EOL> ) <EOL> class ST_BrType ( XsdString ) : <EOL> @ classmethod <EOL> def validate ( cls , value ) : <EOL> cls . validate_string ( value ) <EOL> valid_values = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> if value not in valid_values : <EOL> raise ValueError ( <EOL> "<STR_LIT>" % ( valid_values , value ) <EOL> ) <EOL> class ST_Coordinate ( BaseIntType ) : <EOL> @ classmethod <EOL> def convert_from_xml ( cls , str_value ) : <EOL> if '<STR_LIT:i>' in str_value or '<STR_LIT:m>' in str_value or '<STR_LIT:p>' in str_value : <EOL> return ST_UniversalMeasure . convert_from_xml ( str_value ) <EOL> return Emu ( int ( str_value ) ) <EOL> @ classmethod <EOL> def validate ( cls , value ) : <EOL> ST_CoordinateUnqualified . validate ( value ) <EOL> class ST_CoordinateUnqualified ( XsdLong ) : <EOL> @ classmethod <EOL> def validate ( cls , value ) : <EOL> cls . validate_int_in_range ( value , - <NUM_LIT> , <NUM_LIT> ) <EOL> class ST_DecimalNumber ( XsdInt ) : <EOL> pass <EOL> class ST_DrawingElementId ( XsdUnsignedInt ) : <EOL> pass <EOL> class ST_HexColor ( BaseStringType ) : <EOL> @ classmethod <EOL> def convert_from_xml ( cls , str_value ) : <EOL> if str_value == '<STR_LIT>' : <EOL> return ST_HexColorAuto . AUTO <EOL> return RGBColor . from_string ( str_value ) <EOL> @ classmethod <EOL> def convert_to_xml ( cls , value ) : <EOL> """<STR_LIT>""" <EOL> return '<STR_LIT>' % value <EOL> @ classmethod <EOL> def validate ( cls , value ) : <EOL> if not isinstance ( value , RGBColor ) : <EOL> raise ValueError ( <EOL> "<STR_LIT>" <EOL> % ( type ( value ) , value ) <EOL> ) <EOL> class ST_HexColorAuto ( XsdStringEnumeration ) : <EOL> """<STR_LIT>""" <EOL> AUTO = '<STR_LIT>' <EOL> _members = ( AUTO , ) <EOL> class ST_HpsMeasure ( XsdUnsignedLong ) : <EOL> """<STR_LIT>""" <EOL> @ classmethod <EOL> def convert_from_xml ( cls , str_value ) : <EOL> if '<STR_LIT:m>' in str_value or '<STR_LIT:n>' in str_value or '<STR_LIT:p>' in str_value : <EOL> return ST_UniversalMeasure . convert_from_xml ( str_value ) <EOL> return Pt ( int ( str_value ) / <NUM_LIT> ) <EOL> @ classmethod <EOL> def convert_to_xml ( cls , value ) : <EOL> emu = Emu ( value ) <EOL> half_points = int ( emu . pt * <NUM_LIT:2> ) <EOL> return str ( half_points ) <EOL> class ST_Merge ( XsdStringEnumeration ) : <EOL> """<STR_LIT>""" <EOL> CONTINUE = '<STR_LIT>' <EOL> RESTART = '<STR_LIT>' <EOL> _members = ( CONTINUE , RESTART ) <EOL> class ST_OnOff ( XsdBoolean ) : <EOL> @ classmethod <EOL> def convert_from_xml ( cls , str_value ) : <EOL> if str_value not in ( '<STR_LIT:1>' , '<STR_LIT:0>' , '<STR_LIT:true>' , '<STR_LIT:false>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> raise InvalidXmlError ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % str_value <EOL> ) <EOL> return str_value in ( '<STR_LIT:1>' , '<STR_LIT:true>' , '<STR_LIT>' ) <EOL> class ST_PositiveCoordinate ( XsdLong ) : <EOL> @ classmethod <EOL> def convert_from_xml ( cls , str_value ) : <EOL> return Emu ( int ( str_value ) ) <EOL> @ classmethod <EOL> def validate ( cls , value ) : <EOL> cls . validate_int_in_range ( value , <NUM_LIT:0> , <NUM_LIT> ) <EOL> class ST_RelationshipId ( XsdString ) : <EOL> pass <EOL> class ST_SignedTwipsMeasure ( XsdInt ) : <EOL> @ classmethod <EOL> def convert_from_xml ( cls , str_value ) : <EOL> if '<STR_LIT:i>' in str_value or '<STR_LIT:m>' in str_value or '<STR_LIT:p>' in str_value : <EOL> return ST_UniversalMeasure . convert_from_xml ( str_value ) <EOL> return Twips ( int ( str_value ) ) <EOL> @ classmethod <EOL> def convert_to_xml ( cls , value ) : <EOL> emu = Emu ( value ) <EOL> twips = emu . twips <EOL> return str ( twips ) <EOL> class ST_String ( XsdString ) : <EOL> pass <EOL> class ST_TblLayoutType ( XsdString ) : <EOL> @ classmethod <EOL> def validate ( cls , value ) : <EOL> cls . validate_string ( value ) <EOL> valid_values = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if value not in valid_values : <EOL> raise ValueError ( <EOL> "<STR_LIT>" % ( valid_values , value ) <EOL> ) <EOL> class ST_TblWidth ( XsdString ) : <EOL> @ classmethod <EOL> def validate ( cls , value ) : <EOL> cls . validate_string ( value ) <EOL> valid_values = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> if value not in valid_values : <EOL> raise ValueError ( <EOL> "<STR_LIT>" % ( valid_values , value ) <EOL> ) <EOL> class ST_TwipsMeasure ( XsdUnsignedLong ) : <EOL> @ classmethod <EOL> def convert_from_xml ( cls , str_value ) : <EOL> if '<STR_LIT:i>' in str_value or '<STR_LIT:m>' in str_value or '<STR_LIT:p>' in str_value : <EOL> return ST_UniversalMeasure . convert_from_xml ( str_value ) <EOL> return Twips ( int ( str_value ) ) <EOL> @ classmethod <EOL> def convert_to_xml ( cls , value ) : <EOL> emu = Emu ( value ) <EOL> twips = emu . twips <EOL> return str ( twips ) <EOL> class ST_UniversalMeasure ( BaseSimpleType ) : <EOL> @ classmethod <EOL> def convert_from_xml ( cls , str_value ) : <EOL> float_part , units_part = str_value [ : - <NUM_LIT:2> ] , str_value [ - <NUM_LIT:2> : ] <EOL> quantity = float ( float_part ) <EOL> multiplier = { <EOL> '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> <EOL> } [ units_part ] <EOL> emu_value = Emu ( int ( round ( quantity * multiplier ) ) ) <EOL> return emu_value <EOL> class ST_VerticalAlignRun ( XsdStringEnumeration ) : <EOL> """<STR_LIT>""" <EOL> BASELINE = '<STR_LIT>' <EOL> SUPERSCRIPT = '<STR_LIT>' <EOL> SUBSCRIPT = '<STR_LIT>' <EOL> _members = ( BASELINE , SUPERSCRIPT , SUBSCRIPT ) </s>
