<s> """<STR_LIT>""" <EOL> import types <EOL> import urlparse <EOL> from xml . sax import saxutils <EOL> from google . appengine . datastore import datastore_pb <EOL> from google . appengine . api import datastore <EOL> from google . appengine . api import datastore_errors <EOL> from google . appengine . api import datastore_types <EOL> class GdKind ( datastore . Entity ) : <EOL> """<STR_LIT>""" <EOL> HEADER = u"""<STR_LIT>""" <EOL> FOOTER = u"""<STR_LIT>""" <EOL> _kind_properties = set ( ) <EOL> _contact_properties = set ( ) <EOL> def __init__ ( self , kind , title , kind_properties , contact_properties = [ ] ) : <EOL> """<STR_LIT>""" <EOL> datastore . Entity . __init__ ( self , kind ) <EOL> if not isinstance ( title , types . StringTypes ) : <EOL> raise datastore_errors . BadValueError ( <EOL> '<STR_LIT>' % <EOL> ( title , datastore_types . typename ( title ) ) ) <EOL> self [ '<STR_LIT:title>' ] = title <EOL> self [ '<STR_LIT:content>' ] = '<STR_LIT>' <EOL> self . _contact_properties = set ( contact_properties ) <EOL> assert not self . _contact_properties . intersection ( self . keys ( ) ) <EOL> self . _kind_properties = set ( kind_properties ) - self . _contact_properties <EOL> self . _kind_properties . add ( '<STR_LIT:title>' ) <EOL> self . _kind_properties . add ( '<STR_LIT:content>' ) <EOL> def _KindPropertiesToXml ( self ) : <EOL> """<STR_LIT>""" <EOL> properties = self . _kind_properties . intersection ( set ( self . keys ( ) ) ) <EOL> xml = u'<STR_LIT>' <EOL> for prop in sorted ( properties ) : <EOL> prop_xml = saxutils . quoteattr ( prop ) [ <NUM_LIT:1> : - <NUM_LIT:1> ] <EOL> value = self [ prop ] <EOL> has_toxml = ( hasattr ( value , '<STR_LIT>' ) or <EOL> isinstance ( value , list ) and hasattr ( value [ <NUM_LIT:0> ] , '<STR_LIT>' ) ) <EOL> for val in self . _XmlEscapeValues ( prop ) : <EOL> if has_toxml : <EOL> xml += '<STR_LIT>' % val <EOL> else : <EOL> xml += '<STR_LIT>' % ( prop_xml , val , prop_xml ) <EOL> return xml <EOL> def _ContactPropertiesToXml ( self ) : <EOL> """<STR_LIT>""" <EOL> properties = self . _contact_properties . intersection ( set ( self . keys ( ) ) ) <EOL> xml = u'<STR_LIT>' <EOL> for prop in sorted ( properties ) : <EOL> values = self [ prop ] <EOL> if not isinstance ( values , list ) : <EOL> values = [ values ] <EOL> for value in values : <EOL> assert isinstance ( value , datastore_types . Key ) <EOL> xml += """<STR_LIT>""" % ( self . kind ( ) . lower ( ) , prop , value . ToTagUri ( ) ) <EOL> return xml <EOL> def _LeftoverPropertiesToXml ( self ) : <EOL> """<STR_LIT>""" <EOL> leftovers = set ( self . keys ( ) ) <EOL> leftovers -= self . _kind_properties <EOL> leftovers -= self . _contact_properties <EOL> if leftovers : <EOL> return u'<STR_LIT>' + '<STR_LIT>' . join ( self . _PropertiesToXml ( leftovers ) ) <EOL> else : <EOL> return u'<STR_LIT>' <EOL> def ToXml ( self ) : <EOL> """<STR_LIT>""" <EOL> xml = GdKind . HEADER % self . kind ( ) . lower ( ) <EOL> xml += self . _KindPropertiesToXml ( ) <EOL> xml += self . _ContactPropertiesToXml ( ) <EOL> xml += self . _LeftoverPropertiesToXml ( ) <EOL> xml += GdKind . FOOTER <EOL> return xml <EOL> class Message ( GdKind ) : <EOL> """<STR_LIT>""" <EOL> KIND_PROPERTIES = [ '<STR_LIT:title>' , '<STR_LIT:content>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> CONTACT_PROPERTIES = [ '<STR_LIT>' , '<STR_LIT:to>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> def __init__ ( self , title , kind = '<STR_LIT>' ) : <EOL> GdKind . __init__ ( self , kind , title , Message . KIND_PROPERTIES , <EOL> Message . CONTACT_PROPERTIES ) <EOL> class Event ( GdKind ) : <EOL> """<STR_LIT>""" <EOL> KIND_PROPERTIES = [ '<STR_LIT:title>' , '<STR_LIT:content>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> CONTACT_PROPERTIES = [ '<STR_LIT>' ] <EOL> class Status : <EOL> CONFIRMED = '<STR_LIT>' <EOL> TENTATIVE = '<STR_LIT>' <EOL> CANCELED = '<STR_LIT>' <EOL> def __init__ ( self , title , kind = '<STR_LIT>' ) : <EOL> GdKind . __init__ ( self , kind , title , Event . KIND_PROPERTIES , <EOL> Event . CONTACT_PROPERTIES ) <EOL> def ToXml ( self ) : <EOL> """<STR_LIT>""" <EOL> xml = GdKind . HEADER % self . kind ( ) . lower ( ) <EOL> self . _kind_properties = set ( Contact . KIND_PROPERTIES ) <EOL> xml += self . _KindPropertiesToXml ( ) <EOL> if '<STR_LIT>' in self : <EOL> xml += """<STR_LIT>""" % self [ '<STR_LIT>' ] <EOL> if '<STR_LIT>' in self : <EOL> xml += """<STR_LIT>""" % ( <EOL> self [ '<STR_LIT>' ] ) <EOL> if '<STR_LIT>' in self : <EOL> lines = [ '<STR_LIT>' % val <EOL> for val in self . _XmlEscapeValues ( '<STR_LIT>' ) ] <EOL> xml += '<STR_LIT>' + '<STR_LIT>' . join ( lines ) <EOL> iso_format = '<STR_LIT>' <EOL> xml += '<STR_LIT>' <EOL> for key in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> if key in self : <EOL> xml += '<STR_LIT>' % ( key , self [ key ] . isoformat ( ) ) <EOL> xml += '<STR_LIT>' <EOL> self . _kind_properties . update ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ] ) <EOL> xml += self . _ContactPropertiesToXml ( ) <EOL> xml += self . _LeftoverPropertiesToXml ( ) <EOL> xml += GdKind . FOOTER <EOL> return xml <EOL> class Contact ( GdKind ) : <EOL> """<STR_LIT>""" <EOL> CONTACT_SECTION_HEADER = """<STR_LIT>""" <EOL> CONTACT_SECTION_FOOTER = """<STR_LIT>""" <EOL> KIND_PROPERTIES = [ '<STR_LIT:title>' , '<STR_LIT:content>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> CONTACT_SECTION_PROPERTIES = [ '<STR_LIT:email>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ] <EOL> def __init__ ( self , title , kind = '<STR_LIT>' ) : <EOL> GdKind . __init__ ( self , kind , title , Contact . KIND_PROPERTIES ) <EOL> def ToXml ( self ) : <EOL> """<STR_LIT>""" <EOL> xml = GdKind . HEADER % self . kind ( ) . lower ( ) <EOL> self . _kind_properties = set ( Contact . KIND_PROPERTIES ) <EOL> xml += self . _KindPropertiesToXml ( ) <EOL> xml += Contact . CONTACT_SECTION_HEADER <EOL> self . _kind_properties = set ( Contact . CONTACT_SECTION_PROPERTIES ) <EOL> xml += self . _KindPropertiesToXml ( ) <EOL> xml += Contact . CONTACT_SECTION_FOOTER <EOL> self . _kind_properties . update ( Contact . KIND_PROPERTIES ) <EOL> xml += self . _LeftoverPropertiesToXml ( ) <EOL> xml += GdKind . FOOTER <EOL> return xml </s>
