<s> """<STR_LIT>""" <EOL> __author__ = '<STR_LIT>' <EOL> import os <EOL> import atom <EOL> try : <EOL> from xml . etree import cElementTree as ElementTree <EOL> except ImportError : <EOL> try : <EOL> import cElementTree as ElementTree <EOL> except ImportError : <EOL> try : <EOL> from xml . etree import ElementTree <EOL> except ImportError : <EOL> from elementtree import ElementTree <EOL> GDATA_NAMESPACE = '<STR_LIT>' <EOL> GDATA_TEMPLATE = '<STR_LIT>' <EOL> OPENSEARCH_NAMESPACE = '<STR_LIT>' <EOL> OPENSEARCH_TEMPLATE = '<STR_LIT>' <EOL> BATCH_NAMESPACE = '<STR_LIT>' <EOL> GACL_NAMESPACE = '<STR_LIT>' <EOL> GACL_TEMPLATE = '<STR_LIT>' <EOL> BATCH_INSERT = '<STR_LIT>' <EOL> BATCH_UPDATE = '<STR_LIT>' <EOL> BATCH_DELETE = '<STR_LIT>' <EOL> BATCH_QUERY = '<STR_LIT>' <EOL> class Error ( Exception ) : <EOL> pass <EOL> class MissingRequiredParameters ( Error ) : <EOL> pass <EOL> class MediaSource ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , file_handle = None , content_type = None , content_length = None , <EOL> file_path = None , file_name = None ) : <EOL> """<STR_LIT>""" <EOL> self . file_handle = file_handle <EOL> self . content_type = content_type <EOL> self . content_length = content_length <EOL> self . file_name = file_name <EOL> if ( file_handle is None and content_type is not None and <EOL> file_path is not None ) : <EOL> self . setFile ( file_path , content_type ) <EOL> def setFile ( self , file_name , content_type ) : <EOL> """<STR_LIT>""" <EOL> self . file_handle = open ( file_name , '<STR_LIT:rb>' ) <EOL> self . content_type = content_type <EOL> self . content_length = os . path . getsize ( file_name ) <EOL> self . file_name = os . path . basename ( file_name ) <EOL> class LinkFinder ( atom . LinkFinder ) : <EOL> """<STR_LIT>""" <EOL> def GetSelfLink ( self ) : <EOL> """<STR_LIT>""" <EOL> for a_link in self . link : <EOL> if a_link . rel == '<STR_LIT>' : <EOL> return a_link <EOL> return None <EOL> def GetEditLink ( self ) : <EOL> for a_link in self . link : <EOL> if a_link . rel == '<STR_LIT>' : <EOL> return a_link <EOL> return None <EOL> def GetEditMediaLink ( self ) : <EOL> """<STR_LIT>""" <EOL> for a_link in self . link : <EOL> if a_link . rel == '<STR_LIT>' : <EOL> return a_link <EOL> if a_link . rel == '<STR_LIT>' : <EOL> return a_link <EOL> return None <EOL> def GetHtmlLink ( self ) : <EOL> """<STR_LIT>""" <EOL> for a_link in self . link : <EOL> if a_link . rel == '<STR_LIT>' and a_link . type == '<STR_LIT>' : <EOL> return a_link <EOL> return None <EOL> def GetPostLink ( self ) : <EOL> """<STR_LIT>""" <EOL> for a_link in self . link : <EOL> if a_link . rel == '<STR_LIT>' : <EOL> return a_link <EOL> return None <EOL> def GetAclLink ( self ) : <EOL> for a_link in self . link : <EOL> if a_link . rel == '<STR_LIT>' : <EOL> return a_link <EOL> return None <EOL> def GetFeedLink ( self ) : <EOL> for a_link in self . link : <EOL> if a_link . rel == '<STR_LIT>' : <EOL> return a_link <EOL> return None <EOL> def GetNextLink ( self ) : <EOL> for a_link in self . link : <EOL> if a_link . rel == '<STR_LIT>' : <EOL> return a_link <EOL> return None <EOL> def GetPrevLink ( self ) : <EOL> for a_link in self . link : <EOL> if a_link . rel == '<STR_LIT>' : <EOL> return a_link <EOL> return None <EOL> class TotalResults ( atom . AtomBase ) : <EOL> """<STR_LIT>""" <EOL> _tag = '<STR_LIT>' <EOL> _namespace = OPENSEARCH_NAMESPACE <EOL> _children = atom . AtomBase . _children . copy ( ) <EOL> _attributes = atom . AtomBase . _attributes . copy ( ) <EOL> def __init__ ( self , extension_elements = None , <EOL> extension_attributes = None , text = None ) : <EOL> self . text = text <EOL> self . extension_elements = extension_elements or [ ] <EOL> self . extension_attributes = extension_attributes or { } <EOL> def TotalResultsFromString ( xml_string ) : <EOL> return atom . CreateClassFromXMLString ( TotalResults , xml_string ) <EOL> class StartIndex ( atom . AtomBase ) : <EOL> """<STR_LIT>""" <EOL> _tag = '<STR_LIT>' <EOL> _namespace = OPENSEARCH_NAMESPACE <EOL> _children = atom . AtomBase . _children . copy ( ) <EOL> _attributes = atom . AtomBase . _attributes . copy ( ) <EOL> def __init__ ( self , extension_elements = None , <EOL> extension_attributes = None , text = None ) : <EOL> self . text = text <EOL> self . extension_elements = extension_elements or [ ] <EOL> self . extension_attributes = extension_attributes or { } <EOL> def StartIndexFromString ( xml_string ) : <EOL> return atom . CreateClassFromXMLString ( StartIndex , xml_string ) <EOL> class ItemsPerPage ( atom . AtomBase ) : <EOL> """<STR_LIT>""" <EOL> _tag = '<STR_LIT>' <EOL> _namespace = OPENSEARCH_NAMESPACE <EOL> _children = atom . AtomBase . _children . copy ( ) <EOL> _attributes = atom . AtomBase . _attributes . copy ( ) <EOL> def __init__ ( self , extension_elements = None , <EOL> extension_attributes = None , text = None ) : <EOL> self . text = text <EOL> self . extension_elements = extension_elements or [ ] <EOL> self . extension_attributes = extension_attributes or { } <EOL> def ItemsPerPageFromString ( xml_string ) : <EOL> return atom . CreateClassFromXMLString ( ItemsPerPage , xml_string ) <EOL> class ExtendedProperty ( atom . AtomBase ) : <EOL> """<STR_LIT>""" <EOL> _tag = '<STR_LIT>' <EOL> _namespace = GDATA_NAMESPACE <EOL> _children = atom . AtomBase . _children . copy ( ) <EOL> _attributes = atom . AtomBase . _attributes . copy ( ) <EOL> _attributes [ '<STR_LIT:name>' ] = '<STR_LIT:name>' <EOL> _attributes [ '<STR_LIT:value>' ] = '<STR_LIT:value>' <EOL> def __init__ ( self , name = None , value = None , extension_elements = None , <EOL> extension_attributes = None , text = None ) : <EOL> self . name = name <EOL> self . value = value <EOL> self . text = text <EOL> self . extension_elements = extension_elements or [ ] <EOL> self . extension_attributes = extension_attributes or { } <EOL> def GetXmlBlobExtensionElement ( self ) : <EOL> """<STR_LIT>""" <EOL> if len ( self . extension_elements ) < <NUM_LIT:1> : <EOL> return None <EOL> else : <EOL> return self . extension_elements [ <NUM_LIT:0> ] <EOL> def GetXmlBlobString ( self ) : <EOL> """<STR_LIT>""" <EOL> blob = self . GetXmlBlobExtensionElement ( ) <EOL> if blob : <EOL> return blob . ToString ( ) <EOL> return None <EOL> def SetXmlBlob ( self , blob ) : <EOL> """<STR_LIT>""" <EOL> self . extension_elements = [ ] <EOL> if isinstance ( blob , atom . ExtensionElement ) : <EOL> self . extension_elements . append ( blob ) <EOL> elif ElementTree . iselement ( blob ) : <EOL> self . extension_elements . append ( atom . _ExtensionElementFromElementTree ( <EOL> blob ) ) <EOL> else : <EOL> self . extension_elements . append ( atom . ExtensionElementFromString ( blob ) ) <EOL> def ExtendedPropertyFromString ( xml_string ) : <EOL> return atom . CreateClassFromXMLString ( ExtendedProperty , xml_string ) <EOL> class GDataEntry ( atom . Entry , LinkFinder ) : <EOL> """<STR_LIT>""" <EOL> _tag = atom . Entry . _tag <EOL> _namespace = atom . Entry . _namespace <EOL> _children = atom . Entry . _children . copy ( ) <EOL> _attributes = atom . Entry . _attributes . copy ( ) <EOL> def __GetId ( self ) : <EOL> return self . __id <EOL> def __SetId ( self , id ) : <EOL> self . __id = id <EOL> if id is not None and id . text is not None : <EOL> self . __id . text = id . text . strip ( ) <EOL> id = property ( __GetId , __SetId ) <EOL> def IsMedia ( self ) : <EOL> """<STR_LIT>""" <EOL> if ( self . GetEditMediaLink ( ) ) : <EOL> return True <EOL> else : <EOL> return False <EOL> def GetMediaURL ( self ) : <EOL> """<STR_LIT>""" <EOL> if not self . IsMedia ( ) : <EOL> return None <EOL> else : <EOL> return self . content . src <EOL> def GDataEntryFromString ( xml_string ) : <EOL> """<STR_LIT>""" <EOL> return atom . CreateClassFromXMLString ( GDataEntry , xml_string ) <EOL> class GDataFeed ( atom . Feed , LinkFinder ) : <EOL> """<STR_LIT>""" <EOL> _tag = '<STR_LIT>' <EOL> _namespace = atom . ATOM_NAMESPACE <EOL> _children = atom . Feed . _children . copy ( ) <EOL> _attributes = atom . Feed . _attributes . copy ( ) <EOL> _children [ '<STR_LIT>' % OPENSEARCH_NAMESPACE ] = ( '<STR_LIT>' , <EOL> TotalResults ) <EOL> _children [ '<STR_LIT>' % OPENSEARCH_NAMESPACE ] = ( '<STR_LIT>' , <EOL> StartIndex ) <EOL> _children [ '<STR_LIT>' % OPENSEARCH_NAMESPACE ] = ( '<STR_LIT>' , <EOL> ItemsPerPage ) <EOL> _children [ '<STR_LIT>' % atom . ATOM_NAMESPACE ] = ( '<STR_LIT>' , [ GDataEntry ] ) <EOL> def __GetId ( self ) : <EOL> return self . __id <EOL> def __SetId ( self , id ) : <EOL> self . __id = id <EOL> if id is not None and id . text is not None : <EOL> self . __id . text = id . text . strip ( ) <EOL> id = property ( __GetId , __SetId ) <EOL> def __GetGenerator ( self ) : <EOL> return self . __generator <EOL> def __SetGenerator ( self , generator ) : <EOL> self . __generator = generator <EOL> if generator is not None : <EOL> self . __generator . text = generator . text . strip ( ) <EOL> generator = property ( __GetGenerator , __SetGenerator ) <EOL> def __init__ ( self , author = None , category = None , contributor = None , <EOL> generator = None , icon = None , atom_id = None , link = None , logo = None , <EOL> rights = None , subtitle = None , title = None , updated = None , entry = None , <EOL> total_results = None , start_index = None , items_per_page = None , <EOL> extension_elements = None , extension_attributes = None , text = None ) : <EOL> """<STR_LIT>""" <EOL> self . author = author or [ ] <EOL> self . category = category or [ ] <EOL> self . contributor = contributor or [ ] <EOL> self . generator = generator <EOL> self . icon = icon <EOL> self . id = atom_id <EOL> self . link = link or [ ] <EOL> self . logo = logo <EOL> self . rights = rights <EOL> self . subtitle = subtitle <EOL> self . title = title <EOL> self . updated = updated <EOL> self . entry = entry or [ ] <EOL> self . total_results = total_results <EOL> self . start_index = start_index <EOL> self . items_per_page = items_per_page <EOL> self . text = text <EOL> self . extension_elements = extension_elements or [ ] <EOL> self . extension_attributes = extension_attributes or { } <EOL> def GDataFeedFromString ( xml_string ) : <EOL> return atom . CreateClassFromXMLString ( GDataFeed , xml_string ) <EOL> class BatchId ( atom . AtomBase ) : <EOL> _tag = '<STR_LIT:id>' <EOL> _namespace = BATCH_NAMESPACE <EOL> _children = atom . AtomBase . _children . copy ( ) <EOL> _attributes = atom . AtomBase . _attributes . copy ( ) <EOL> def BatchIdFromString ( xml_string ) : <EOL> return atom . CreateClassFromXMLString ( BatchId , xml_string ) <EOL> class BatchOperation ( atom . AtomBase ) : <EOL> _tag = '<STR_LIT>' <EOL> _namespace = BATCH_NAMESPACE <EOL> _children = atom . AtomBase . _children . copy ( ) <EOL> _attributes = atom . AtomBase . _attributes . copy ( ) <EOL> _attributes [ '<STR_LIT:type>' ] = '<STR_LIT:type>' <EOL> def __init__ ( self , op_type = None , extension_elements = None , <EOL> extension_attributes = None , <EOL> text = None ) : <EOL> self . type = op_type <EOL> atom . AtomBase . __init__ ( self , <EOL> extension_elements = extension_elements , <EOL> extension_attributes = extension_attributes , <EOL> text = text ) <EOL> def BatchOperationFromString ( xml_string ) : <EOL> return atom . CreateClassFromXMLString ( BatchOperation , xml_string ) <EOL> class BatchStatus ( atom . AtomBase ) : <EOL> """<STR_LIT>""" <EOL> _tag = '<STR_LIT:status>' <EOL> _namespace = BATCH_NAMESPACE <EOL> _children = atom . AtomBase . _children . copy ( ) <EOL> _attributes = atom . AtomBase . _attributes . copy ( ) <EOL> _attributes [ '<STR_LIT:code>' ] = '<STR_LIT:code>' <EOL> _attributes [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> _attributes [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> def __init__ ( self , code = None , reason = None , content_type = None , <EOL> extension_elements = None , extension_attributes = None , text = None ) : <EOL> self . code = code <EOL> self . reason = reason <EOL> self . content_type = content_type <EOL> atom . AtomBase . __init__ ( self , extension_elements = extension_elements , <EOL> extension_attributes = extension_attributes , <EOL> text = text ) <EOL> def BatchStatusFromString ( xml_string ) : <EOL> return atom . CreateClassFromXMLString ( BatchStatus , xml_string ) <EOL> class BatchEntry ( GDataEntry ) : <EOL> """<STR_LIT>""" <EOL> _tag = GDataEntry . _tag <EOL> _namespace = GDataEntry . _namespace <EOL> _children = GDataEntry . _children . copy ( ) <EOL> _children [ '<STR_LIT>' % BATCH_NAMESPACE ] = ( '<STR_LIT>' , BatchOperation ) <EOL> _children [ '<STR_LIT>' % BATCH_NAMESPACE ] = ( '<STR_LIT>' , BatchId ) <EOL> _children [ '<STR_LIT>' % BATCH_NAMESPACE ] = ( '<STR_LIT>' , BatchStatus ) <EOL> _attributes = GDataEntry . _attributes . copy ( ) <EOL> def __init__ ( self , author = None , category = None , content = None , <EOL> contributor = None , atom_id = None , link = None , published = None , rights = None , <EOL> source = None , summary = None , control = None , title = None , updated = None , <EOL> batch_operation = None , batch_id = None , batch_status = None , <EOL> extension_elements = None , extension_attributes = None , text = None ) : <EOL> self . batch_operation = batch_operation <EOL> self . batch_id = batch_id <EOL> self . batch_status = batch_status <EOL> GDataEntry . __init__ ( self , author = author , category = category , <EOL> content = content , contributor = contributor , atom_id = atom_id , link = link , <EOL> published = published , rights = rights , source = source , summary = summary , <EOL> control = control , title = title , updated = updated , <EOL> extension_elements = extension_elements , <EOL> extension_attributes = extension_attributes , text = text ) <EOL> def BatchEntryFromString ( xml_string ) : <EOL> return atom . CreateClassFromXMLString ( BatchEntry , xml_string ) <EOL> class BatchInterrupted ( atom . AtomBase ) : <EOL> """<STR_LIT>""" <EOL> _tag = '<STR_LIT>' <EOL> _namespace = BATCH_NAMESPACE <EOL> _children = atom . AtomBase . _children . copy ( ) <EOL> _attributes = atom . AtomBase . _attributes . copy ( ) <EOL> _attributes [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> _attributes [ '<STR_LIT:success>' ] = '<STR_LIT:success>' <EOL> _attributes [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> _attributes [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> def __init__ ( self , reason = None , success = None , failures = None , parsed = None , <EOL> extension_elements = None , extension_attributes = None , text = None ) : <EOL> self . reason = reason <EOL> self . success = success <EOL> self . failures = failures <EOL> self . parsed = parsed <EOL> atom . AtomBase . __init__ ( self , extension_elements = extension_elements , <EOL> extension_attributes = extension_attributes , <EOL> text = text ) <EOL> def BatchInterruptedFromString ( xml_string ) : <EOL> return atom . CreateClassFromXMLString ( BatchInterrupted , xml_string ) <EOL> class BatchFeed ( GDataFeed ) : <EOL> """<STR_LIT>""" <EOL> _tag = GDataFeed . _tag <EOL> _namespace = GDataFeed . _namespace <EOL> _children = GDataFeed . _children . copy ( ) <EOL> _attributes = GDataFeed . _attributes . copy ( ) <EOL> _children [ '<STR_LIT>' % atom . ATOM_NAMESPACE ] = ( '<STR_LIT>' , [ BatchEntry ] ) <EOL> _children [ '<STR_LIT>' % BATCH_NAMESPACE ] = ( '<STR_LIT>' , BatchInterrupted ) <EOL> def __init__ ( self , author = None , category = None , contributor = None , <EOL> generator = None , icon = None , atom_id = None , link = None , logo = None , <EOL> rights = None , subtitle = None , title = None , updated = None , entry = None , <EOL> total_results = None , start_index = None , items_per_page = None , <EOL> interrupted = None , <EOL> extension_elements = None , extension_attributes = None , text = None ) : <EOL> self . interrupted = interrupted <EOL> GDataFeed . __init__ ( self , author = author , category = category , <EOL> contributor = contributor , generator = generator , <EOL> icon = icon , atom_id = atom_id , link = link , <EOL> logo = logo , rights = rights , subtitle = subtitle , <EOL> title = title , updated = updated , entry = entry , <EOL> total_results = total_results , start_index = start_index , <EOL> items_per_page = items_per_page , <EOL> extension_elements = extension_elements , <EOL> extension_attributes = extension_attributes , <EOL> text = text ) <EOL> def AddBatchEntry ( self , entry = None , id_url_string = None , <EOL> batch_id_string = None , operation_string = None ) : <EOL> """<STR_LIT>""" <EOL> if entry is None and id_url_string is None : <EOL> raise MissingRequiredParameters ( '<STR_LIT>' ) <EOL> if entry is None and id_url_string is not None : <EOL> entry = BatchEntry ( atom_id = atom . Id ( text = id_url_string ) ) <EOL> if batch_id_string is not None : <EOL> entry . batch_id = BatchId ( text = batch_id_string ) <EOL> elif entry . batch_id is None or entry . batch_id . text is None : <EOL> entry . batch_id = BatchId ( text = str ( len ( self . entry ) ) ) <EOL> if operation_string is not None : <EOL> entry . batch_operation = BatchOperation ( op_type = operation_string ) <EOL> self . entry . append ( entry ) <EOL> return entry <EOL> def AddInsert ( self , entry , batch_id_string = None ) : <EOL> """<STR_LIT>""" <EOL> entry = self . AddBatchEntry ( entry = entry , batch_id_string = batch_id_string , <EOL> operation_string = BATCH_INSERT ) <EOL> def AddUpdate ( self , entry , batch_id_string = None ) : <EOL> """<STR_LIT>""" <EOL> entry = self . AddBatchEntry ( entry = entry , batch_id_string = batch_id_string , <EOL> operation_string = BATCH_UPDATE ) <EOL> def AddDelete ( self , url_string = None , entry = None , batch_id_string = None ) : <EOL> """<STR_LIT>""" <EOL> entry = self . AddBatchEntry ( entry = entry , id_url_string = url_string , <EOL> batch_id_string = batch_id_string , <EOL> operation_string = BATCH_DELETE ) <EOL> def AddQuery ( self , url_string = None , entry = None , batch_id_string = None ) : <EOL> """<STR_LIT>""" <EOL> entry = self . AddBatchEntry ( entry = entry , id_url_string = url_string , <EOL> batch_id_string = batch_id_string , <EOL> operation_string = BATCH_QUERY ) <EOL> def GetBatchLink ( self ) : <EOL> for link in self . link : <EOL> if link . rel == '<STR_LIT>' : <EOL> return link <EOL> return None <EOL> def BatchFeedFromString ( xml_string ) : <EOL> return atom . CreateClassFromXMLString ( BatchFeed , xml_string ) <EOL> class EntryLink ( atom . AtomBase ) : <EOL> """<STR_LIT>""" <EOL> _tag = '<STR_LIT>' <EOL> _namespace = GDATA_NAMESPACE <EOL> _children = atom . AtomBase . _children . copy ( ) <EOL> _attributes = atom . AtomBase . _attributes . copy ( ) <EOL> _children [ '<STR_LIT>' % atom . ATOM_NAMESPACE ] = ( '<STR_LIT>' , GDataEntry ) <EOL> _attributes [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> _attributes [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> _attributes [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> def __init__ ( self , href = None , read_only = None , rel = None , <EOL> entry = None , extension_elements = None , <EOL> extension_attributes = None , text = None ) : <EOL> self . href = href <EOL> self . read_only = read_only <EOL> self . rel = rel <EOL> self . entry = entry <EOL> self . text = text <EOL> self . extension_elements = extension_elements or [ ] <EOL> self . extension_attributes = extension_attributes or { } <EOL> def EntryLinkFromString ( xml_string ) : <EOL> return atom . CreateClassFromXMLString ( EntryLink , xml_string ) <EOL> class FeedLink ( atom . AtomBase ) : <EOL> """<STR_LIT>""" <EOL> _tag = '<STR_LIT>' <EOL> _namespace = GDATA_NAMESPACE <EOL> _children = atom . AtomBase . _children . copy ( ) <EOL> _attributes = atom . AtomBase . _attributes . copy ( ) <EOL> _children [ '<STR_LIT>' % atom . ATOM_NAMESPACE ] = ( '<STR_LIT>' , GDataFeed ) <EOL> _attributes [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> _attributes [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> _attributes [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> _attributes [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> def __init__ ( self , count_hint = None , href = None , read_only = None , rel = None , <EOL> feed = None , extension_elements = None , extension_attributes = None , <EOL> text = None ) : <EOL> self . count_hint = count_hint <EOL> self . href = href <EOL> self . read_only = read_only <EOL> self . rel = rel <EOL> self . feed = feed <EOL> self . text = text <EOL> self . extension_elements = extension_elements or [ ] <EOL> self . extension_attributes = extension_attributes or { } <EOL> def FeedLinkFromString ( xml_string ) : <EOL> return atom . CreateClassFromXMLString ( FeedLink , xml_string ) </s>
