3
# Copyright 2009 Google Inc. All Rights Reserved.
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
9
# http://www.apache.org/licenses/LICENSE-2.0
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.
17
"""Contains extensions to Atom objects used with Google Documents."""
19
__author__ = ('api.jfisher (Jeff Fisher), '
20
'api.eric@google.com (Eric Bidelman)')
26
DOCUMENTS_NAMESPACE = 'http://schemas.google.com/docs/2007'
29
class Scope(atom.AtomBase):
30
"""The DocList ACL scope element"""
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'
39
def __init__(self, value=None, type=None, extension_elements=None,
40
extension_attributes=None, text=None):
44
self.extension_elements = extension_elements or []
45
self.extension_attributes = extension_attributes or {}
48
class Role(atom.AtomBase):
49
"""The DocList ACL role element"""
52
_namespace = gdata.GACL_NAMESPACE
53
_children = atom.AtomBase._children.copy()
54
_attributes = atom.AtomBase._attributes.copy()
55
_attributes['value'] = 'value'
57
def __init__(self, value=None, extension_elements=None,
58
extension_attributes=None, text=None):
61
self.extension_elements = extension_elements or []
62
self.extension_attributes = extension_attributes or {}
65
class FeedLink(atom.AtomBase):
66
"""The DocList gd:feedLink element"""
69
_namespace = gdata.GDATA_NAMESPACE
70
_attributes = atom.AtomBase._attributes.copy()
71
_attributes['rel'] = 'rel'
72
_attributes['href'] = 'href'
74
def __init__(self, href=None, rel=None, text=None, extension_elements=None,
75
extension_attributes=None):
78
atom.AtomBase.__init__(self, extension_elements=extension_elements,
79
extension_attributes=extension_attributes, text=text)
82
class ResourceId(atom.AtomBase):
83
"""The DocList gd:resourceId element"""
86
_namespace = gdata.GDATA_NAMESPACE
87
_children = atom.AtomBase._children.copy()
88
_attributes = atom.AtomBase._attributes.copy()
89
_attributes['value'] = 'value'
91
def __init__(self, value=None, extension_elements=None,
92
extension_attributes=None, text=None):
95
self.extension_elements = extension_elements or []
96
self.extension_attributes = extension_attributes or {}
99
class LastModifiedBy(atom.Person):
100
"""The DocList gd:lastModifiedBy element"""
102
_tag = 'lastModifiedBy'
103
_namespace = gdata.GDATA_NAMESPACE
106
class LastViewed(atom.Person):
107
"""The DocList gd:lastViewed element"""
110
_namespace = gdata.GDATA_NAMESPACE
113
class WritersCanInvite(atom.AtomBase):
114
"""The DocList docs:writersCanInvite element"""
116
_tag = 'writersCanInvite'
117
_namespace = DOCUMENTS_NAMESPACE
118
_attributes = atom.AtomBase._attributes.copy()
119
_attributes['value'] = 'value'
122
class DocumentListEntry(gdata.GDataEntry):
123
"""The Google Documents version of an Atom Entry"""
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',
132
_children['{%s}lastModifiedBy' % gdata.GDATA_NAMESPACE] = ('lastModifiedBy',
134
_children['{%s}lastViewed' % gdata.GDATA_NAMESPACE] = ('lastViewed',
136
_children['{%s}writersCanInvite' % DOCUMENTS_NAMESPACE] = (
137
'writersCanInvite', WritersCanInvite)
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)
155
def GetAclLink(self):
156
"""Extracts the DocListEntry's <gd:feedLink>.
163
def GetDocumentType(self):
164
"""Extracts the type of document from the DocListEntry.
166
This method returns the type of document the DocListEntry
167
represents. Possible values are document, presentation,
168
spreadsheet, folder, or pdf.
171
A string representing the type of document.
174
for category in self.category:
175
if category.scheme == gdata.GDATA_NAMESPACE + '#kind':
176
return category.label
181
def DocumentListEntryFromString(xml_string):
182
"""Converts an XML string into a DocumentListEntry object.
185
xml_string: string The XML describing a Document List feed entry.
188
A DocumentListEntry object corresponding to the given XML.
190
return atom.CreateClassFromXMLString(DocumentListEntry, xml_string)
193
class DocumentListAclEntry(gdata.GDataEntry):
194
"""A DocList ACL Entry flavor of an Atom Entry"""
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)
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)
214
def DocumentListAclEntryFromString(xml_string):
215
"""Converts an XML string into a DocumentListAclEntry object.
218
xml_string: string The XML describing a Document List ACL feed entry.
221
A DocumentListAclEntry object corresponding to the given XML.
223
return atom.CreateClassFromXMLString(DocumentListAclEntry, xml_string)
226
class DocumentListFeed(gdata.GDataFeed):
227
"""A feed containing a list of Google Documents Items"""
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',
237
def DocumentListFeedFromString(xml_string):
238
"""Converts an XML string into a DocumentListFeed object.
241
xml_string: string The XML describing a DocumentList feed.
244
A DocumentListFeed object corresponding to the given XML.
246
return atom.CreateClassFromXMLString(DocumentListFeed, xml_string)
249
class DocumentListAclFeed(gdata.GDataFeed):
250
"""A DocList ACL feed flavor of a Atom feed"""
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])
260
def DocumentListAclFeedFromString(xml_string):
261
"""Converts an XML string into a DocumentListAclFeed object.
264
xml_string: string The XML describing a DocumentList feed.
267
A DocumentListFeed object corresponding to the given XML.
269
return atom.CreateClassFromXMLString(DocumentListAclFeed, xml_string)