PageRenderTime 36ms CodeModel.GetById 18ms app.highlight 15ms RepoModel.GetById 1ms app.codeStats 0ms

/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
 17"""Contains objects used with Google Apps."""
 18
 19__author__ = 'google-apps-apis@googlegroups.com'
 20
 21
 22import atom
 23import gdata
 24
 25
 26# XML namespaces which are often used in Google Apps entity.
 27APPS_NAMESPACE = 'http://schemas.google.com/apps/2006'
 28APPS_TEMPLATE = '{http://schemas.google.com/apps/2006}%s'
 29
 30
 31class Rfc822Msg(atom.AtomBase):
 32  """The Migration rfc822Msg element."""
 33
 34  _tag = 'rfc822Msg'
 35  _namespace = APPS_NAMESPACE
 36  _children = atom.AtomBase._children.copy()
 37  _attributes = atom.AtomBase._attributes.copy()
 38  _attributes['encoding'] = 'encoding'
 39
 40  def __init__(self, extension_elements=None,
 41               extension_attributes=None, text=None):
 42    self.text = text
 43    self.encoding = 'base64'
 44    self.extension_elements = extension_elements or []
 45    self.extension_attributes = extension_attributes or {}
 46
 47
 48def Rfc822MsgFromString(xml_string):
 49  """Parse in the Rrc822 message from the XML definition."""
 50
 51  return atom.CreateClassFromXMLString(Rfc822Msg, xml_string)
 52
 53
 54class MailItemProperty(atom.AtomBase):
 55  """The Migration mailItemProperty element."""
 56
 57  _tag = 'mailItemProperty'
 58  _namespace = APPS_NAMESPACE
 59  _children = atom.AtomBase._children.copy()
 60  _attributes = atom.AtomBase._attributes.copy()
 61  _attributes['value'] = 'value'
 62
 63  def __init__(self, value=None, extension_elements=None,
 64               extension_attributes=None, text=None):
 65    self.value = value
 66    self.text = text
 67    self.extension_elements = extension_elements or []
 68    self.extension_attributes = extension_attributes or {}
 69
 70
 71def MailItemPropertyFromString(xml_string):
 72  """Parse in the MailItemProperiy from the XML definition."""
 73
 74  return atom.CreateClassFromXMLString(MailItemProperty, xml_string)
 75
 76
 77class Label(atom.AtomBase):
 78  """The Migration label element."""
 79
 80  _tag = 'label'
 81  _namespace = APPS_NAMESPACE
 82  _children = atom.AtomBase._children.copy()
 83  _attributes = atom.AtomBase._attributes.copy()
 84  _attributes['labelName'] = 'label_name'
 85
 86  def __init__(self, label_name=None,
 87               extension_elements=None, extension_attributes=None,
 88               text=None):
 89    self.label_name = label_name
 90    self.text = text
 91    self.extension_elements = extension_elements or []
 92    self.extension_attributes = extension_attributes or {}
 93
 94
 95def LabelFromString(xml_string):
 96  """Parse in the mailItemProperty from the XML definition."""
 97
 98  return atom.CreateClassFromXMLString(Label, xml_string)
 99
100
101class MailEntry(gdata.GDataEntry):
102  """A Google Migration flavor of an Atom Entry."""
103
104  _tag = 'entry'
105  _namespace = atom.ATOM_NAMESPACE
106  _children = gdata.GDataEntry._children.copy()
107  _attributes = gdata.GDataEntry._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
113  def __init__(self, author=None, category=None, content=None,
114               atom_id=None, link=None, published=None,
115               title=None, updated=None,
116               rfc822_msg=None, mail_item_property=None, label=None,
117               extended_property=None,
118               extension_elements=None, extension_attributes=None, text=None):
119
120    gdata.GDataEntry.__init__(self, author=author, category=category,
121                              content=content,
122                              atom_id=atom_id, link=link, published=published,
123                              title=title, updated=updated)
124    self.rfc822_msg = rfc822_msg
125    self.mail_item_property = mail_item_property
126    self.label = label
127    self.extended_property = extended_property or []
128    self.text = text
129    self.extension_elements = extension_elements or []
130    self.extension_attributes = extension_attributes or {}
131
132
133def MailEntryFromString(xml_string):
134  """Parse in the MailEntry from the XML definition."""
135
136  return atom.CreateClassFromXMLString(MailEntry, xml_string)
137
138
139class BatchMailEntry(gdata.BatchEntry):
140  """A Google Migration flavor of an Atom Entry."""
141
142  _tag = gdata.BatchEntry._tag
143  _namespace = gdata.BatchEntry._namespace
144  _children = gdata.BatchEntry._children.copy()
145  _attributes = gdata.BatchEntry._attributes.copy()
146  _children['{%s}rfc822Msg' % APPS_NAMESPACE] = ('rfc822_msg', Rfc822Msg)
147  _children['{%s}mailItemProperty' % APPS_NAMESPACE] = ('mail_item_property',
148                                                        [MailItemProperty])
149  _children['{%s}label' % APPS_NAMESPACE] = ('label', [Label])
150
151  def __init__(self, author=None, category=None, content=None,
152               atom_id=None, link=None, published=None,
153               title=None, updated=None,
154               rfc822_msg=None, mail_item_property=None, label=None,
155               batch_operation=None, batch_id=None, batch_status=None,
156               extended_property=None,
157               extension_elements=None, extension_attributes=None, text=None):
158
159    gdata.BatchEntry.__init__(self, author=author, category=category,
160                              content=content,
161                              atom_id=atom_id, link=link, published=published,
162                              batch_operation=batch_operation,
163                              batch_id=batch_id, batch_status=batch_status,
164                              title=title, updated=updated)
165    self.rfc822_msg = rfc822_msg or None
166    self.mail_item_property = mail_item_property or []
167    self.label = label or []
168    self.extended_property = extended_property or []
169    self.text = text
170    self.extension_elements = extension_elements or []
171    self.extension_attributes = extension_attributes or {}
172
173
174def BatchMailEntryFromString(xml_string):
175  """Parse in the BatchMailEntry from the XML definition."""
176
177  return atom.CreateClassFromXMLString(BatchMailEntry, xml_string)
178
179
180class BatchMailEventFeed(gdata.BatchFeed):
181  """A Migration event feed flavor of an Atom Feed."""
182
183  _tag = gdata.BatchFeed._tag
184  _namespace = gdata.BatchFeed._namespace
185  _children = gdata.BatchFeed._children.copy()
186  _attributes = gdata.BatchFeed._attributes.copy()
187  _children['{%s}entry' % atom.ATOM_NAMESPACE] = ('entry', [BatchMailEntry])
188
189  def __init__(self, author=None, category=None, contributor=None,
190               generator=None, icon=None, atom_id=None, link=None, logo=None,
191               rights=None, subtitle=None, title=None, updated=None,
192               entry=None, total_results=None, start_index=None,
193               items_per_page=None, interrupted=None, extension_elements=None,
194               extension_attributes=None, text=None):
195    gdata.BatchFeed.__init__(self, author=author, category=category,
196                             contributor=contributor, generator=generator,
197                             icon=icon, atom_id=atom_id, link=link,
198                             logo=logo, rights=rights, subtitle=subtitle,
199                             title=title, updated=updated, entry=entry,
200                             total_results=total_results,
201                             start_index=start_index,
202                             items_per_page=items_per_page,
203                             interrupted=interrupted,
204                             extension_elements=extension_elements,
205                             extension_attributes=extension_attributes,
206                             text=text)
207
208
209def BatchMailEventFeedFromString(xml_string):
210  """Parse in the BatchMailEventFeed from the XML definition."""
211
212  return atom.CreateClassFromXMLString(BatchMailEventFeed, xml_string)