Esempio n. 1
0
def DocumentListFeedFromString(xml_string):
    """Converts an XML string into a DocumentListFeed object.

  Args:
    xml_string: string The XML describing a DocumentList feed.

  Returns:
    A DocumentListFeed object corresponding to the given XML.
  """
    element_tree = ElementTree.fromstring(xml_string)
    return _DocumentListFeedFromElementTree(element_tree)


# Generate function to handle feed parsing using ElementTree.
_DocumentListFeedFromElementTree = atom._AtomInstanceFromElementTree(DocumentListFeed, "feed", atom.ATOM_NAMESPACE)


class DocumentListEntry(gdata.GDataEntry):
    """The Google Documents version of an Atom Entry"""

    pass


def DocumentListEntryFromString(xml_string):
    """Converts an XML string into a DocumentListEntry object.

  Args:
    xml_string: string The XML describing a Document List feed entry.

  Returns:
Esempio n. 2
0
  def _TakeChildFromElementTree(self, child, element_tree):
    if child.tag == '{%s}%s' % (APPS_NAMESPACE, 'login'):
      self.login = _LoginFromElementTree(child)
      element_tree.remove(child)
    elif child.tag == '{%s}%s' % (APPS_NAMESPACE, 'nickname'):
      self.nickname = _NicknameFromElementTree(child)
      element_tree.remove(child)
    else:
      gdata.GDataEntry._TakeChildFromElementTree(self, child, element_tree)

def NicknameEntryFromString(xml_string):
  element_tree = ElementTree.fromstring(xml_string)
  return _NicknameEntryFromElementTree(element_tree)

_NicknameEntryFromElementTree = atom._AtomInstanceFromElementTree(
  NicknameEntry, 'entry', atom.ATOM_NAMESPACE)

class NicknameFeed(gdata.GDataFeed, gdata.LinkFinder):
  """A Google Apps Nickname feed flavor of an Atom Feed"""

  def __init__(self, author=None, category=None, contributor=None,
               generator=None, icon=None, atom_id=None, link=None, logo=None, 
               rights=None, subtitle=None, title=None, updated=None,
               entry=None, total_results=None, start_index=None,
               items_per_page=None, extension_elements=None,
               extension_attributes=None, text=None):
    gdata.GDataFeed.__init__(self, author=author, category=category,
                             contributor=contributor, generator=generator,
                             icon=icon,  atom_id=atom_id, link=link,
                             logo=logo, rights=rights, subtitle=subtitle,
                             title=title, updated=updated, entry=entry,
Esempio n. 3
0
    if child.tag == '{%s}%s' % (atom.ATOM_NAMESPACE, 'entry'):
      self.entry.append(_GBaseSnippetFromElementTree(child))
      element_tree.remove(child)
    else:
      GBaseItemFeed._TakeChildFromElementTree(self, child, element_tree)

  def _TransferFromElementTree(self, element_tree):
    while len(element_tree) > 0:
      self._TakeChildFromElementTree(element_tree[0], element_tree)
    GBaseItemFeed._TransferFromElementTree(self, element_tree)

def GBaseSnippetFeedFromString(xml_string):
  element_tree = ElementTree.fromstring(xml_string)
  return _GBaseSnippetFeedFromElementTree(element_tree)

_GBaseSnippetFeedFromElementTree = atom._AtomInstanceFromElementTree(
    GBaseSnippetFeed, 'feed', atom.ATOM_NAMESPACE)


class GBaseAttributesFeed(gdata.GDataFeed):
  """A feed containing Google Base Attributes
 
  A query sent to the attributes feed will return a feed of
  attributes which are present in the items that match the
  query. 
  """

  def _TakeChildFromElementTree(self, child, element_tree):
    if child.tag == '{%s}%s' % (atom.ATOM_NAMESPACE, 'entry'):
      self.entry.append(_GBaseAttributeEntryFromElementTree(child))
      element_tree.remove(child)
    else:
Esempio n. 4
0
  
  def _TakeChildFromElementTree(self, child, element_tree):
    if child.tag == '{%s}%s' % (atom.ATOM_NAMESPACE, 'id'):
      atom.Entry._TakeChildFromElementTree(self, child, element_tree)
      if self.id and self.id.text:
        self.id.text = self.id.text.strip()
    else:
      atom.Entry._TakeChildFromElementTree(self, child, element_tree)
  
def GDataEntryFromString(xml_string):
  """Creates a new GDataEntry instance given a string of XML."""

  element_tree = ElementTree.fromstring(xml_string)
  return _GDataEntryFromElementTree(element_tree)

_GDataEntryFromElementTree = atom._AtomInstanceFromElementTree(GDataEntry, 
    'entry', atom.ATOM_NAMESPACE)

class TotalResults(atom.AtomBase):
  """opensearch:TotalResults for a GData feed"""

  def __init__(self, extension_elements=None,
     extension_attributes=None, text=None):
    self.text = text
    self.extension_elements = extension_elements or []
    self.extension_attributes = extension_attributes or {}

  def _TransferToElementTree(self, element_tree):
    element_tree.tag = OPENSEARCH_TEMPLATE % 'totalResults'
    atom.AtomBase._TransferToElementTree(self, element_tree)
    return element_tree
Esempio n. 5
0
class CalendarEventEntryLink(gdata.EntryLink):
  """An entryLink which contains a calendar event entry
  
  Within an event's recurranceExceptions, an entry link
  points to a calendar event entry. This class exists
  to capture the calendar specific extensions in the entry.
  """

  def _TakeChildFromElementTree(self, child, element_tree):
    if child.tag == '{%s}%s' % (atom.ATOM_NAMESPACE, 'entry'):
      self.entry = _CalendarEventEntryFromElementTree(child)
      element_tree.remove(child)
    else:
      gdata.EntryLink._TakeChildFromElementTree(self, child, element_tree)

_CalendarEventEntryLinkFromElementTree = atom._AtomInstanceFromElementTree(
    CalendarEventEntryLink, 'entryLink', gdata.GDATA_NAMESPACE)

def CalendarEventEntryLinkFromString(xml_string):
  element_tree = ElementTree.fromstring(xml_string)
  return _CalendarEventEntryLinkFromElementTree(element_tree)
  

class RecurrenceException(atom.AtomBase):
  """The Google Calendar RecurrenceException element"""
  
  def __init__(self, specialized=None, entry_link=None, 
      original_event=None, extension_elements=None, 
      extension_attributes=None, text=None):
    self.specialized = specialized
    self.entry_link = entry_link
    self.original_event = original_event