~pablo-elenya/exaile/diacritica

« back to all changes in this revision

Viewing changes to plugins/gcalc/gdata/docs/__init__.py

  • Committer: Pablo Ruiz Múzquiz
  • Date: 2010-01-11 19:53:01 UTC
  • Revision ID: pruiz@ubuntuvm-20100111195301-pm1d2ppe36gytu77
initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
#
 
3
# Copyright 2009 Google Inc. All Rights Reserved.
 
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 extensions to Atom objects used with Google Documents."""
 
18
 
 
19
__author__ = ('api.jfisher (Jeff Fisher), '
 
20
              'api.eric@google.com (Eric Bidelman)')
 
21
 
 
22
import atom
 
23
import gdata
 
24
 
 
25
 
 
26
DOCUMENTS_NAMESPACE = 'http://schemas.google.com/docs/2007'
 
27
 
 
28
 
 
29
class Scope(atom.AtomBase):
 
30
  """The DocList ACL scope element"""
 
31
 
 
32
  _tag = 'scope'
 
33
  _namespace = gdata.GACL_NAMESPACE
 
34
  _children = atom.AtomBase._children.copy()
 
35
  _attributes = atom.AtomBase._attributes.copy()
 
36
  _attributes['value'] = 'value'
 
37
  _attributes['type'] = 'type'
 
38
 
 
39
  def __init__(self, value=None, type=None, extension_elements=None,
 
40
               extension_attributes=None, text=None):
 
41
    self.value = value
 
42
    self.type = type
 
43
    self.text = text
 
44
    self.extension_elements = extension_elements or []
 
45
    self.extension_attributes = extension_attributes or {}
 
46
 
 
47
 
 
48
class Role(atom.AtomBase):
 
49
  """The DocList ACL role element"""
 
50
 
 
51
  _tag = 'role'
 
52
  _namespace = gdata.GACL_NAMESPACE
 
53
  _children = atom.AtomBase._children.copy()
 
54
  _attributes = atom.AtomBase._attributes.copy()
 
55
  _attributes['value'] = 'value'
 
56
 
 
57
  def __init__(self, value=None, extension_elements=None,
 
58
               extension_attributes=None, text=None):
 
59
    self.value = value
 
60
    self.text = text
 
61
    self.extension_elements = extension_elements or []
 
62
    self.extension_attributes = extension_attributes or {}
 
63
 
 
64
 
 
65
class FeedLink(atom.AtomBase):
 
66
  """The DocList gd:feedLink element"""
 
67
 
 
68
  _tag = 'feedLink'
 
69
  _namespace = gdata.GDATA_NAMESPACE
 
70
  _attributes = atom.AtomBase._attributes.copy()
 
71
  _attributes['rel'] = 'rel'
 
72
  _attributes['href'] = 'href'
 
73
 
 
74
  def __init__(self, href=None, rel=None, text=None, extension_elements=None,
 
75
               extension_attributes=None):
 
76
    self.href = href
 
77
    self.rel = rel
 
78
    atom.AtomBase.__init__(self, extension_elements=extension_elements,
 
79
                           extension_attributes=extension_attributes, text=text)
 
80
 
 
81
 
 
82
class ResourceId(atom.AtomBase):
 
83
  """The DocList gd:resourceId element"""
 
84
 
 
85
  _tag = 'resourceId'
 
86
  _namespace = gdata.GDATA_NAMESPACE
 
87
  _children = atom.AtomBase._children.copy()
 
88
  _attributes = atom.AtomBase._attributes.copy()
 
89
  _attributes['value'] = 'value'
 
90
 
 
91
  def __init__(self, value=None, extension_elements=None,
 
92
               extension_attributes=None, text=None):
 
93
    self.value = value
 
94
    self.text = text
 
95
    self.extension_elements = extension_elements or []
 
96
    self.extension_attributes = extension_attributes or {}
 
97
 
 
98
 
 
99
class LastModifiedBy(atom.Person):
 
100
  """The DocList gd:lastModifiedBy element"""
 
101
 
 
102
  _tag = 'lastModifiedBy'
 
103
  _namespace = gdata.GDATA_NAMESPACE
 
104
 
 
105
 
 
106
class LastViewed(atom.Person):
 
107
  """The DocList gd:lastViewed element"""
 
108
 
 
109
  _tag = 'lastViewed'
 
110
  _namespace = gdata.GDATA_NAMESPACE
 
111
 
 
112
 
 
113
class WritersCanInvite(atom.AtomBase):
 
114
  """The DocList docs:writersCanInvite element"""
 
115
 
 
116
  _tag = 'writersCanInvite'
 
117
  _namespace = DOCUMENTS_NAMESPACE
 
118
  _attributes = atom.AtomBase._attributes.copy()
 
119
  _attributes['value'] = 'value'
 
120
 
 
121
 
 
122
class DocumentListEntry(gdata.GDataEntry):
 
123
  """The Google Documents version of an Atom Entry"""
 
124
 
 
125
  _tag = gdata.GDataEntry._tag
 
126
  _namespace = atom.ATOM_NAMESPACE
 
127
  _children = gdata.GDataEntry._children.copy()
 
128
  _attributes = gdata.GDataEntry._attributes.copy()
 
129
  _children['{%s}feedLink' % gdata.GDATA_NAMESPACE] = ('feedLink', FeedLink)
 
130
  _children['{%s}resourceId' % gdata.GDATA_NAMESPACE] = ('resourceId',
 
131
                                                         ResourceId)
 
132
  _children['{%s}lastModifiedBy' % gdata.GDATA_NAMESPACE] = ('lastModifiedBy',
 
133
                                                             LastModifiedBy)
 
134
  _children['{%s}lastViewed' % gdata.GDATA_NAMESPACE] = ('lastViewed',
 
135
                                                         LastViewed)
 
136
  _children['{%s}writersCanInvite' % DOCUMENTS_NAMESPACE] = (
 
137
      'writersCanInvite', WritersCanInvite)
 
138
 
 
139
  def __init__(self, resourceId=None, feedLink=None, lastViewed=None,
 
140
               lastModifiedBy=None, writersCanInvite=None, author=None,
 
141
               category=None, content=None, atom_id=None, link=None,
 
142
               published=None, title=None, updated=None, text=None,
 
143
               extension_elements=None, extension_attributes=None):
 
144
    self.feedLink = feedLink
 
145
    self.lastViewed = lastViewed
 
146
    self.lastModifiedBy = lastModifiedBy
 
147
    self.resourceId = resourceId
 
148
    self.writersCanInvite = writersCanInvite
 
149
    gdata.GDataEntry.__init__(
 
150
        self, author=author, category=category, content=content,
 
151
        atom_id=atom_id, link=link, published=published, title=title,
 
152
        updated=updated, extension_elements=extension_elements,
 
153
        extension_attributes=extension_attributes, text=text)
 
154
 
 
155
  def GetAclLink(self):
 
156
    """Extracts the DocListEntry's <gd:feedLink>.
 
157
 
 
158
    Returns:
 
159
      A FeedLink object.
 
160
    """
 
161
    return self.feedLink
 
162
 
 
163
  def GetDocumentType(self):
 
164
    """Extracts the type of document from the DocListEntry.
 
165
 
 
166
    This method returns the type of document the DocListEntry
 
167
    represents.  Possible values are document, presentation,
 
168
    spreadsheet, folder, or pdf.
 
169
 
 
170
    Returns:
 
171
      A string representing the type of document.
 
172
    """
 
173
    if self.category:
 
174
      for category in self.category:
 
175
        if category.scheme == gdata.GDATA_NAMESPACE + '#kind':
 
176
          return category.label
 
177
    else:
 
178
      return None
 
179
 
 
180
 
 
181
def DocumentListEntryFromString(xml_string):
 
182
  """Converts an XML string into a DocumentListEntry object.
 
183
 
 
184
  Args:
 
185
    xml_string: string The XML describing a Document List feed entry.
 
186
 
 
187
  Returns:
 
188
    A DocumentListEntry object corresponding to the given XML.
 
189
  """
 
190
  return atom.CreateClassFromXMLString(DocumentListEntry, xml_string)
 
191
 
 
192
 
 
193
class DocumentListAclEntry(gdata.GDataEntry):
 
194
  """A DocList ACL Entry flavor of an Atom Entry"""
 
195
 
 
196
  _tag = gdata.GDataEntry._tag
 
197
  _namespace = gdata.GDataEntry._namespace
 
198
  _children = gdata.GDataEntry._children.copy()
 
199
  _attributes = gdata.GDataEntry._attributes.copy()
 
200
  _children['{%s}scope' % gdata.GACL_NAMESPACE] = ('scope', Scope)
 
201
  _children['{%s}role' % gdata.GACL_NAMESPACE] = ('role', Role)
 
202
 
 
203
  def __init__(self, category=None, atom_id=None, link=None,
 
204
               title=None, updated=None, scope=None, role=None,
 
205
               extension_elements=None, extension_attributes=None, text=None):
 
206
    gdata.GDataEntry.__init__(self, author=None, category=category,
 
207
                              content=None, atom_id=atom_id, link=link,
 
208
                              published=None, title=title,
 
209
                              updated=updated, text=None)
 
210
    self.scope = scope
 
211
    self.role = role
 
212
 
 
213
 
 
214
def DocumentListAclEntryFromString(xml_string):
 
215
  """Converts an XML string into a DocumentListAclEntry object.
 
216
 
 
217
  Args:
 
218
    xml_string: string The XML describing a Document List ACL feed entry.
 
219
 
 
220
  Returns:
 
221
    A DocumentListAclEntry object corresponding to the given XML.
 
222
  """
 
223
  return atom.CreateClassFromXMLString(DocumentListAclEntry, xml_string)
 
224
 
 
225
 
 
226
class DocumentListFeed(gdata.GDataFeed):
 
227
  """A feed containing a list of Google Documents Items"""
 
228
 
 
229
  _tag = gdata.GDataFeed._tag
 
230
  _namespace = atom.ATOM_NAMESPACE
 
231
  _children = gdata.GDataFeed._children.copy()
 
232
  _attributes = gdata.GDataFeed._attributes.copy()
 
233
  _children['{%s}entry' % atom.ATOM_NAMESPACE] = ('entry',
 
234
                                                  [DocumentListEntry])
 
235
 
 
236
 
 
237
def DocumentListFeedFromString(xml_string):
 
238
  """Converts an XML string into a DocumentListFeed object.
 
239
 
 
240
  Args:
 
241
    xml_string: string The XML describing a DocumentList feed.
 
242
 
 
243
  Returns:
 
244
    A DocumentListFeed object corresponding to the given XML.
 
245
  """
 
246
  return atom.CreateClassFromXMLString(DocumentListFeed, xml_string)
 
247
 
 
248
 
 
249
class DocumentListAclFeed(gdata.GDataFeed):
 
250
  """A DocList ACL feed flavor of a Atom feed"""
 
251
 
 
252
  _tag = gdata.GDataFeed._tag
 
253
  _namespace = atom.ATOM_NAMESPACE
 
254
  _children = gdata.GDataFeed._children.copy()
 
255
  _attributes = gdata.GDataFeed._attributes.copy()
 
256
  _children['{%s}entry' % atom.ATOM_NAMESPACE] = ('entry', 
 
257
                                                  [DocumentListAclEntry])
 
258
 
 
259
 
 
260
def DocumentListAclFeedFromString(xml_string):
 
261
  """Converts an XML string into a DocumentListAclFeed object.
 
262
 
 
263
  Args:
 
264
    xml_string: string The XML describing a DocumentList feed.
 
265
 
 
266
  Returns:
 
267
    A DocumentListFeed object corresponding to the given XML.
 
268
  """
 
269
  return atom.CreateClassFromXMLString(DocumentListAclFeed, xml_string)