gam7 7.3.4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of gam7 might be problematic. Click here for more details.

Files changed (72) hide show
  1. gam/__init__.py +77555 -0
  2. gam/__main__.py +40 -0
  3. gam/atom/__init__.py +1460 -0
  4. gam/atom/auth.py +41 -0
  5. gam/atom/client.py +214 -0
  6. gam/atom/core.py +535 -0
  7. gam/atom/data.py +327 -0
  8. gam/atom/http.py +354 -0
  9. gam/atom/http_core.py +599 -0
  10. gam/atom/http_interface.py +144 -0
  11. gam/atom/mock_http.py +123 -0
  12. gam/atom/mock_http_core.py +313 -0
  13. gam/atom/mock_service.py +235 -0
  14. gam/atom/service.py +723 -0
  15. gam/atom/token_store.py +105 -0
  16. gam/atom/url.py +130 -0
  17. gam/cacerts.pem +1130 -0
  18. gam/cbcm-v1.1beta1.json +593 -0
  19. gam/contactdelegation-v1.json +249 -0
  20. gam/datastudio-v1.json +486 -0
  21. gam/gamlib/__init__.py +17 -0
  22. gam/gamlib/glaction.py +308 -0
  23. gam/gamlib/glapi.py +837 -0
  24. gam/gamlib/glcfg.py +616 -0
  25. gam/gamlib/glclargs.py +1184 -0
  26. gam/gamlib/glentity.py +831 -0
  27. gam/gamlib/glgapi.py +817 -0
  28. gam/gamlib/glgdata.py +98 -0
  29. gam/gamlib/glglobals.py +307 -0
  30. gam/gamlib/glindent.py +46 -0
  31. gam/gamlib/glmsgs.py +547 -0
  32. gam/gamlib/glskus.py +246 -0
  33. gam/gamlib/gluprop.py +279 -0
  34. gam/gamlib/glverlibs.py +33 -0
  35. gam/gamlib/yubikey.py +202 -0
  36. gam/gdata/__init__.py +825 -0
  37. gam/gdata/alt/__init__.py +20 -0
  38. gam/gdata/alt/app_engine.py +101 -0
  39. gam/gdata/alt/appengine.py +321 -0
  40. gam/gdata/apps/__init__.py +526 -0
  41. gam/gdata/apps/audit/__init__.py +1 -0
  42. gam/gdata/apps/audit/service.py +278 -0
  43. gam/gdata/apps/contacts/__init__.py +874 -0
  44. gam/gdata/apps/contacts/service.py +355 -0
  45. gam/gdata/apps/service.py +544 -0
  46. gam/gdata/apps/sites/__init__.py +283 -0
  47. gam/gdata/apps/sites/service.py +246 -0
  48. gam/gdata/service.py +1714 -0
  49. gam/gdata/urlfetch.py +247 -0
  50. gam/googleapiclient/__init__.py +27 -0
  51. gam/googleapiclient/_auth.py +167 -0
  52. gam/googleapiclient/_helpers.py +207 -0
  53. gam/googleapiclient/channel.py +315 -0
  54. gam/googleapiclient/discovery.py +1662 -0
  55. gam/googleapiclient/discovery_cache/__init__.py +78 -0
  56. gam/googleapiclient/discovery_cache/appengine_memcache.py +55 -0
  57. gam/googleapiclient/discovery_cache/base.py +46 -0
  58. gam/googleapiclient/discovery_cache/file_cache.py +145 -0
  59. gam/googleapiclient/errors.py +197 -0
  60. gam/googleapiclient/http.py +1962 -0
  61. gam/googleapiclient/mimeparse.py +183 -0
  62. gam/googleapiclient/model.py +429 -0
  63. gam/googleapiclient/schema.py +317 -0
  64. gam/googleapiclient/version.py +15 -0
  65. gam/iso8601/__init__.py +28 -0
  66. gam/iso8601/iso8601.py +160 -0
  67. gam/serviceaccountlookup-v1.json +141 -0
  68. gam/six.py +982 -0
  69. gam7-7.3.4.dist-info/METADATA +69 -0
  70. gam7-7.3.4.dist-info/RECORD +72 -0
  71. gam7-7.3.4.dist-info/WHEEL +4 -0
  72. gam7-7.3.4.dist-info/licenses/LICENSE +201 -0
gam/atom/__init__.py ADDED
@@ -0,0 +1,1460 @@
1
+ #
2
+ # Copyright (C) 2006 Google Inc.
3
+ #
4
+ # Licensed under the Apache License 2.0;
5
+
6
+
7
+
8
+ """Contains classes representing Atom elements.
9
+
10
+ Module objective: provide data classes for Atom constructs. These classes hide
11
+ the XML-ness of Atom and provide a set of native Python classes to interact
12
+ with.
13
+
14
+ Conversions to and from XML should only be necessary when the Atom classes
15
+ "touch the wire" and are sent over HTTP. For this reason this module
16
+ provides methods and functions to convert Atom classes to and from strings.
17
+
18
+ For more information on the Atom data model, see RFC 4287
19
+ (http://www.ietf.org/rfc/rfc4287.txt)
20
+
21
+ AtomBase: A foundation class on which Atom classes are built. It
22
+ handles the parsing of attributes and children which are common to all
23
+ Atom classes. By default, the AtomBase class translates all XML child
24
+ nodes into ExtensionElements.
25
+
26
+ ExtensionElement: Atom allows Atom objects to contain XML which is not part
27
+ of the Atom specification, these are called extension elements. If a
28
+ classes parser encounters an unexpected XML construct, it is translated
29
+ into an ExtensionElement instance. ExtensionElement is designed to fully
30
+ capture the information in the XML. Child nodes in an XML extension are
31
+ turned into ExtensionElements as well.
32
+ """
33
+ from functools import wraps
34
+
35
+ # __author__ = 'api.jscudder (Jeffrey Scudder)'
36
+
37
+ import lxml.etree as ElementTree
38
+ import warnings
39
+
40
+ # XML namespaces which are often used in Atom entities.
41
+ ATOM_NAMESPACE = 'http://www.w3.org/2005/Atom'
42
+ ELEMENT_TEMPLATE = '{http://www.w3.org/2005/Atom}%s'
43
+ APP_NAMESPACE = 'http://purl.org/atom/app#'
44
+ APP_TEMPLATE = '{http://purl.org/atom/app#}%s'
45
+
46
+ # This encoding is used for converting strings before translating the XML
47
+ # into an object.
48
+ XML_STRING_ENCODING = 'utf-8'
49
+ # The desired string encoding for object members. set or monkey-patch to
50
+ # unicode if you want object members to be Python unicode strings, instead of
51
+ # encoded strings
52
+ MEMBER_STRING_ENCODING = str
53
+ #MEMBER_STRING_ENCODING = 'utf-8'
54
+ # MEMBER_STRING_ENCODING = unicode
55
+
56
+ # If True, all methods which are exclusive to v1 will raise a
57
+ # DeprecationWarning
58
+ ENABLE_V1_WARNINGS = False
59
+
60
+
61
+ def v1_deprecated(warning=None):
62
+ """Shows a warning if ENABLE_V1_WARNINGS is True.
63
+
64
+ Function decorator used to mark methods used in v1 classes which
65
+ may be removed in future versions of the library.
66
+ """
67
+ warning = warning or ''
68
+
69
+ # This closure is what is returned from the deprecated function.
70
+ def mark_deprecated(f):
71
+ # The deprecated_function wraps the actual call to f.
72
+ @wraps(f)
73
+ def optional_warn_function(*args, **kwargs):
74
+ if ENABLE_V1_WARNINGS:
75
+ warnings.warn(warning, DeprecationWarning, stacklevel=2)
76
+ return f(*args, **kwargs)
77
+
78
+ return optional_warn_function
79
+
80
+ return mark_deprecated
81
+
82
+
83
+ def CreateClassFromXMLString(target_class, xml_string, string_encoding=None):
84
+ """Creates an instance of the target class from the string contents.
85
+
86
+ Args:
87
+ target_class: class The class which will be instantiated and populated
88
+ with the contents of the XML. This class must have a _tag and a
89
+ _namespace class variable.
90
+ xml_string: str A string which contains valid XML. The root element
91
+ of the XML string should match the tag and namespace of the desired
92
+ class.
93
+ string_encoding: str The character encoding which the xml_string should
94
+ be converted to before it is interpreted and translated into
95
+ objects. The default is None in which case the string encoding
96
+ is not changed.
97
+
98
+ Returns:
99
+ An instance of the target class with members assigned according to the
100
+ contents of the XML - or None if the root XML tag and namespace did not
101
+ match those of the target class.
102
+ """
103
+ encoding = string_encoding or XML_STRING_ENCODING
104
+ if encoding and isinstance(xml_string, str):
105
+ xml_string = xml_string.encode(encoding)
106
+ tree = ElementTree.fromstring(xml_string)
107
+ return _CreateClassFromElementTree(target_class, tree)
108
+
109
+
110
+ CreateClassFromXMLString = v1_deprecated(
111
+ 'Please use atom.core.parse with atom.data classes instead.')(
112
+ CreateClassFromXMLString)
113
+
114
+
115
+ def _CreateClassFromElementTree(target_class, tree, namespace=None, tag=None):
116
+ """Instantiates the class and populates members according to the tree.
117
+
118
+ Note: Only use this function with classes that have _namespace and _tag
119
+ class members.
120
+
121
+ Args:
122
+ target_class: class The class which will be instantiated and populated
123
+ with the contents of the XML.
124
+ tree: ElementTree An element tree whose contents will be converted into
125
+ members of the new target_class instance.
126
+ namespace: str (optional) The namespace which the XML tree's root node must
127
+ match. If omitted, the namespace defaults to the _namespace of the
128
+ target class.
129
+ tag: str (optional) The tag which the XML tree's root node must match. If
130
+ omitted, the tag defaults to the _tag class member of the target
131
+ class.
132
+
133
+ Returns:
134
+ An instance of the target class - or None if the tag and namespace of
135
+ the XML tree's root node did not match the desired namespace and tag.
136
+ """
137
+ if namespace is None:
138
+ namespace = target_class._namespace
139
+ if tag is None:
140
+ tag = target_class._tag
141
+ if tree.tag == '{%s}%s' % (namespace, tag):
142
+ target = target_class()
143
+ target._HarvestElementTree(tree)
144
+ return target
145
+ else:
146
+ return None
147
+
148
+
149
+ class ExtensionContainer(object):
150
+ def __init__(self, extension_elements=None, extension_attributes=None,
151
+ text=None):
152
+ self.extension_elements = extension_elements or []
153
+ self.extension_attributes = extension_attributes or {}
154
+ self.text = text
155
+
156
+ __init__ = v1_deprecated(
157
+ 'Please use data model classes in atom.data instead.')(
158
+ __init__)
159
+
160
+ # Three methods to create an object from an ElementTree
161
+ def _HarvestElementTree(self, tree):
162
+ # Fill in the instance members from the contents of the XML tree.
163
+ for child in tree:
164
+ self._ConvertElementTreeToMember(child)
165
+ for attribute, value in tree.attrib.items():
166
+ self._ConvertElementAttributeToMember(attribute, value)
167
+ # Encode the text string according to the desired encoding type. (UTF-8)
168
+ if tree.text:
169
+ if MEMBER_STRING_ENCODING is str:
170
+ self.text = tree.text
171
+ else:
172
+ self.text = tree.text.encode(MEMBER_STRING_ENCODING)
173
+
174
+ def _ConvertElementTreeToMember(self, child_tree, current_class=None):
175
+ self.extension_elements.append(_ExtensionElementFromElementTree(
176
+ child_tree))
177
+
178
+ def _ConvertElementAttributeToMember(self, attribute, value):
179
+ # Encode the attribute value's string with the desired type Default UTF-8
180
+ if value:
181
+ if MEMBER_STRING_ENCODING is str:
182
+ self.extension_attributes[attribute] = value
183
+ else:
184
+ self.extension_attributes[attribute] = value.encode(
185
+ MEMBER_STRING_ENCODING)
186
+
187
+ # One method to create an ElementTree from an object
188
+ def _AddMembersToElementTree(self, tree):
189
+ for child in self.extension_elements:
190
+ child._BecomeChildElement(tree)
191
+ for attribute, value in self.extension_attributes.items():
192
+ if value:
193
+ if isinstance(value, str) or MEMBER_STRING_ENCODING is str:
194
+ tree.attrib[attribute] = value
195
+ else:
196
+ # Decode the value from the desired encoding (default UTF-8).
197
+ tree.attrib[attribute] = value.decode(MEMBER_STRING_ENCODING)
198
+ if self.text:
199
+ if isinstance(self.text, str) or MEMBER_STRING_ENCODING is str:
200
+ tree.text = self.text
201
+ else:
202
+ tree.text = self.text.decode(MEMBER_STRING_ENCODING)
203
+
204
+ def FindExtensions(self, tag=None, namespace=None):
205
+ """Searches extension elements for child nodes with the desired name.
206
+
207
+ Returns a list of extension elements within this object whose tag
208
+ and/or namespace match those passed in. To find all extensions in
209
+ a particular namespace, specify the namespace but not the tag name.
210
+ If you specify only the tag, the result list may contain extension
211
+ elements in multiple namespaces.
212
+
213
+ Args:
214
+ tag: str (optional) The desired tag
215
+ namespace: str (optional) The desired namespace
216
+
217
+ Returns:
218
+ A list of elements whose tag and/or namespace match the parameters
219
+ values
220
+ """
221
+
222
+ results = []
223
+
224
+ if tag and namespace:
225
+ for element in self.extension_elements:
226
+ if element.tag == tag and element.namespace == namespace:
227
+ results.append(element)
228
+ elif tag and not namespace:
229
+ for element in self.extension_elements:
230
+ if element.tag == tag:
231
+ results.append(element)
232
+ elif namespace and not tag:
233
+ for element in self.extension_elements:
234
+ if element.namespace == namespace:
235
+ results.append(element)
236
+ else:
237
+ for element in self.extension_elements:
238
+ results.append(element)
239
+
240
+ return results
241
+
242
+
243
+ class AtomBase(ExtensionContainer):
244
+ _children = {}
245
+ _attributes = {}
246
+
247
+ def __init__(self, extension_elements=None, extension_attributes=None,
248
+ text=None):
249
+ self.extension_elements = extension_elements or []
250
+ self.extension_attributes = extension_attributes or {}
251
+ self.text = text
252
+
253
+ __init__ = v1_deprecated(
254
+ 'Please use data model classes in atom.data instead.')(
255
+ __init__)
256
+
257
+ def _ConvertElementTreeToMember(self, child_tree):
258
+ # Find the element's tag in this class's list of child members
259
+ if child_tree.tag in self.__class__._children:
260
+ member_name = self.__class__._children[child_tree.tag][0]
261
+ member_class = self.__class__._children[child_tree.tag][1]
262
+ # If the class member is supposed to contain a list, make sure the
263
+ # matching member is set to a list, then append the new member
264
+ # instance to the list.
265
+ if isinstance(member_class, list):
266
+ if getattr(self, member_name) is None:
267
+ setattr(self, member_name, [])
268
+ getattr(self, member_name).append(_CreateClassFromElementTree(
269
+ member_class[0], child_tree))
270
+ else:
271
+ setattr(self, member_name,
272
+ _CreateClassFromElementTree(member_class, child_tree))
273
+ else:
274
+ ExtensionContainer._ConvertElementTreeToMember(self, child_tree)
275
+
276
+ def _ConvertElementAttributeToMember(self, attribute, value):
277
+ # Find the attribute in this class's list of attributes.
278
+ if attribute in self.__class__._attributes:
279
+ # Find the member of this class which corresponds to the XML attribute
280
+ # (lookup in current_class._attributes) and set this member to the
281
+ # desired value (using self.__dict__).
282
+ if value:
283
+ # Encode the string to capture non-ascii characters (default UTF-8)
284
+ if MEMBER_STRING_ENCODING is str:
285
+ setattr(self, self.__class__._attributes[attribute], value)
286
+ else:
287
+ setattr(self, self.__class__._attributes[attribute],
288
+ value.encode(MEMBER_STRING_ENCODING))
289
+ else:
290
+ ExtensionContainer._ConvertElementAttributeToMember(
291
+ self, attribute, value)
292
+
293
+ # Three methods to create an ElementTree from an object
294
+ def _AddMembersToElementTree(self, tree):
295
+ # Convert the members of this class which are XML child nodes.
296
+ # This uses the class's _children dictionary to find the members which
297
+ # should become XML child nodes.
298
+ member_node_names = [values[0] for tag, values in
299
+ self.__class__._children.items()]
300
+ for member_name in member_node_names:
301
+ member = getattr(self, member_name)
302
+ if member is None:
303
+ pass
304
+ elif isinstance(member, list):
305
+ for instance in member:
306
+ instance._BecomeChildElement(tree)
307
+ else:
308
+ member._BecomeChildElement(tree)
309
+ # Convert the members of this class which are XML attributes.
310
+ for xml_attribute, member_name in self.__class__._attributes.items():
311
+ member = getattr(self, member_name)
312
+ if member is not None:
313
+ if isinstance(member, str) or MEMBER_STRING_ENCODING is str:
314
+ tree.attrib[xml_attribute] = member
315
+ else:
316
+ tree.attrib[xml_attribute] = member.decode(MEMBER_STRING_ENCODING)
317
+ # Lastly, call the ExtensionContainers's _AddMembersToElementTree to
318
+ # convert any extension attributes.
319
+ ExtensionContainer._AddMembersToElementTree(self, tree)
320
+
321
+ def _BecomeChildElement(self, tree):
322
+ """
323
+
324
+ Note: Only for use with classes that have a _tag and _namespace class
325
+ member. It is in AtomBase so that it can be inherited but it should
326
+ not be called on instances of AtomBase.
327
+
328
+ """
329
+ new_child = ElementTree.Element('tag__')
330
+ tree.append(new_child)
331
+ new_child.tag = '{%s}%s' % (self.__class__._namespace,
332
+ self.__class__._tag)
333
+ self._AddMembersToElementTree(new_child)
334
+
335
+ def _ToElementTree(self):
336
+ """
337
+
338
+ Note, this method is designed to be used only with classes that have a
339
+ _tag and _namespace. It is placed in AtomBase for inheritance but should
340
+ not be called on this class.
341
+
342
+ """
343
+ new_tree = ElementTree.Element('{%s}%s' % (self.__class__._namespace,
344
+ self.__class__._tag))
345
+ self._AddMembersToElementTree(new_tree)
346
+ return new_tree
347
+
348
+ def ToString(self, string_encoding=str):
349
+ """Converts the Atom object to a string containing XML."""
350
+ return ElementTree.tostring(self._ToElementTree(), encoding=string_encoding)
351
+
352
+ def __str__(self):
353
+ return self.ToString()
354
+
355
+
356
+ class Name(AtomBase):
357
+ """The atom:name element"""
358
+
359
+ _tag = 'name'
360
+ _namespace = ATOM_NAMESPACE
361
+ _children = AtomBase._children.copy()
362
+ _attributes = AtomBase._attributes.copy()
363
+
364
+ def __init__(self, text=None, extension_elements=None,
365
+ extension_attributes=None):
366
+ """Constructor for Name
367
+
368
+ Args:
369
+ text: str The text data in the this element
370
+ extension_elements: list A list of ExtensionElement instances
371
+ extension_attributes: dict A dictionary of attribute value string pairs
372
+ """
373
+
374
+ self.text = text
375
+ self.extension_elements = extension_elements or []
376
+ self.extension_attributes = extension_attributes or {}
377
+
378
+
379
+ def NameFromString(xml_string):
380
+ return CreateClassFromXMLString(Name, xml_string)
381
+
382
+
383
+ class Email(AtomBase):
384
+ """The atom:email element"""
385
+
386
+ _tag = 'email'
387
+ _namespace = ATOM_NAMESPACE
388
+ _children = AtomBase._children.copy()
389
+ _attributes = AtomBase._attributes.copy()
390
+
391
+ def __init__(self, text=None, extension_elements=None,
392
+ extension_attributes=None):
393
+ """Constructor for Email
394
+
395
+ Args:
396
+ extension_elements: list A list of ExtensionElement instances
397
+ extension_attributes: dict A dictionary of attribute value string pairs
398
+ text: str The text data in the this element
399
+ """
400
+
401
+ self.text = text
402
+ self.extension_elements = extension_elements or []
403
+ self.extension_attributes = extension_attributes or {}
404
+
405
+
406
+ def EmailFromString(xml_string):
407
+ return CreateClassFromXMLString(Email, xml_string)
408
+
409
+
410
+ class Uri(AtomBase):
411
+ """The atom:uri element"""
412
+
413
+ _tag = 'uri'
414
+ _namespace = ATOM_NAMESPACE
415
+ _children = AtomBase._children.copy()
416
+ _attributes = AtomBase._attributes.copy()
417
+
418
+ def __init__(self, text=None, extension_elements=None,
419
+ extension_attributes=None):
420
+ """Constructor for Uri
421
+
422
+ Args:
423
+ extension_elements: list A list of ExtensionElement instances
424
+ extension_attributes: dict A dictionary of attribute value string pairs
425
+ text: str The text data in the this element
426
+ """
427
+
428
+ self.text = text
429
+ self.extension_elements = extension_elements or []
430
+ self.extension_attributes = extension_attributes or {}
431
+
432
+
433
+ def UriFromString(xml_string):
434
+ return CreateClassFromXMLString(Uri, xml_string)
435
+
436
+
437
+ class Person(AtomBase):
438
+ """A foundation class from which atom:author and atom:contributor extend.
439
+
440
+ A person contains information like name, email address, and web page URI for
441
+ an author or contributor to an Atom feed.
442
+ """
443
+
444
+ _children = AtomBase._children.copy()
445
+ _attributes = AtomBase._attributes.copy()
446
+ _children['{%s}name' % (ATOM_NAMESPACE)] = ('name', Name)
447
+ _children['{%s}email' % (ATOM_NAMESPACE)] = ('email', Email)
448
+ _children['{%s}uri' % (ATOM_NAMESPACE)] = ('uri', Uri)
449
+
450
+ def __init__(self, name=None, email=None, uri=None,
451
+ extension_elements=None, extension_attributes=None, text=None):
452
+ """Foundation from which author and contributor are derived.
453
+
454
+ The constructor is provided for illustrative purposes, you should not
455
+ need to instantiate a Person.
456
+
457
+ Args:
458
+ name: Name The person's name
459
+ email: Email The person's email address
460
+ uri: Uri The URI of the person's webpage
461
+ extension_elements: list A list of ExtensionElement instances which are
462
+ children of this element.
463
+ extension_attributes: dict A dictionary of strings which are the values
464
+ for additional XML attributes of this element.
465
+ text: String The text contents of the element. This is the contents
466
+ of the Entry's XML text node. (Example: <foo>This is the text</foo>)
467
+ """
468
+
469
+ self.name = name
470
+ self.email = email
471
+ self.uri = uri
472
+ self.extension_elements = extension_elements or []
473
+ self.extension_attributes = extension_attributes or {}
474
+ self.text = text
475
+
476
+
477
+ class Author(Person):
478
+ """The atom:author element
479
+
480
+ An author is a required element in Feed.
481
+ """
482
+
483
+ _tag = 'author'
484
+ _namespace = ATOM_NAMESPACE
485
+ _children = Person._children.copy()
486
+ _attributes = Person._attributes.copy()
487
+
488
+ # _children = {}
489
+ # _attributes = {}
490
+
491
+ def __init__(self, name=None, email=None, uri=None,
492
+ extension_elements=None, extension_attributes=None, text=None):
493
+ """Constructor for Author
494
+
495
+ Args:
496
+ name: Name
497
+ email: Email
498
+ uri: Uri
499
+ extension_elements: list A list of ExtensionElement instances
500
+ extension_attributes: dict A dictionary of attribute value string pairs
501
+ text: str The text data in the this element
502
+ """
503
+
504
+ self.name = name
505
+ self.email = email
506
+ self.uri = uri
507
+ self.extension_elements = extension_elements or []
508
+ self.extension_attributes = extension_attributes or {}
509
+ self.text = text
510
+
511
+
512
+ def AuthorFromString(xml_string):
513
+ return CreateClassFromXMLString(Author, xml_string)
514
+
515
+
516
+ class Contributor(Person):
517
+ """The atom:contributor element"""
518
+
519
+ _tag = 'contributor'
520
+ _namespace = ATOM_NAMESPACE
521
+ _children = Person._children.copy()
522
+ _attributes = Person._attributes.copy()
523
+
524
+ def __init__(self, name=None, email=None, uri=None,
525
+ extension_elements=None, extension_attributes=None, text=None):
526
+ """Constructor for Contributor
527
+
528
+ Args:
529
+ name: Name
530
+ email: Email
531
+ uri: Uri
532
+ extension_elements: list A list of ExtensionElement instances
533
+ extension_attributes: dict A dictionary of attribute value string pairs
534
+ text: str The text data in the this element
535
+ """
536
+
537
+ self.name = name
538
+ self.email = email
539
+ self.uri = uri
540
+ self.extension_elements = extension_elements or []
541
+ self.extension_attributes = extension_attributes or {}
542
+ self.text = text
543
+
544
+
545
+ def ContributorFromString(xml_string):
546
+ return CreateClassFromXMLString(Contributor, xml_string)
547
+
548
+
549
+ class Link(AtomBase):
550
+ """The atom:link element"""
551
+
552
+ _tag = 'link'
553
+ _namespace = ATOM_NAMESPACE
554
+ _children = AtomBase._children.copy()
555
+ _attributes = AtomBase._attributes.copy()
556
+ _attributes['rel'] = 'rel'
557
+ _attributes['href'] = 'href'
558
+ _attributes['type'] = 'type'
559
+ _attributes['title'] = 'title'
560
+ _attributes['length'] = 'length'
561
+ _attributes['hreflang'] = 'hreflang'
562
+
563
+ def __init__(self, href=None, rel=None, link_type=None, hreflang=None,
564
+ title=None, length=None, text=None, extension_elements=None,
565
+ extension_attributes=None):
566
+ """Constructor for Link
567
+
568
+ Args:
569
+ href: string The href attribute of the link
570
+ rel: string
571
+ type: string
572
+ hreflang: string The language for the href
573
+ title: string
574
+ length: string The length of the href's destination
575
+ extension_elements: list A list of ExtensionElement instances
576
+ extension_attributes: dict A dictionary of attribute value string pairs
577
+ text: str The text data in the this element
578
+ """
579
+
580
+ self.href = href
581
+ self.rel = rel
582
+ self.type = link_type
583
+ self.hreflang = hreflang
584
+ self.title = title
585
+ self.length = length
586
+ self.text = text
587
+ self.extension_elements = extension_elements or []
588
+ self.extension_attributes = extension_attributes or {}
589
+
590
+
591
+ def LinkFromString(xml_string):
592
+ return CreateClassFromXMLString(Link, xml_string)
593
+
594
+
595
+ class Generator(AtomBase):
596
+ """The atom:generator element"""
597
+
598
+ _tag = 'generator'
599
+ _namespace = ATOM_NAMESPACE
600
+ _children = AtomBase._children.copy()
601
+ _attributes = AtomBase._attributes.copy()
602
+ _attributes['uri'] = 'uri'
603
+ _attributes['version'] = 'version'
604
+
605
+ def __init__(self, uri=None, version=None, text=None,
606
+ extension_elements=None, extension_attributes=None):
607
+ """Constructor for Generator
608
+
609
+ Args:
610
+ uri: string
611
+ version: string
612
+ text: str The text data in the this element
613
+ extension_elements: list A list of ExtensionElement instances
614
+ extension_attributes: dict A dictionary of attribute value string pairs
615
+ """
616
+
617
+ self.uri = uri
618
+ self.version = version
619
+ self.text = text
620
+ self.extension_elements = extension_elements or []
621
+ self.extension_attributes = extension_attributes or {}
622
+
623
+
624
+ def GeneratorFromString(xml_string):
625
+ return CreateClassFromXMLString(Generator, xml_string)
626
+
627
+
628
+ class Text(AtomBase):
629
+ """A foundation class from which atom:title, summary, etc. extend.
630
+
631
+ This class should never be instantiated.
632
+ """
633
+
634
+ _children = AtomBase._children.copy()
635
+ _attributes = AtomBase._attributes.copy()
636
+ _attributes['type'] = 'type'
637
+
638
+ def __init__(self, text_type=None, text=None, extension_elements=None,
639
+ extension_attributes=None):
640
+ """Constructor for Text
641
+
642
+ Args:
643
+ text_type: string
644
+ text: str The text data in the this element
645
+ extension_elements: list A list of ExtensionElement instances
646
+ extension_attributes: dict A dictionary of attribute value string pairs
647
+ """
648
+
649
+ self.type = text_type
650
+ self.text = text
651
+ self.extension_elements = extension_elements or []
652
+ self.extension_attributes = extension_attributes or {}
653
+
654
+
655
+ class Title(Text):
656
+ """The atom:title element"""
657
+
658
+ _tag = 'title'
659
+ _namespace = ATOM_NAMESPACE
660
+ _children = Text._children.copy()
661
+ _attributes = Text._attributes.copy()
662
+
663
+ def __init__(self, title_type=None, text=None, extension_elements=None,
664
+ extension_attributes=None):
665
+ """Constructor for Title
666
+
667
+ Args:
668
+ title_type: string
669
+ text: str The text data in the this element
670
+ extension_elements: list A list of ExtensionElement instances
671
+ extension_attributes: dict A dictionary of attribute value string pairs
672
+ """
673
+
674
+ self.type = title_type
675
+ self.text = text
676
+ self.extension_elements = extension_elements or []
677
+ self.extension_attributes = extension_attributes or {}
678
+
679
+
680
+ def TitleFromString(xml_string):
681
+ return CreateClassFromXMLString(Title, xml_string)
682
+
683
+
684
+ class Subtitle(Text):
685
+ """The atom:subtitle element"""
686
+
687
+ _tag = 'subtitle'
688
+ _namespace = ATOM_NAMESPACE
689
+ _children = Text._children.copy()
690
+ _attributes = Text._attributes.copy()
691
+
692
+ def __init__(self, subtitle_type=None, text=None, extension_elements=None,
693
+ extension_attributes=None):
694
+ """Constructor for Subtitle
695
+
696
+ Args:
697
+ subtitle_type: string
698
+ text: str The text data in the this element
699
+ extension_elements: list A list of ExtensionElement instances
700
+ extension_attributes: dict A dictionary of attribute value string pairs
701
+ """
702
+
703
+ self.type = subtitle_type
704
+ self.text = text
705
+ self.extension_elements = extension_elements or []
706
+ self.extension_attributes = extension_attributes or {}
707
+
708
+
709
+ def SubtitleFromString(xml_string):
710
+ return CreateClassFromXMLString(Subtitle, xml_string)
711
+
712
+
713
+ class Rights(Text):
714
+ """The atom:rights element"""
715
+
716
+ _tag = 'rights'
717
+ _namespace = ATOM_NAMESPACE
718
+ _children = Text._children.copy()
719
+ _attributes = Text._attributes.copy()
720
+
721
+ def __init__(self, rights_type=None, text=None, extension_elements=None,
722
+ extension_attributes=None):
723
+ """Constructor for Rights
724
+
725
+ Args:
726
+ rights_type: string
727
+ text: str The text data in the this element
728
+ extension_elements: list A list of ExtensionElement instances
729
+ extension_attributes: dict A dictionary of attribute value string pairs
730
+ """
731
+
732
+ self.type = rights_type
733
+ self.text = text
734
+ self.extension_elements = extension_elements or []
735
+ self.extension_attributes = extension_attributes or {}
736
+
737
+
738
+ def RightsFromString(xml_string):
739
+ return CreateClassFromXMLString(Rights, xml_string)
740
+
741
+
742
+ class Summary(Text):
743
+ """The atom:summary element"""
744
+
745
+ _tag = 'summary'
746
+ _namespace = ATOM_NAMESPACE
747
+ _children = Text._children.copy()
748
+ _attributes = Text._attributes.copy()
749
+
750
+ def __init__(self, summary_type=None, text=None, extension_elements=None,
751
+ extension_attributes=None):
752
+ """Constructor for Summary
753
+
754
+ Args:
755
+ summary_type: string
756
+ text: str The text data in the this element
757
+ extension_elements: list A list of ExtensionElement instances
758
+ extension_attributes: dict A dictionary of attribute value string pairs
759
+ """
760
+
761
+ self.type = summary_type
762
+ self.text = text
763
+ self.extension_elements = extension_elements or []
764
+ self.extension_attributes = extension_attributes or {}
765
+
766
+
767
+ def SummaryFromString(xml_string):
768
+ return CreateClassFromXMLString(Summary, xml_string)
769
+
770
+
771
+ class Content(Text):
772
+ """The atom:content element"""
773
+
774
+ _tag = 'content'
775
+ _namespace = ATOM_NAMESPACE
776
+ _children = Text._children.copy()
777
+ _attributes = Text._attributes.copy()
778
+ _attributes['src'] = 'src'
779
+
780
+ def __init__(self, content_type=None, src=None, text=None,
781
+ extension_elements=None, extension_attributes=None):
782
+ """Constructor for Content
783
+
784
+ Args:
785
+ content_type: string
786
+ src: string
787
+ text: str The text data in the this element
788
+ extension_elements: list A list of ExtensionElement instances
789
+ extension_attributes: dict A dictionary of attribute value string pairs
790
+ """
791
+
792
+ self.type = content_type
793
+ self.src = src
794
+ self.text = text
795
+ self.extension_elements = extension_elements or []
796
+ self.extension_attributes = extension_attributes or {}
797
+
798
+
799
+ def ContentFromString(xml_string):
800
+ return CreateClassFromXMLString(Content, xml_string)
801
+
802
+
803
+ class Category(AtomBase):
804
+ """The atom:category element"""
805
+
806
+ _tag = 'category'
807
+ _namespace = ATOM_NAMESPACE
808
+ _children = AtomBase._children.copy()
809
+ _attributes = AtomBase._attributes.copy()
810
+ _attributes['term'] = 'term'
811
+ _attributes['scheme'] = 'scheme'
812
+ _attributes['label'] = 'label'
813
+
814
+ def __init__(self, term=None, scheme=None, label=None, text=None,
815
+ extension_elements=None, extension_attributes=None):
816
+ """Constructor for Category
817
+
818
+ Args:
819
+ term: str
820
+ scheme: str
821
+ label: str
822
+ text: str The text data in the this element
823
+ extension_elements: list A list of ExtensionElement instances
824
+ extension_attributes: dict A dictionary of attribute value string pairs
825
+ """
826
+
827
+ self.term = term
828
+ self.scheme = scheme
829
+ self.label = label
830
+ self.text = text
831
+ self.extension_elements = extension_elements or []
832
+ self.extension_attributes = extension_attributes or {}
833
+
834
+
835
+ def CategoryFromString(xml_string):
836
+ return CreateClassFromXMLString(Category, xml_string)
837
+
838
+
839
+ class Id(AtomBase):
840
+ """The atom:id element."""
841
+
842
+ _tag = 'id'
843
+ _namespace = ATOM_NAMESPACE
844
+ _children = AtomBase._children.copy()
845
+ _attributes = AtomBase._attributes.copy()
846
+
847
+ def __init__(self, text=None, extension_elements=None,
848
+ extension_attributes=None):
849
+ """Constructor for Id
850
+
851
+ Args:
852
+ text: str The text data in the this element
853
+ extension_elements: list A list of ExtensionElement instances
854
+ extension_attributes: dict A dictionary of attribute value string pairs
855
+ """
856
+
857
+ self.text = text
858
+ self.extension_elements = extension_elements or []
859
+ self.extension_attributes = extension_attributes or {}
860
+
861
+
862
+ def IdFromString(xml_string):
863
+ return CreateClassFromXMLString(Id, xml_string)
864
+
865
+
866
+ class Icon(AtomBase):
867
+ """The atom:icon element."""
868
+
869
+ _tag = 'icon'
870
+ _namespace = ATOM_NAMESPACE
871
+ _children = AtomBase._children.copy()
872
+ _attributes = AtomBase._attributes.copy()
873
+
874
+ def __init__(self, text=None, extension_elements=None,
875
+ extension_attributes=None):
876
+ """Constructor for Icon
877
+
878
+ Args:
879
+ text: str The text data in the this element
880
+ extension_elements: list A list of ExtensionElement instances
881
+ extension_attributes: dict A dictionary of attribute value string pairs
882
+ """
883
+
884
+ self.text = text
885
+ self.extension_elements = extension_elements or []
886
+ self.extension_attributes = extension_attributes or {}
887
+
888
+
889
+ def IconFromString(xml_string):
890
+ return CreateClassFromXMLString(Icon, xml_string)
891
+
892
+
893
+ class Logo(AtomBase):
894
+ """The atom:logo element."""
895
+
896
+ _tag = 'logo'
897
+ _namespace = ATOM_NAMESPACE
898
+ _children = AtomBase._children.copy()
899
+ _attributes = AtomBase._attributes.copy()
900
+
901
+ def __init__(self, text=None, extension_elements=None,
902
+ extension_attributes=None):
903
+ """Constructor for Logo
904
+
905
+ Args:
906
+ text: str The text data in the this element
907
+ extension_elements: list A list of ExtensionElement instances
908
+ extension_attributes: dict A dictionary of attribute value string pairs
909
+ """
910
+
911
+ self.text = text
912
+ self.extension_elements = extension_elements or []
913
+ self.extension_attributes = extension_attributes or {}
914
+
915
+
916
+ def LogoFromString(xml_string):
917
+ return CreateClassFromXMLString(Logo, xml_string)
918
+
919
+
920
+ class Draft(AtomBase):
921
+ """The app:draft element which indicates if this entry should be public."""
922
+
923
+ _tag = 'draft'
924
+ _namespace = APP_NAMESPACE
925
+ _children = AtomBase._children.copy()
926
+ _attributes = AtomBase._attributes.copy()
927
+
928
+ def __init__(self, text=None, extension_elements=None,
929
+ extension_attributes=None):
930
+ """Constructor for app:draft
931
+
932
+ Args:
933
+ text: str The text data in the this element
934
+ extension_elements: list A list of ExtensionElement instances
935
+ extension_attributes: dict A dictionary of attribute value string pairs
936
+ """
937
+
938
+ self.text = text
939
+ self.extension_elements = extension_elements or []
940
+ self.extension_attributes = extension_attributes or {}
941
+
942
+
943
+ def DraftFromString(xml_string):
944
+ return CreateClassFromXMLString(Draft, xml_string)
945
+
946
+
947
+ class Control(AtomBase):
948
+ """The app:control element indicating restrictions on publication.
949
+
950
+ The APP control element may contain a draft element indicating whether or
951
+ not this entry should be publicly available.
952
+ """
953
+
954
+ _tag = 'control'
955
+ _namespace = APP_NAMESPACE
956
+ _children = AtomBase._children.copy()
957
+ _attributes = AtomBase._attributes.copy()
958
+ _children['{%s}draft' % APP_NAMESPACE] = ('draft', Draft)
959
+
960
+ def __init__(self, draft=None, text=None, extension_elements=None,
961
+ extension_attributes=None):
962
+ """Constructor for app:control"""
963
+
964
+ self.draft = draft
965
+ self.text = text
966
+ self.extension_elements = extension_elements or []
967
+ self.extension_attributes = extension_attributes or {}
968
+
969
+
970
+ def ControlFromString(xml_string):
971
+ return CreateClassFromXMLString(Control, xml_string)
972
+
973
+
974
+ class Date(AtomBase):
975
+ """A parent class for atom:updated, published, etc."""
976
+
977
+ # TODO Add text to and from time conversion methods to allow users to set
978
+ # the contents of a Date to a python DateTime object.
979
+
980
+ _children = AtomBase._children.copy()
981
+ _attributes = AtomBase._attributes.copy()
982
+
983
+ def __init__(self, text=None, extension_elements=None,
984
+ extension_attributes=None):
985
+ self.text = text
986
+ self.extension_elements = extension_elements or []
987
+ self.extension_attributes = extension_attributes or {}
988
+
989
+
990
+ class Updated(Date):
991
+ """The atom:updated element."""
992
+
993
+ _tag = 'updated'
994
+ _namespace = ATOM_NAMESPACE
995
+ _children = Date._children.copy()
996
+ _attributes = Date._attributes.copy()
997
+
998
+ def __init__(self, text=None, extension_elements=None,
999
+ extension_attributes=None):
1000
+ """Constructor for Updated
1001
+
1002
+ Args:
1003
+ text: str The text data in the this element
1004
+ extension_elements: list A list of ExtensionElement instances
1005
+ extension_attributes: dict A dictionary of attribute value string pairs
1006
+ """
1007
+
1008
+ self.text = text
1009
+ self.extension_elements = extension_elements or []
1010
+ self.extension_attributes = extension_attributes or {}
1011
+
1012
+
1013
+ def UpdatedFromString(xml_string):
1014
+ return CreateClassFromXMLString(Updated, xml_string)
1015
+
1016
+
1017
+ class Published(Date):
1018
+ """The atom:published element."""
1019
+
1020
+ _tag = 'published'
1021
+ _namespace = ATOM_NAMESPACE
1022
+ _children = Date._children.copy()
1023
+ _attributes = Date._attributes.copy()
1024
+
1025
+ def __init__(self, text=None, extension_elements=None,
1026
+ extension_attributes=None):
1027
+ """Constructor for Published
1028
+
1029
+ Args:
1030
+ text: str The text data in the this element
1031
+ extension_elements: list A list of ExtensionElement instances
1032
+ extension_attributes: dict A dictionary of attribute value string pairs
1033
+ """
1034
+
1035
+ self.text = text
1036
+ self.extension_elements = extension_elements or []
1037
+ self.extension_attributes = extension_attributes or {}
1038
+
1039
+
1040
+ def PublishedFromString(xml_string):
1041
+ return CreateClassFromXMLString(Published, xml_string)
1042
+
1043
+
1044
+ class LinkFinder(object):
1045
+ """An "interface" providing methods to find link elements
1046
+
1047
+ Entry elements often contain multiple links which differ in the rel
1048
+ attribute or content type. Often, developers are interested in a specific
1049
+ type of link so this class provides methods to find specific classes of
1050
+ links.
1051
+
1052
+ This class is used as a mixin in Atom entries and feeds.
1053
+ """
1054
+
1055
+ def GetSelfLink(self):
1056
+ """Find the first link with rel set to 'self'
1057
+
1058
+ Returns:
1059
+ An atom.Link or none if none of the links had rel equal to 'self'
1060
+ """
1061
+
1062
+ for a_link in self.link:
1063
+ if a_link.rel == 'self':
1064
+ return a_link
1065
+ return None
1066
+
1067
+ def GetEditLink(self):
1068
+ for a_link in self.link:
1069
+ if a_link.rel == 'edit':
1070
+ return a_link
1071
+ return None
1072
+
1073
+ def GetEditMediaLink(self):
1074
+ for a_link in self.link:
1075
+ if a_link.rel == 'edit-media':
1076
+ return a_link
1077
+ return None
1078
+
1079
+ def GetNextLink(self):
1080
+ for a_link in self.link:
1081
+ if a_link.rel == 'next':
1082
+ return a_link
1083
+ return None
1084
+
1085
+ def GetLicenseLink(self):
1086
+ for a_link in self.link:
1087
+ if a_link.rel == 'license':
1088
+ return a_link
1089
+ return None
1090
+
1091
+ def GetAlternateLink(self):
1092
+ for a_link in self.link:
1093
+ if a_link.rel == 'alternate':
1094
+ return a_link
1095
+ return None
1096
+
1097
+
1098
+ class FeedEntryParent(AtomBase, LinkFinder):
1099
+ """A super class for atom:feed and entry, contains shared attributes"""
1100
+
1101
+ _children = AtomBase._children.copy()
1102
+ _attributes = AtomBase._attributes.copy()
1103
+ _children['{%s}author' % ATOM_NAMESPACE] = ('author', [Author])
1104
+ _children['{%s}category' % ATOM_NAMESPACE] = ('category', [Category])
1105
+ _children['{%s}contributor' % ATOM_NAMESPACE] = ('contributor', [Contributor])
1106
+ _children['{%s}id' % ATOM_NAMESPACE] = ('id', Id)
1107
+ _children['{%s}link' % ATOM_NAMESPACE] = ('link', [Link])
1108
+ _children['{%s}rights' % ATOM_NAMESPACE] = ('rights', Rights)
1109
+ _children['{%s}title' % ATOM_NAMESPACE] = ('title', Title)
1110
+ _children['{%s}updated' % ATOM_NAMESPACE] = ('updated', Updated)
1111
+
1112
+ def __init__(self, author=None, category=None, contributor=None,
1113
+ atom_id=None, link=None, rights=None, title=None, updated=None,
1114
+ text=None, extension_elements=None, extension_attributes=None):
1115
+ self.author = author or []
1116
+ self.category = category or []
1117
+ self.contributor = contributor or []
1118
+ self.id = atom_id
1119
+ self.link = link or []
1120
+ self.rights = rights
1121
+ self.title = title
1122
+ self.updated = updated
1123
+ self.text = text
1124
+ self.extension_elements = extension_elements or []
1125
+ self.extension_attributes = extension_attributes or {}
1126
+
1127
+
1128
+ class Source(FeedEntryParent):
1129
+ """The atom:source element"""
1130
+
1131
+ _tag = 'source'
1132
+ _namespace = ATOM_NAMESPACE
1133
+ _children = FeedEntryParent._children.copy()
1134
+ _attributes = FeedEntryParent._attributes.copy()
1135
+ _children['{%s}generator' % ATOM_NAMESPACE] = ('generator', Generator)
1136
+ _children['{%s}icon' % ATOM_NAMESPACE] = ('icon', Icon)
1137
+ _children['{%s}logo' % ATOM_NAMESPACE] = ('logo', Logo)
1138
+ _children['{%s}subtitle' % ATOM_NAMESPACE] = ('subtitle', Subtitle)
1139
+
1140
+ def __init__(self, author=None, category=None, contributor=None,
1141
+ generator=None, icon=None, atom_id=None, link=None, logo=None,
1142
+ rights=None, subtitle=None, title=None, updated=None, text=None,
1143
+ extension_elements=None, extension_attributes=None):
1144
+ """Constructor for Source
1145
+
1146
+ Args:
1147
+ author: list (optional) A list of Author instances which belong to this
1148
+ class.
1149
+ category: list (optional) A list of Category instances
1150
+ contributor: list (optional) A list on Contributor instances
1151
+ generator: Generator (optional)
1152
+ icon: Icon (optional)
1153
+ id: Id (optional) The entry's Id element
1154
+ link: list (optional) A list of Link instances
1155
+ logo: Logo (optional)
1156
+ rights: Rights (optional) The entry's Rights element
1157
+ subtitle: Subtitle (optional) The entry's subtitle element
1158
+ title: Title (optional) the entry's title element
1159
+ updated: Updated (optional) the entry's updated element
1160
+ text: String (optional) The text contents of the element. This is the
1161
+ contents of the Entry's XML text node.
1162
+ (Example: <foo>This is the text</foo>)
1163
+ extension_elements: list (optional) A list of ExtensionElement instances
1164
+ which are children of this element.
1165
+ extension_attributes: dict (optional) A dictionary of strings which are
1166
+ the values for additional XML attributes of this element.
1167
+ """
1168
+
1169
+ self.author = author or []
1170
+ self.category = category or []
1171
+ self.contributor = contributor or []
1172
+ self.generator = generator
1173
+ self.icon = icon
1174
+ self.id = atom_id
1175
+ self.link = link or []
1176
+ self.logo = logo
1177
+ self.rights = rights
1178
+ self.subtitle = subtitle
1179
+ self.title = title
1180
+ self.updated = updated
1181
+ self.text = text
1182
+ self.extension_elements = extension_elements or []
1183
+ self.extension_attributes = extension_attributes or {}
1184
+
1185
+
1186
+ def SourceFromString(xml_string):
1187
+ return CreateClassFromXMLString(Source, xml_string)
1188
+
1189
+
1190
+ class Entry(FeedEntryParent):
1191
+ """The atom:entry element"""
1192
+
1193
+ _tag = 'entry'
1194
+ _namespace = ATOM_NAMESPACE
1195
+ _children = FeedEntryParent._children.copy()
1196
+ _attributes = FeedEntryParent._attributes.copy()
1197
+ _children['{%s}content' % ATOM_NAMESPACE] = ('content', Content)
1198
+ _children['{%s}published' % ATOM_NAMESPACE] = ('published', Published)
1199
+ _children['{%s}source' % ATOM_NAMESPACE] = ('source', Source)
1200
+ _children['{%s}summary' % ATOM_NAMESPACE] = ('summary', Summary)
1201
+ _children['{%s}control' % APP_NAMESPACE] = ('control', Control)
1202
+
1203
+ def __init__(self, author=None, category=None, content=None,
1204
+ contributor=None, atom_id=None, link=None, published=None, rights=None,
1205
+ source=None, summary=None, control=None, title=None, updated=None,
1206
+ extension_elements=None, extension_attributes=None, text=None):
1207
+ """Constructor for atom:entry
1208
+
1209
+ Args:
1210
+ author: list A list of Author instances which belong to this class.
1211
+ category: list A list of Category instances
1212
+ content: Content The entry's Content
1213
+ contributor: list A list on Contributor instances
1214
+ id: Id The entry's Id element
1215
+ link: list A list of Link instances
1216
+ published: Published The entry's Published element
1217
+ rights: Rights The entry's Rights element
1218
+ source: Source the entry's source element
1219
+ summary: Summary the entry's summary element
1220
+ title: Title the entry's title element
1221
+ updated: Updated the entry's updated element
1222
+ control: The entry's app:control element which can be used to mark an
1223
+ entry as a draft which should not be publicly viewable.
1224
+ text: String The text contents of the element. This is the contents
1225
+ of the Entry's XML text node. (Example: <foo>This is the text</foo>)
1226
+ extension_elements: list A list of ExtensionElement instances which are
1227
+ children of this element.
1228
+ extension_attributes: dict A dictionary of strings which are the values
1229
+ for additional XML attributes of this element.
1230
+ """
1231
+
1232
+ self.author = author or []
1233
+ self.category = category or []
1234
+ self.content = content
1235
+ self.contributor = contributor or []
1236
+ self.id = atom_id
1237
+ self.link = link or []
1238
+ self.published = published
1239
+ self.rights = rights
1240
+ self.source = source
1241
+ self.summary = summary
1242
+ self.title = title
1243
+ self.updated = updated
1244
+ self.control = control
1245
+ self.text = text
1246
+ self.extension_elements = extension_elements or []
1247
+ self.extension_attributes = extension_attributes or {}
1248
+
1249
+ __init__ = v1_deprecated('Please use atom.data.Entry instead.')(__init__)
1250
+
1251
+
1252
+ def EntryFromString(xml_string):
1253
+ return CreateClassFromXMLString(Entry, xml_string)
1254
+
1255
+
1256
+ class Feed(Source):
1257
+ """The atom:feed element"""
1258
+
1259
+ _tag = 'feed'
1260
+ _namespace = ATOM_NAMESPACE
1261
+ _children = Source._children.copy()
1262
+ _attributes = Source._attributes.copy()
1263
+ _children['{%s}entry' % ATOM_NAMESPACE] = ('entry', [Entry])
1264
+
1265
+ def __init__(self, author=None, category=None, contributor=None,
1266
+ generator=None, icon=None, atom_id=None, link=None, logo=None,
1267
+ rights=None, subtitle=None, title=None, updated=None, entry=None,
1268
+ text=None, extension_elements=None, extension_attributes=None):
1269
+ """Constructor for Source
1270
+
1271
+ Args:
1272
+ author: list (optional) A list of Author instances which belong to this
1273
+ class.
1274
+ category: list (optional) A list of Category instances
1275
+ contributor: list (optional) A list on Contributor instances
1276
+ generator: Generator (optional)
1277
+ icon: Icon (optional)
1278
+ id: Id (optional) The entry's Id element
1279
+ link: list (optional) A list of Link instances
1280
+ logo: Logo (optional)
1281
+ rights: Rights (optional) The entry's Rights element
1282
+ subtitle: Subtitle (optional) The entry's subtitle element
1283
+ title: Title (optional) the entry's title element
1284
+ updated: Updated (optional) the entry's updated element
1285
+ entry: list (optional) A list of the Entry instances contained in the
1286
+ feed.
1287
+ text: String (optional) The text contents of the element. This is the
1288
+ contents of the Entry's XML text node.
1289
+ (Example: <foo>This is the text</foo>)
1290
+ extension_elements: list (optional) A list of ExtensionElement instances
1291
+ which are children of this element.
1292
+ extension_attributes: dict (optional) A dictionary of strings which are
1293
+ the values for additional XML attributes of this element.
1294
+ """
1295
+
1296
+ self.author = author or []
1297
+ self.category = category or []
1298
+ self.contributor = contributor or []
1299
+ self.generator = generator
1300
+ self.icon = icon
1301
+ self.id = atom_id
1302
+ self.link = link or []
1303
+ self.logo = logo
1304
+ self.rights = rights
1305
+ self.subtitle = subtitle
1306
+ self.title = title
1307
+ self.updated = updated
1308
+ self.entry = entry or []
1309
+ self.text = text
1310
+ self.extension_elements = extension_elements or []
1311
+ self.extension_attributes = extension_attributes or {}
1312
+
1313
+ __init__ = v1_deprecated('Please use atom.data.Feed instead.')(__init__)
1314
+
1315
+
1316
+ def FeedFromString(xml_string):
1317
+ return CreateClassFromXMLString(Feed, xml_string)
1318
+
1319
+
1320
+ class ExtensionElement(object):
1321
+ """Represents extra XML elements contained in Atom classes."""
1322
+
1323
+ def __init__(self, tag, namespace=None, attributes=None,
1324
+ children=None, text=None):
1325
+ """Constructor for EtensionElement
1326
+
1327
+ Args:
1328
+ namespace: string (optional) The XML namespace for this element.
1329
+ tag: string (optional) The tag (without the namespace qualifier) for
1330
+ this element. To reconstruct the full qualified name of the element,
1331
+ combine this tag with the namespace.
1332
+ attributes: dict (optinal) The attribute value string pairs for the XML
1333
+ attributes of this element.
1334
+ children: list (optional) A list of ExtensionElements which represent
1335
+ the XML child nodes of this element.
1336
+ """
1337
+
1338
+ self.namespace = namespace
1339
+ self.tag = tag
1340
+ self.attributes = attributes or {}
1341
+ self.children = children or []
1342
+ self.text = text
1343
+
1344
+ def ToString(self):
1345
+ element_tree = self._TransferToElementTree(ElementTree.Element('tag__'))
1346
+ return ElementTree.tostring(element_tree, encoding="UTF-8")
1347
+
1348
+ def _TransferToElementTree(self, element_tree):
1349
+ if self.tag is None:
1350
+ return None
1351
+
1352
+ if self.namespace is not None:
1353
+ element_tree.tag = '{%s}%s' % (self.namespace, self.tag)
1354
+ else:
1355
+ element_tree.tag = self.tag
1356
+
1357
+ for key, value in self.attributes.items():
1358
+ element_tree.attrib[key] = value
1359
+
1360
+ for child in self.children:
1361
+ child._BecomeChildElement(element_tree)
1362
+
1363
+ element_tree.text = self.text
1364
+
1365
+ return element_tree
1366
+
1367
+ def _BecomeChildElement(self, element_tree):
1368
+ """Converts this object into an etree element and adds it as a child node.
1369
+
1370
+ Adds self to the ElementTree. This method is required to avoid verbose XML
1371
+ which constantly redefines the namespace.
1372
+
1373
+ Args:
1374
+ element_tree: ElementTree._Element The element to which this object's XML
1375
+ will be added.
1376
+ """
1377
+ new_element = ElementTree.Element('tag__') # uh, uhm... empty tag name - sorry google, this is bogus? (c)https://github.com/lqc
1378
+ element_tree.append(new_element)
1379
+ self._TransferToElementTree(new_element)
1380
+
1381
+ def FindChildren(self, tag=None, namespace=None):
1382
+ """Searches child nodes for objects with the desired tag/namespace.
1383
+
1384
+ Returns a list of extension elements within this object whose tag
1385
+ and/or namespace match those passed in. To find all children in
1386
+ a particular namespace, specify the namespace but not the tag name.
1387
+ If you specify only the tag, the result list may contain extension
1388
+ elements in multiple namespaces.
1389
+
1390
+ Args:
1391
+ tag: str (optional) The desired tag
1392
+ namespace: str (optional) The desired namespace
1393
+
1394
+ Returns:
1395
+ A list of elements whose tag and/or namespace match the parameters
1396
+ values
1397
+ """
1398
+
1399
+ results = []
1400
+
1401
+ if tag and namespace:
1402
+ for element in self.children:
1403
+ if element.tag == tag and element.namespace == namespace:
1404
+ results.append(element)
1405
+ elif tag and not namespace:
1406
+ for element in self.children:
1407
+ if element.tag == tag:
1408
+ results.append(element)
1409
+ elif namespace and not tag:
1410
+ for element in self.children:
1411
+ if element.namespace == namespace:
1412
+ results.append(element)
1413
+ else:
1414
+ for element in self.children:
1415
+ results.append(element)
1416
+
1417
+ return results
1418
+
1419
+
1420
+ def ExtensionElementFromString(xml_string):
1421
+ element_tree = ElementTree.fromstring(xml_string)
1422
+ return _ExtensionElementFromElementTree(element_tree)
1423
+
1424
+
1425
+ def _ExtensionElementFromElementTree(element_tree):
1426
+ element_tag = element_tree.tag
1427
+ if '}' in element_tag:
1428
+ namespace = element_tag[1:element_tag.index('}')]
1429
+ tag = element_tag[element_tag.index('}') + 1:]
1430
+ else:
1431
+ namespace = None
1432
+ tag = element_tag
1433
+ extension = ExtensionElement(namespace=namespace, tag=tag)
1434
+ for key, value in element_tree.attrib.items():
1435
+ extension.attributes[key] = value
1436
+ for child in element_tree:
1437
+ extension.children.append(_ExtensionElementFromElementTree(child))
1438
+ extension.text = element_tree.text
1439
+ return extension
1440
+
1441
+
1442
+ def deprecated(warning=None):
1443
+ """Decorator to raise warning each time the function is called.
1444
+
1445
+ Args:
1446
+ warning: The warning message to be displayed as a string (optinoal).
1447
+ """
1448
+ warning = warning or ''
1449
+
1450
+ # This closure is what is returned from the deprecated function.
1451
+ def mark_deprecated(f):
1452
+ # The deprecated_function wraps the actual call to f.
1453
+ @wraps(f)
1454
+ def deprecated_function(*args, **kwargs):
1455
+ warnings.warn(warning, DeprecationWarning, stacklevel=2)
1456
+ return f(*args, **kwargs)
1457
+
1458
+ return deprecated_function
1459
+
1460
+ return mark_deprecated