<s> '''<STR_LIT>''' <EOL> from attributes import CoreAttrib , ConditionalAttrib , StyleAttrib , GraphicalEventsAttrib , PaintAttrib , OpacityAttrib , GraphicsAttrib , CursorAttrib , FilterAttrib , MaskAttrib , ClipAttrib <EOL> class TextContent : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , content ) : <EOL> self . content = content <EOL> def setContent ( self , content ) : <EOL> self . content = content <EOL> def getXML ( self ) : <EOL> return self . content <EOL> class BaseElement : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , elementName ) : <EOL> """<STR_LIT>""" <EOL> self . _elementName = elementName <EOL> self . _attributes = { } <EOL> self . _textContent = "<STR_LIT>" <EOL> self . _subElements = [ ] <EOL> def appendTextContent ( self , text ) : <EOL> self . addElement ( TextContent ( text ) ) <EOL> def addElement ( self , element ) : <EOL> self . _subElements . append ( element ) <EOL> def getElementAt ( self , pos ) : <EOL> return self . _subElements [ pos ] <EOL> def insertElementAt ( self , element , pos ) : <EOL> return self . _subElements . insert ( pos , element ) <EOL> def getXML ( self ) : <EOL> """<STR_LIT>""" <EOL> xml = '<STR_LIT:<>' + self . _elementName + '<STR_LIT:U+0020>' <EOL> for key , value in self . _attributes . items ( ) : <EOL> if value != None : <EOL> xml += key + '<STR_LIT>' + self . quote_attrib ( str ( value ) ) + '<STR_LIT>' <EOL> if len ( self . _subElements ) == <NUM_LIT:0> : <EOL> xml += '<STR_LIT>' <EOL> else : <EOL> xml += '<STR_LIT>' <EOL> for subelement in self . _subElements : <EOL> xml += str ( subelement . getXML ( ) ) <EOL> xml += '<STR_LIT>' + self . _elementName + '<STR_LIT>' <EOL> return xml <EOL> def setAttribute ( self , attribute_name , attribute_value ) : <EOL> self . _attributes [ attribute_name ] = attribute_value <EOL> def getAttribute ( self , attribute_name ) : <EOL> return self . _attributes . get ( attribute_name ) <EOL> def setKWARGS ( self , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> for key in kwargs . keys ( ) : <EOL> f = getattr ( self , '<STR_LIT>' + key ) <EOL> f ( kwargs [ key ] ) <EOL> def wrap_xml ( self , xml , encoding = '<STR_LIT>' , standalone = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> header = '''<STR_LIT>''' % ( encoding , standalone ) <EOL> return header + xml <EOL> def save ( self , filename , encoding = '<STR_LIT>' , standalone = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> f = open ( filename , '<STR_LIT:w>' ) <EOL> f . write ( self . wrap_xml ( self . getXML ( ) , encoding , standalone ) ) <EOL> f . close ( ) <EOL> def quote_attrib ( self , inStr ) : <EOL> """<STR_LIT>""" <EOL> s1 = ( isinstance ( inStr , basestring ) and inStr or <EOL> '<STR_LIT:%s>' % inStr ) <EOL> s1 = s1 . replace ( '<STR_LIT:&>' , '<STR_LIT>' ) <EOL> s1 = s1 . replace ( '<STR_LIT:<>' , '<STR_LIT>' ) <EOL> s1 = s1 . replace ( '<STR_LIT:>>' , '<STR_LIT>' ) <EOL> if '<STR_LIT:">' in s1 : <EOL> s1 = '<STR_LIT:%s>' % s1 . replace ( '<STR_LIT:">' , "<STR_LIT>" ) <EOL> return s1 <EOL> class PointAttrib : <EOL> """<STR_LIT>""" <EOL> def set_x ( self , x ) : <EOL> self . _attributes [ '<STR_LIT:x>' ] = x <EOL> def get_x ( self ) : <EOL> return self . _attributes . get ( '<STR_LIT:x>' ) <EOL> def set_y ( self , y ) : <EOL> self . _attributes [ '<STR_LIT:y>' ] = y <EOL> def get_y ( self ) : <EOL> return self . _attributes . get ( '<STR_LIT:y>' ) <EOL> class DeltaPointAttrib : <EOL> """<STR_LIT>""" <EOL> def set_dx ( self , dx ) : <EOL> self . _attributes [ '<STR_LIT>' ] = dx <EOL> def get_dx ( self ) : <EOL> return self . _attributes . get ( '<STR_LIT>' ) <EOL> def set_dy ( self , dy ) : <EOL> self . _attributes [ '<STR_LIT>' ] = dy <EOL> def get_dy ( self ) : <EOL> return self . _attributes . get ( '<STR_LIT>' ) <EOL> class PointToAttrib : <EOL> """<STR_LIT>""" <EOL> def set_x2 ( self , x2 ) : <EOL> self . _attributes [ '<STR_LIT>' ] = x2 <EOL> def get_x2 ( self ) : <EOL> return self . _attributes . get ( '<STR_LIT>' ) <EOL> def set_y2 ( self , y2 ) : <EOL> self . _attributes [ '<STR_LIT>' ] = y2 <EOL> def get_y2 ( self ) : <EOL> return self . _attributes . get ( '<STR_LIT>' ) <EOL> class DimensionAttrib : <EOL> """<STR_LIT>""" <EOL> def set_height ( self , height ) : <EOL> self . _attributes [ '<STR_LIT>' ] = height <EOL> def get_height ( self ) : <EOL> return self . _attributes . get ( '<STR_LIT>' ) <EOL> def set_width ( self , width ) : <EOL> self . _attributes [ '<STR_LIT:width>' ] = width <EOL> def get_width ( self ) : <EOL> return self . _attributes . get ( '<STR_LIT:width>' ) <EOL> class RotateAttrib : <EOL> """<STR_LIT>""" <EOL> def set_rotate ( self , rotate ) : <EOL> self . _attributes [ '<STR_LIT>' ] = rotate <EOL> def get_rotate ( self ) : <EOL> return self . _attributes . get ( '<STR_LIT>' ) <EOL> class BaseShape ( BaseElement , CoreAttrib , ConditionalAttrib , StyleAttrib , GraphicalEventsAttrib , PaintAttrib , OpacityAttrib , GraphicsAttrib , CursorAttrib , FilterAttrib , MaskAttrib , ClipAttrib ) : <EOL> """<STR_LIT>""" <EOL> def set_transform ( self , transform ) : <EOL> self . _attributes [ '<STR_LIT>' ] = transform <EOL> def get_transform ( self ) : <EOL> return self . _attributes . get ( '<STR_LIT>' ) </s>
