/gdata/apps/migration/__init__.py

http://radioappz.googlecode.com/ · Python · 212 lines · 133 code · 50 blank · 29 comment · 15 complexity · 08a6b4b05fbcb66e4965dda03eae2c50 MD5 · raw file

  1. #!/usr/bin/python
  2. #
  3. # Copyright (C) 2008 Google
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License");
  6. # you may not use this file except in compliance with the License.
  7. # You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. """Contains objects used with Google Apps."""
  17. __author__ = 'google-apps-apis@googlegroups.com'
  18. import atom
  19. import gdata
  20. # XML namespaces which are often used in Google Apps entity.
  21. APPS_NAMESPACE = 'http://schemas.google.com/apps/2006'
  22. APPS_TEMPLATE = '{http://schemas.google.com/apps/2006}%s'
  23. class Rfc822Msg(atom.AtomBase):
  24. """The Migration rfc822Msg element."""
  25. _tag = 'rfc822Msg'
  26. _namespace = APPS_NAMESPACE
  27. _children = atom.AtomBase._children.copy()
  28. _attributes = atom.AtomBase._attributes.copy()
  29. _attributes['encoding'] = 'encoding'
  30. def __init__(self, extension_elements=None,
  31. extension_attributes=None, text=None):
  32. self.text = text
  33. self.encoding = 'base64'
  34. self.extension_elements = extension_elements or []
  35. self.extension_attributes = extension_attributes or {}
  36. def Rfc822MsgFromString(xml_string):
  37. """Parse in the Rrc822 message from the XML definition."""
  38. return atom.CreateClassFromXMLString(Rfc822Msg, xml_string)
  39. class MailItemProperty(atom.AtomBase):
  40. """The Migration mailItemProperty element."""
  41. _tag = 'mailItemProperty'
  42. _namespace = APPS_NAMESPACE
  43. _children = atom.AtomBase._children.copy()
  44. _attributes = atom.AtomBase._attributes.copy()
  45. _attributes['value'] = 'value'
  46. def __init__(self, value=None, extension_elements=None,
  47. extension_attributes=None, text=None):
  48. self.value = value
  49. self.text = text
  50. self.extension_elements = extension_elements or []
  51. self.extension_attributes = extension_attributes or {}
  52. def MailItemPropertyFromString(xml_string):
  53. """Parse in the MailItemProperiy from the XML definition."""
  54. return atom.CreateClassFromXMLString(MailItemProperty, xml_string)
  55. class Label(atom.AtomBase):
  56. """The Migration label element."""
  57. _tag = 'label'
  58. _namespace = APPS_NAMESPACE
  59. _children = atom.AtomBase._children.copy()
  60. _attributes = atom.AtomBase._attributes.copy()
  61. _attributes['labelName'] = 'label_name'
  62. def __init__(self, label_name=None,
  63. extension_elements=None, extension_attributes=None,
  64. text=None):
  65. self.label_name = label_name
  66. self.text = text
  67. self.extension_elements = extension_elements or []
  68. self.extension_attributes = extension_attributes or {}
  69. def LabelFromString(xml_string):
  70. """Parse in the mailItemProperty from the XML definition."""
  71. return atom.CreateClassFromXMLString(Label, xml_string)
  72. class MailEntry(gdata.GDataEntry):
  73. """A Google Migration flavor of an Atom Entry."""
  74. _tag = 'entry'
  75. _namespace = atom.ATOM_NAMESPACE
  76. _children = gdata.GDataEntry._children.copy()
  77. _attributes = gdata.GDataEntry._attributes.copy()
  78. _children['{%s}rfc822Msg' % APPS_NAMESPACE] = ('rfc822_msg', Rfc822Msg)
  79. _children['{%s}mailItemProperty' % APPS_NAMESPACE] = ('mail_item_property',
  80. [MailItemProperty])
  81. _children['{%s}label' % APPS_NAMESPACE] = ('label', [Label])
  82. def __init__(self, author=None, category=None, content=None,
  83. atom_id=None, link=None, published=None,
  84. title=None, updated=None,
  85. rfc822_msg=None, mail_item_property=None, label=None,
  86. extended_property=None,
  87. extension_elements=None, extension_attributes=None, text=None):
  88. gdata.GDataEntry.__init__(self, author=author, category=category,
  89. content=content,
  90. atom_id=atom_id, link=link, published=published,
  91. title=title, updated=updated)
  92. self.rfc822_msg = rfc822_msg
  93. self.mail_item_property = mail_item_property
  94. self.label = label
  95. self.extended_property = extended_property or []
  96. self.text = text
  97. self.extension_elements = extension_elements or []
  98. self.extension_attributes = extension_attributes or {}
  99. def MailEntryFromString(xml_string):
  100. """Parse in the MailEntry from the XML definition."""
  101. return atom.CreateClassFromXMLString(MailEntry, xml_string)
  102. class BatchMailEntry(gdata.BatchEntry):
  103. """A Google Migration flavor of an Atom Entry."""
  104. _tag = gdata.BatchEntry._tag
  105. _namespace = gdata.BatchEntry._namespace
  106. _children = gdata.BatchEntry._children.copy()
  107. _attributes = gdata.BatchEntry._attributes.copy()
  108. _children['{%s}rfc822Msg' % APPS_NAMESPACE] = ('rfc822_msg', Rfc822Msg)
  109. _children['{%s}mailItemProperty' % APPS_NAMESPACE] = ('mail_item_property',
  110. [MailItemProperty])
  111. _children['{%s}label' % APPS_NAMESPACE] = ('label', [Label])
  112. def __init__(self, author=None, category=None, content=None,
  113. atom_id=None, link=None, published=None,
  114. title=None, updated=None,
  115. rfc822_msg=None, mail_item_property=None, label=None,
  116. batch_operation=None, batch_id=None, batch_status=None,
  117. extended_property=None,
  118. extension_elements=None, extension_attributes=None, text=None):
  119. gdata.BatchEntry.__init__(self, author=author, category=category,
  120. content=content,
  121. atom_id=atom_id, link=link, published=published,
  122. batch_operation=batch_operation,
  123. batch_id=batch_id, batch_status=batch_status,
  124. title=title, updated=updated)
  125. self.rfc822_msg = rfc822_msg or None
  126. self.mail_item_property = mail_item_property or []
  127. self.label = label or []
  128. self.extended_property = extended_property or []
  129. self.text = text
  130. self.extension_elements = extension_elements or []
  131. self.extension_attributes = extension_attributes or {}
  132. def BatchMailEntryFromString(xml_string):
  133. """Parse in the BatchMailEntry from the XML definition."""
  134. return atom.CreateClassFromXMLString(BatchMailEntry, xml_string)
  135. class BatchMailEventFeed(gdata.BatchFeed):
  136. """A Migration event feed flavor of an Atom Feed."""
  137. _tag = gdata.BatchFeed._tag
  138. _namespace = gdata.BatchFeed._namespace
  139. _children = gdata.BatchFeed._children.copy()
  140. _attributes = gdata.BatchFeed._attributes.copy()
  141. _children['{%s}entry' % atom.ATOM_NAMESPACE] = ('entry', [BatchMailEntry])
  142. def __init__(self, author=None, category=None, contributor=None,
  143. generator=None, icon=None, atom_id=None, link=None, logo=None,
  144. rights=None, subtitle=None, title=None, updated=None,
  145. entry=None, total_results=None, start_index=None,
  146. items_per_page=None, interrupted=None, extension_elements=None,
  147. extension_attributes=None, text=None):
  148. gdata.BatchFeed.__init__(self, author=author, category=category,
  149. contributor=contributor, generator=generator,
  150. icon=icon, atom_id=atom_id, link=link,
  151. logo=logo, rights=rights, subtitle=subtitle,
  152. title=title, updated=updated, entry=entry,
  153. total_results=total_results,
  154. start_index=start_index,
  155. items_per_page=items_per_page,
  156. interrupted=interrupted,
  157. extension_elements=extension_elements,
  158. extension_attributes=extension_attributes,
  159. text=text)
  160. def BatchMailEventFeedFromString(xml_string):
  161. """Parse in the BatchMailEventFeed from the XML definition."""
  162. return atom.CreateClassFromXMLString(BatchMailEventFeed, xml_string)