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/gdata/__init__.py ADDED
@@ -0,0 +1,825 @@
1
+ #!/usr/bin/python
2
+ #
3
+ # Copyright (C) 2006 Google Inc.
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
+
18
+ """Contains classes representing Google Data elements.
19
+
20
+ Extends Atom classes to add Google Data specific elements.
21
+ """
22
+
23
+
24
+ __author__ = 'j.s@google.com (Jeffrey Scudder)'
25
+
26
+ import os
27
+ import atom
28
+ import lxml.etree as ElementTree
29
+
30
+ # XML namespaces which are often used in GData entities.
31
+ GDATA_NAMESPACE = 'http://schemas.google.com/g/2005'
32
+ GDATA_TEMPLATE = '{http://schemas.google.com/g/2005}%s'
33
+ OPENSEARCH_NAMESPACE = 'http://a9.com/-/spec/opensearchrss/1.0/'
34
+ OPENSEARCH_TEMPLATE = '{http://a9.com/-/spec/opensearchrss/1.0/}%s'
35
+ BATCH_NAMESPACE = 'http://schemas.google.com/gdata/batch'
36
+ GACL_NAMESPACE = 'http://schemas.google.com/acl/2007'
37
+ GACL_TEMPLATE = '{http://schemas.google.com/acl/2007}%s'
38
+
39
+
40
+ # Labels used in batch request entries to specify the desired CRUD operation.
41
+ BATCH_INSERT = 'insert'
42
+ BATCH_UPDATE = 'update'
43
+ BATCH_DELETE = 'delete'
44
+ BATCH_QUERY = 'query'
45
+
46
+ class Error(Exception):
47
+ pass
48
+
49
+
50
+ class MissingRequiredParameters(Error):
51
+ pass
52
+
53
+
54
+ class MediaSource(object):
55
+ """GData Entries can refer to media sources, so this class provides a
56
+ place to store references to these objects along with some metadata.
57
+ """
58
+
59
+ def __init__(self, file_handle=None, content_type=None, content_length=None,
60
+ file_path=None, file_name=None):
61
+ """Creates an object of type MediaSource.
62
+
63
+ Args:
64
+ file_handle: A file handle pointing to the file to be encapsulated in the
65
+ MediaSource
66
+ content_type: string The MIME type of the file. Required if a file_handle
67
+ is given.
68
+ content_length: int The size of the file. Required if a file_handle is
69
+ given.
70
+ file_path: string (optional) A full path name to the file. Used in
71
+ place of a file_handle.
72
+ file_name: string The name of the file without any path information.
73
+ Required if a file_handle is given.
74
+ """
75
+ self.file_handle = file_handle
76
+ self.content_type = content_type
77
+ self.content_length = content_length
78
+ self.file_name = file_name
79
+
80
+ if (file_handle is None and content_type is not None and
81
+ file_path is not None):
82
+ self.setFile(file_path, content_type)
83
+
84
+ def setFile(self, file_name, content_type):
85
+ """A helper function which can create a file handle from a given filename
86
+ and set the content type and length all at once.
87
+
88
+ Args:
89
+ file_name: string The path and file name to the file containing the media
90
+ content_type: string A MIME type representing the type of the media
91
+ """
92
+
93
+ self.file_handle = open(file_name, 'rb')
94
+ self.content_type = content_type
95
+ self.content_length = os.path.getsize(file_name)
96
+ self.file_name = os.path.basename(file_name)
97
+
98
+
99
+ class LinkFinder(atom.LinkFinder):
100
+ """An "interface" providing methods to find link elements
101
+
102
+ GData Entry elements often contain multiple links which differ in the rel
103
+ attribute or content type. Often, developers are interested in a specific
104
+ type of link so this class provides methods to find specific classes of
105
+ links.
106
+
107
+ This class is used as a mixin in GData entries.
108
+ """
109
+
110
+ def GetSelfLink(self):
111
+ """Find the first link with rel set to 'self'
112
+
113
+ Returns:
114
+ An atom.Link or none if none of the links had rel equal to 'self'
115
+ """
116
+
117
+ for a_link in self.link:
118
+ if a_link.rel == 'self':
119
+ return a_link
120
+ return None
121
+
122
+ def GetEditLink(self):
123
+ for a_link in self.link:
124
+ if a_link.rel == 'edit':
125
+ return a_link
126
+ return None
127
+
128
+ def GetEditMediaLink(self):
129
+ """The Picasa API mistakenly returns media-edit rather than edit-media, but
130
+ this may change soon.
131
+ """
132
+ for a_link in self.link:
133
+ if a_link.rel == 'edit-media':
134
+ return a_link
135
+ if a_link.rel == 'media-edit':
136
+ return a_link
137
+ return None
138
+
139
+ def GetHtmlLink(self):
140
+ """Find the first link with rel of alternate and type of text/html
141
+
142
+ Returns:
143
+ An atom.Link or None if no links matched
144
+ """
145
+ for a_link in self.link:
146
+ if a_link.rel == 'alternate' and a_link.type == 'text/html':
147
+ return a_link
148
+ return None
149
+
150
+ def GetPostLink(self):
151
+ """Get a link containing the POST target URL.
152
+
153
+ The POST target URL is used to insert new entries.
154
+
155
+ Returns:
156
+ A link object with a rel matching the POST type.
157
+ """
158
+ for a_link in self.link:
159
+ if a_link.rel == 'http://schemas.google.com/g/2005#post':
160
+ return a_link
161
+ return None
162
+
163
+ def GetAclLink(self):
164
+ for a_link in self.link:
165
+ if a_link.rel == 'http://schemas.google.com/acl/2007#accessControlList':
166
+ return a_link
167
+ return None
168
+
169
+ def GetFeedLink(self):
170
+ for a_link in self.link:
171
+ if a_link.rel == 'http://schemas.google.com/g/2005#feed':
172
+ return a_link
173
+ return None
174
+
175
+ def GetNextLink(self):
176
+ for a_link in self.link:
177
+ if a_link.rel == 'next':
178
+ return a_link
179
+ return None
180
+
181
+ def GetPrevLink(self):
182
+ for a_link in self.link:
183
+ if a_link.rel == 'previous':
184
+ return a_link
185
+ return None
186
+
187
+
188
+ class TotalResults(atom.AtomBase):
189
+ """opensearch:TotalResults for a GData feed"""
190
+
191
+ _tag = 'totalResults'
192
+ _namespace = OPENSEARCH_NAMESPACE
193
+ _children = atom.AtomBase._children.copy()
194
+ _attributes = atom.AtomBase._attributes.copy()
195
+
196
+ def __init__(self, extension_elements=None,
197
+ extension_attributes=None, text=None):
198
+ self.text = text
199
+ self.extension_elements = extension_elements or []
200
+ self.extension_attributes = extension_attributes or {}
201
+
202
+
203
+ def TotalResultsFromString(xml_string):
204
+ return atom.CreateClassFromXMLString(TotalResults, xml_string)
205
+
206
+
207
+ class StartIndex(atom.AtomBase):
208
+ """The opensearch:startIndex element in GData feed"""
209
+
210
+ _tag = 'startIndex'
211
+ _namespace = OPENSEARCH_NAMESPACE
212
+ _children = atom.AtomBase._children.copy()
213
+ _attributes = atom.AtomBase._attributes.copy()
214
+
215
+ def __init__(self, extension_elements=None,
216
+ extension_attributes=None, text=None):
217
+ self.text = text
218
+ self.extension_elements = extension_elements or []
219
+ self.extension_attributes = extension_attributes or {}
220
+
221
+
222
+ def StartIndexFromString(xml_string):
223
+ return atom.CreateClassFromXMLString(StartIndex, xml_string)
224
+
225
+
226
+ class ItemsPerPage(atom.AtomBase):
227
+ """The opensearch:itemsPerPage element in GData feed"""
228
+
229
+ _tag = 'itemsPerPage'
230
+ _namespace = OPENSEARCH_NAMESPACE
231
+ _children = atom.AtomBase._children.copy()
232
+ _attributes = atom.AtomBase._attributes.copy()
233
+
234
+ def __init__(self, extension_elements=None,
235
+ extension_attributes=None, text=None):
236
+ self.text = text
237
+ self.extension_elements = extension_elements or []
238
+ self.extension_attributes = extension_attributes or {}
239
+
240
+
241
+ def ItemsPerPageFromString(xml_string):
242
+ return atom.CreateClassFromXMLString(ItemsPerPage, xml_string)
243
+
244
+
245
+ class ExtendedProperty(atom.AtomBase):
246
+ """The Google Data extendedProperty element.
247
+
248
+ Used to store arbitrary key-value information specific to your
249
+ application. The value can either be a text string stored as an XML
250
+ attribute (.value), or an XML node (XmlBlob) as a child element.
251
+
252
+ This element is used in the Google Calendar data API and the Google
253
+ Contacts data API.
254
+ """
255
+
256
+ _tag = 'extendedProperty'
257
+ _namespace = GDATA_NAMESPACE
258
+ _children = atom.AtomBase._children.copy()
259
+ _attributes = atom.AtomBase._attributes.copy()
260
+ _attributes['name'] = 'name'
261
+ _attributes['value'] = 'value'
262
+
263
+ def __init__(self, name=None, value=None, extension_elements=None,
264
+ extension_attributes=None, text=None):
265
+ self.name = name
266
+ self.value = value
267
+ self.text = text
268
+ self.extension_elements = extension_elements or []
269
+ self.extension_attributes = extension_attributes or {}
270
+
271
+ def GetXmlBlobExtensionElement(self):
272
+ """Returns the XML blob as an atom.ExtensionElement.
273
+
274
+ Returns:
275
+ An atom.ExtensionElement representing the blob's XML, or None if no
276
+ blob was set.
277
+ """
278
+ if len(self.extension_elements) < 1:
279
+ return None
280
+ else:
281
+ return self.extension_elements[0]
282
+
283
+ def GetXmlBlobString(self):
284
+ """Returns the XML blob as a string.
285
+
286
+ Returns:
287
+ A string containing the blob's XML, or None if no blob was set.
288
+ """
289
+ blob = self.GetXmlBlobExtensionElement()
290
+ if blob:
291
+ return blob.ToString()
292
+ return None
293
+
294
+ def SetXmlBlob(self, blob):
295
+ """Sets the contents of the extendedProperty to XML as a child node.
296
+
297
+ Since the extendedProperty is only allowed one child element as an XML
298
+ blob, setting the XML blob will erase any preexisting extension elements
299
+ in this object.
300
+
301
+ Args:
302
+ blob: str, ElementTree Element or atom.ExtensionElement representing
303
+ the XML blob stored in the extendedProperty.
304
+ """
305
+ # Erase any existing extension_elements, clears the child nodes from the
306
+ # extendedProperty.
307
+ self.extension_elements = []
308
+ if isinstance(blob, atom.ExtensionElement):
309
+ self.extension_elements.append(blob)
310
+ elif ElementTree.iselement(blob):
311
+ self.extension_elements.append(atom._ExtensionElementFromElementTree(
312
+ blob))
313
+ else:
314
+ self.extension_elements.append(atom.ExtensionElementFromString(blob))
315
+
316
+
317
+ def ExtendedPropertyFromString(xml_string):
318
+ return atom.CreateClassFromXMLString(ExtendedProperty, xml_string)
319
+
320
+
321
+ class GDataEntry(atom.Entry, LinkFinder):
322
+ """Extends Atom Entry to provide data processing"""
323
+
324
+ _tag = atom.Entry._tag
325
+ _namespace = atom.Entry._namespace
326
+ _children = atom.Entry._children.copy()
327
+ _attributes = atom.Entry._attributes.copy()
328
+
329
+ def __GetId(self):
330
+ return self.__id
331
+
332
+ # This method was created to strip the unwanted whitespace from the id's
333
+ # text node.
334
+ def __SetId(self, id):
335
+ self.__id = id
336
+ if id is not None and id.text is not None:
337
+ self.__id.text = id.text.strip()
338
+
339
+ id = property(__GetId, __SetId)
340
+
341
+ def IsMedia(self):
342
+ """Determines whether or not an entry is a GData Media entry.
343
+ """
344
+ if (self.GetEditMediaLink()):
345
+ return True
346
+ else:
347
+ return False
348
+
349
+ def GetMediaURL(self):
350
+ """Returns the URL to the media content, if the entry is a media entry.
351
+ Otherwise returns None.
352
+ """
353
+ if not self.IsMedia():
354
+ return None
355
+ else:
356
+ return self.content.src
357
+
358
+
359
+ def GDataEntryFromString(xml_string):
360
+ """Creates a new GDataEntry instance given a string of XML."""
361
+ return atom.CreateClassFromXMLString(GDataEntry, xml_string)
362
+
363
+
364
+ class GDataFeed(atom.Feed, LinkFinder):
365
+ """A Feed from a GData service"""
366
+
367
+ _tag = 'feed'
368
+ _namespace = atom.ATOM_NAMESPACE
369
+ _children = atom.Feed._children.copy()
370
+ _attributes = atom.Feed._attributes.copy()
371
+ _children['{%s}totalResults' % OPENSEARCH_NAMESPACE] = ('total_results',
372
+ TotalResults)
373
+ _children['{%s}startIndex' % OPENSEARCH_NAMESPACE] = ('start_index',
374
+ StartIndex)
375
+ _children['{%s}itemsPerPage' % OPENSEARCH_NAMESPACE] = ('items_per_page',
376
+ ItemsPerPage)
377
+ # Add a conversion rule for atom:entry to make it into a GData
378
+ # Entry.
379
+ _children['{%s}entry' % atom.ATOM_NAMESPACE] = ('entry', [GDataEntry])
380
+
381
+ def __GetId(self):
382
+ return self.__id
383
+
384
+ def __SetId(self, id):
385
+ self.__id = id
386
+ if id is not None and id.text is not None:
387
+ self.__id.text = id.text.strip()
388
+
389
+ id = property(__GetId, __SetId)
390
+
391
+ def __GetGenerator(self):
392
+ return self.__generator
393
+
394
+ def __SetGenerator(self, generator):
395
+ self.__generator = generator
396
+ if generator is not None:
397
+ self.__generator.text = generator.text.strip()
398
+
399
+ generator = property(__GetGenerator, __SetGenerator)
400
+
401
+ def __init__(self, author=None, category=None, contributor=None,
402
+ generator=None, icon=None, atom_id=None, link=None, logo=None,
403
+ rights=None, subtitle=None, title=None, updated=None, entry=None,
404
+ total_results=None, start_index=None, items_per_page=None,
405
+ extension_elements=None, extension_attributes=None, text=None):
406
+ """Constructor for Source
407
+
408
+ Args:
409
+ author: list (optional) A list of Author instances which belong to this
410
+ class.
411
+ category: list (optional) A list of Category instances
412
+ contributor: list (optional) A list on Contributor instances
413
+ generator: Generator (optional)
414
+ icon: Icon (optional)
415
+ id: Id (optional) The entry's Id element
416
+ link: list (optional) A list of Link instances
417
+ logo: Logo (optional)
418
+ rights: Rights (optional) The entry's Rights element
419
+ subtitle: Subtitle (optional) The entry's subtitle element
420
+ title: Title (optional) the entry's title element
421
+ updated: Updated (optional) the entry's updated element
422
+ entry: list (optional) A list of the Entry instances contained in the
423
+ feed.
424
+ text: String (optional) The text contents of the element. This is the
425
+ contents of the Entry's XML text node.
426
+ (Example: <foo>This is the text</foo>)
427
+ extension_elements: list (optional) A list of ExtensionElement instances
428
+ which are children of this element.
429
+ extension_attributes: dict (optional) A dictionary of strings which are
430
+ the values for additional XML attributes of this element.
431
+ """
432
+
433
+ self.author = author or []
434
+ self.category = category or []
435
+ self.contributor = contributor or []
436
+ self.generator = generator
437
+ self.icon = icon
438
+ self.id = atom_id
439
+ self.link = link or []
440
+ self.logo = logo
441
+ self.rights = rights
442
+ self.subtitle = subtitle
443
+ self.title = title
444
+ self.updated = updated
445
+ self.entry = entry or []
446
+ self.total_results = total_results
447
+ self.start_index = start_index
448
+ self.items_per_page = items_per_page
449
+ self.text = text
450
+ self.extension_elements = extension_elements or []
451
+ self.extension_attributes = extension_attributes or {}
452
+
453
+
454
+ def GDataFeedFromString(xml_string):
455
+ return atom.CreateClassFromXMLString(GDataFeed, xml_string)
456
+
457
+
458
+ class BatchId(atom.AtomBase):
459
+ _tag = 'id'
460
+ _namespace = BATCH_NAMESPACE
461
+ _children = atom.AtomBase._children.copy()
462
+ _attributes = atom.AtomBase._attributes.copy()
463
+
464
+
465
+ def BatchIdFromString(xml_string):
466
+ return atom.CreateClassFromXMLString(BatchId, xml_string)
467
+
468
+
469
+ class BatchOperation(atom.AtomBase):
470
+ _tag = 'operation'
471
+ _namespace = BATCH_NAMESPACE
472
+ _children = atom.AtomBase._children.copy()
473
+ _attributes = atom.AtomBase._attributes.copy()
474
+ _attributes['type'] = 'type'
475
+
476
+ def __init__(self, op_type=None, extension_elements=None,
477
+ extension_attributes=None,
478
+ text=None):
479
+ self.type = op_type
480
+ atom.AtomBase.__init__(self,
481
+ extension_elements=extension_elements,
482
+ extension_attributes=extension_attributes,
483
+ text=text)
484
+
485
+
486
+ def BatchOperationFromString(xml_string):
487
+ return atom.CreateClassFromXMLString(BatchOperation, xml_string)
488
+
489
+
490
+ class BatchStatus(atom.AtomBase):
491
+ """The batch:status element present in a batch response entry.
492
+
493
+ A status element contains the code (HTTP response code) and
494
+ reason as elements. In a single request these fields would
495
+ be part of the HTTP response, but in a batch request each
496
+ Entry operation has a corresponding Entry in the response
497
+ feed which includes status information.
498
+
499
+ See http://code.google.com/apis/gdata/batch.html#Handling_Errors
500
+ """
501
+
502
+ _tag = 'status'
503
+ _namespace = BATCH_NAMESPACE
504
+ _children = atom.AtomBase._children.copy()
505
+ _attributes = atom.AtomBase._attributes.copy()
506
+ _attributes['code'] = 'code'
507
+ _attributes['reason'] = 'reason'
508
+ _attributes['content-type'] = 'content_type'
509
+
510
+ def __init__(self, code=None, reason=None, content_type=None,
511
+ extension_elements=None, extension_attributes=None, text=None):
512
+ self.code = code
513
+ self.reason = reason
514
+ self.content_type = content_type
515
+ atom.AtomBase.__init__(self, extension_elements=extension_elements,
516
+ extension_attributes=extension_attributes,
517
+ text=text)
518
+
519
+
520
+ def BatchStatusFromString(xml_string):
521
+ return atom.CreateClassFromXMLString(BatchStatus, xml_string)
522
+
523
+
524
+ class BatchEntry(GDataEntry):
525
+ """An atom:entry for use in batch requests.
526
+
527
+ The BatchEntry contains additional members to specify the operation to be
528
+ performed on this entry and a batch ID so that the server can reference
529
+ individual operations in the response feed. For more information, see:
530
+ http://code.google.com/apis/gdata/batch.html
531
+ """
532
+
533
+ _tag = GDataEntry._tag
534
+ _namespace = GDataEntry._namespace
535
+ _children = GDataEntry._children.copy()
536
+ _children['{%s}operation' % BATCH_NAMESPACE] = ('batch_operation', BatchOperation)
537
+ _children['{%s}id' % BATCH_NAMESPACE] = ('batch_id', BatchId)
538
+ _children['{%s}status' % BATCH_NAMESPACE] = ('batch_status', BatchStatus)
539
+ _attributes = GDataEntry._attributes.copy()
540
+
541
+ def __init__(self, author=None, category=None, content=None,
542
+ contributor=None, atom_id=None, link=None, published=None, rights=None,
543
+ source=None, summary=None, control=None, title=None, updated=None,
544
+ batch_operation=None, batch_id=None, batch_status=None,
545
+ extension_elements=None, extension_attributes=None, text=None):
546
+ self.batch_operation = batch_operation
547
+ self.batch_id = batch_id
548
+ self.batch_status = batch_status
549
+ GDataEntry.__init__(self, author=author, category=category,
550
+ content=content, contributor=contributor, atom_id=atom_id, link=link,
551
+ published=published, rights=rights, source=source, summary=summary,
552
+ control=control, title=title, updated=updated,
553
+ extension_elements=extension_elements,
554
+ extension_attributes=extension_attributes, text=text)
555
+
556
+
557
+ def BatchEntryFromString(xml_string):
558
+ return atom.CreateClassFromXMLString(BatchEntry, xml_string)
559
+
560
+
561
+ class BatchInterrupted(atom.AtomBase):
562
+ """The batch:interrupted element sent if batch request was interrupted.
563
+
564
+ Only appears in a feed if some of the batch entries could not be processed.
565
+ See: http://code.google.com/apis/gdata/batch.html#Handling_Errors
566
+ """
567
+
568
+ _tag = 'interrupted'
569
+ _namespace = BATCH_NAMESPACE
570
+ _children = atom.AtomBase._children.copy()
571
+ _attributes = atom.AtomBase._attributes.copy()
572
+ _attributes['reason'] = 'reason'
573
+ _attributes['success'] = 'success'
574
+ _attributes['failures'] = 'failures'
575
+ _attributes['parsed'] = 'parsed'
576
+
577
+ def __init__(self, reason=None, success=None, failures=None, parsed=None,
578
+ extension_elements=None, extension_attributes=None, text=None):
579
+ self.reason = reason
580
+ self.success = success
581
+ self.failures = failures
582
+ self.parsed = parsed
583
+ atom.AtomBase.__init__(self, extension_elements=extension_elements,
584
+ extension_attributes=extension_attributes,
585
+ text=text)
586
+
587
+
588
+ def BatchInterruptedFromString(xml_string):
589
+ return atom.CreateClassFromXMLString(BatchInterrupted, xml_string)
590
+
591
+
592
+ class BatchFeed(GDataFeed):
593
+ """A feed containing a list of batch request entries."""
594
+
595
+ _tag = GDataFeed._tag
596
+ _namespace = GDataFeed._namespace
597
+ _children = GDataFeed._children.copy()
598
+ _attributes = GDataFeed._attributes.copy()
599
+ _children['{%s}entry' % atom.ATOM_NAMESPACE] = ('entry', [BatchEntry])
600
+ _children['{%s}interrupted' % BATCH_NAMESPACE] = ('interrupted', BatchInterrupted)
601
+
602
+ def __init__(self, author=None, category=None, contributor=None,
603
+ generator=None, icon=None, atom_id=None, link=None, logo=None,
604
+ rights=None, subtitle=None, title=None, updated=None, entry=None,
605
+ total_results=None, start_index=None, items_per_page=None,
606
+ interrupted=None,
607
+ extension_elements=None, extension_attributes=None, text=None):
608
+ self.interrupted = interrupted
609
+ GDataFeed.__init__(self, author=author, category=category,
610
+ contributor=contributor, generator=generator,
611
+ icon=icon, atom_id=atom_id, link=link,
612
+ logo=logo, rights=rights, subtitle=subtitle,
613
+ title=title, updated=updated, entry=entry,
614
+ total_results=total_results, start_index=start_index,
615
+ items_per_page=items_per_page,
616
+ extension_elements=extension_elements,
617
+ extension_attributes=extension_attributes,
618
+ text=text)
619
+
620
+ def AddBatchEntry(self, entry=None, id_url_string=None,
621
+ batch_id_string=None, operation_string=None):
622
+ """Logic for populating members of a BatchEntry and adding to the feed.
623
+
624
+
625
+ If the entry is not a BatchEntry, it is converted to a BatchEntry so
626
+ that the batch specific members will be present.
627
+
628
+ The id_url_string can be used in place of an entry if the batch operation
629
+ applies to a URL. For example query and delete operations require just
630
+ the URL of an entry, no body is sent in the HTTP request. If an
631
+ id_url_string is sent instead of an entry, a BatchEntry is created and
632
+ added to the feed.
633
+
634
+ This method also assigns the desired batch id to the entry so that it
635
+ can be referenced in the server's response. If the batch_id_string is
636
+ None, this method will assign a batch_id to be the index at which this
637
+ entry will be in the feed's entry list.
638
+
639
+ Args:
640
+ entry: BatchEntry, atom.Entry, or another Entry flavor (optional) The
641
+ entry which will be sent to the server as part of the batch request.
642
+ The item must have a valid atom id so that the server knows which
643
+ entry this request references.
644
+ id_url_string: str (optional) The URL of the entry to be acted on. You
645
+ can find this URL in the text member of the atom id for an entry.
646
+ If an entry is not sent, this id will be used to construct a new
647
+ BatchEntry which will be added to the request feed.
648
+ batch_id_string: str (optional) The batch ID to be used to reference
649
+ this batch operation in the results feed. If this parameter is None,
650
+ the current length of the feed's entry array will be used as a
651
+ count. Note that batch_ids should either always be specified or
652
+ never, mixing could potentially result in duplicate batch ids.
653
+ operation_string: str (optional) The desired batch operation which will
654
+ set the batch_operation.type member of the entry. Options are
655
+ 'insert', 'update', 'delete', and 'query'
656
+
657
+ Raises:
658
+ MissingRequiredParameters: Raised if neither an id_ url_string nor an
659
+ entry are provided in the request.
660
+
661
+ Returns:
662
+ The added entry.
663
+ """
664
+ if entry is None and id_url_string is None:
665
+ raise MissingRequiredParameters('supply either an entry or URL string')
666
+ if entry is None and id_url_string is not None:
667
+ entry = BatchEntry(atom_id=atom.Id(text=id_url_string))
668
+ # TODO: handle cases in which the entry lacks batch_... members.
669
+ #if not isinstance(entry, BatchEntry):
670
+ # Convert the entry to a batch entry.
671
+ if batch_id_string is not None:
672
+ entry.batch_id = BatchId(text=batch_id_string)
673
+ elif entry.batch_id is None or entry.batch_id.text is None:
674
+ entry.batch_id = BatchId(text=str(len(self.entry)))
675
+ if operation_string is not None:
676
+ entry.batch_operation = BatchOperation(op_type=operation_string)
677
+ self.entry.append(entry)
678
+ return entry
679
+
680
+ def AddInsert(self, entry, batch_id_string=None):
681
+ """Add an insert request to the operations in this batch request feed.
682
+
683
+ If the entry doesn't yet have an operation or a batch id, these will
684
+ be set to the insert operation and a batch_id specified as a parameter.
685
+
686
+ Args:
687
+ entry: BatchEntry The entry which will be sent in the batch feed as an
688
+ insert request.
689
+ batch_id_string: str (optional) The batch ID to be used to reference
690
+ this batch operation in the results feed. If this parameter is None,
691
+ the current length of the feed's entry array will be used as a
692
+ count. Note that batch_ids should either always be specified or
693
+ never, mixing could potentially result in duplicate batch ids.
694
+ """
695
+ entry = self.AddBatchEntry(entry=entry, batch_id_string=batch_id_string,
696
+ operation_string=BATCH_INSERT)
697
+
698
+ def AddUpdate(self, entry, batch_id_string=None):
699
+ """Add an update request to the list of batch operations in this feed.
700
+
701
+ Sets the operation type of the entry to insert if it is not already set
702
+ and assigns the desired batch id to the entry so that it can be
703
+ referenced in the server's response.
704
+
705
+ Args:
706
+ entry: BatchEntry The entry which will be sent to the server as an
707
+ update (HTTP PUT) request. The item must have a valid atom id
708
+ so that the server knows which entry to replace.
709
+ batch_id_string: str (optional) The batch ID to be used to reference
710
+ this batch operation in the results feed. If this parameter is None,
711
+ the current length of the feed's entry array will be used as a
712
+ count. See also comments for AddInsert.
713
+ """
714
+ entry = self.AddBatchEntry(entry=entry, batch_id_string=batch_id_string,
715
+ operation_string=BATCH_UPDATE)
716
+
717
+ def AddDelete(self, url_string=None, entry=None, batch_id_string=None):
718
+ """Adds a delete request to the batch request feed.
719
+
720
+ This method takes either the url_string which is the atom id of the item
721
+ to be deleted, or the entry itself. The atom id of the entry must be
722
+ present so that the server knows which entry should be deleted.
723
+
724
+ Args:
725
+ url_string: str (optional) The URL of the entry to be deleted. You can
726
+ find this URL in the text member of the atom id for an entry.
727
+ entry: BatchEntry (optional) The entry to be deleted.
728
+ batch_id_string: str (optional)
729
+
730
+ Raises:
731
+ MissingRequiredParameters: Raised if neither a url_string nor an entry
732
+ are provided in the request.
733
+ """
734
+ entry = self.AddBatchEntry(entry=entry, id_url_string=url_string,
735
+ batch_id_string=batch_id_string,
736
+ operation_string=BATCH_DELETE)
737
+
738
+ def AddQuery(self, url_string=None, entry=None, batch_id_string=None):
739
+ """Adds a query request to the batch request feed.
740
+
741
+ This method takes either the url_string which is the query URL
742
+ whose results will be added to the result feed. The query URL will
743
+ be encapsulated in a BatchEntry, and you may pass in the BatchEntry
744
+ with a query URL instead of sending a url_string.
745
+
746
+ Args:
747
+ url_string: str (optional)
748
+ entry: BatchEntry (optional)
749
+ batch_id_string: str (optional)
750
+
751
+ Raises:
752
+ MissingRequiredParameters
753
+ """
754
+ entry = self.AddBatchEntry(entry=entry, id_url_string=url_string,
755
+ batch_id_string=batch_id_string,
756
+ operation_string=BATCH_QUERY)
757
+
758
+ def GetBatchLink(self):
759
+ for link in self.link:
760
+ if link.rel == 'http://schemas.google.com/g/2005#batch':
761
+ return link
762
+ return None
763
+
764
+
765
+ def BatchFeedFromString(xml_string):
766
+ return atom.CreateClassFromXMLString(BatchFeed, xml_string)
767
+
768
+
769
+ class EntryLink(atom.AtomBase):
770
+ """The gd:entryLink element"""
771
+
772
+ _tag = 'entryLink'
773
+ _namespace = GDATA_NAMESPACE
774
+ _children = atom.AtomBase._children.copy()
775
+ _attributes = atom.AtomBase._attributes.copy()
776
+ # The entry used to be an atom.Entry, now it is a GDataEntry.
777
+ _children['{%s}entry' % atom.ATOM_NAMESPACE] = ('entry', GDataEntry)
778
+ _attributes['rel'] = 'rel'
779
+ _attributes['readOnly'] = 'read_only'
780
+ _attributes['href'] = 'href'
781
+
782
+ def __init__(self, href=None, read_only=None, rel=None,
783
+ entry=None, extension_elements=None,
784
+ extension_attributes=None, text=None):
785
+ self.href = href
786
+ self.read_only = read_only
787
+ self.rel = rel
788
+ self.entry = entry
789
+ self.text = text
790
+ self.extension_elements = extension_elements or []
791
+ self.extension_attributes = extension_attributes or {}
792
+
793
+
794
+ def EntryLinkFromString(xml_string):
795
+ return atom.CreateClassFromXMLString(EntryLink, xml_string)
796
+
797
+
798
+ class FeedLink(atom.AtomBase):
799
+ """The gd:feedLink element"""
800
+
801
+ _tag = 'feedLink'
802
+ _namespace = GDATA_NAMESPACE
803
+ _children = atom.AtomBase._children.copy()
804
+ _attributes = atom.AtomBase._attributes.copy()
805
+ _children['{%s}feed' % atom.ATOM_NAMESPACE] = ('feed', GDataFeed)
806
+ _attributes['rel'] = 'rel'
807
+ _attributes['readOnly'] = 'read_only'
808
+ _attributes['countHint'] = 'count_hint'
809
+ _attributes['href'] = 'href'
810
+
811
+ def __init__(self, count_hint=None, href=None, read_only=None, rel=None,
812
+ feed=None, extension_elements=None, extension_attributes=None,
813
+ text=None):
814
+ self.count_hint = count_hint
815
+ self.href = href
816
+ self.read_only = read_only
817
+ self.rel = rel
818
+ self.feed = feed
819
+ self.text = text
820
+ self.extension_elements = extension_elements or []
821
+ self.extension_attributes = extension_attributes or {}
822
+
823
+
824
+ def FeedLinkFromString(xml_string):
825
+ return atom.CreateClassFromXMLString(FeedLink, xml_string)