3
# Copyright (C) 2006 Google Inc.
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.
19
# add text=none to all inits
22
"""Contains extensions to ElementWrapper objects used with Google Calendar."""
24
__author__ = 'api.vli (Vivian Li), api.rboyd (Ryan Boyd)'
27
from xml.etree import cElementTree as ElementTree
30
import cElementTree as ElementTree
32
from elementtree import ElementTree
37
# XML namespaces which are often used in Google Calendar entities.
38
GCAL_NAMESPACE = 'http://schemas.google.com/gCal/2005'
39
GCAL_TEMPLATE = '{http://schemas.google.com/gCal/2005}%s'
40
WEB_CONTENT_LINK_REL = '%s/%s' % (GCAL_NAMESPACE, 'webContent')
41
GACL_NAMESPACE = gdata.GACL_NAMESPACE
42
GACL_TEMPLATE = gdata.GACL_TEMPLATE
46
class ValueAttributeContainer(atom.AtomBase):
47
"""A parent class for all Calendar classes which have a value attribute.
49
Children include Color, AccessLevel, Hidden
52
_children = atom.AtomBase._children.copy()
53
_attributes = atom.AtomBase._attributes.copy()
54
_attributes['value'] = 'value'
56
def __init__(self, value=None, extension_elements=None,
57
extension_attributes=None, text=None):
60
self.extension_elements = extension_elements or []
61
self.extension_attributes = extension_attributes or {}
63
class Color(ValueAttributeContainer):
64
"""The Google Calendar color element"""
67
_namespace = GCAL_NAMESPACE
68
_children = ValueAttributeContainer._children.copy()
69
_attributes = ValueAttributeContainer._attributes.copy()
73
class AccessLevel(ValueAttributeContainer):
74
"""The Google Calendar accesslevel element"""
77
_namespace = GCAL_NAMESPACE
78
_children = ValueAttributeContainer._children.copy()
79
_attributes = ValueAttributeContainer._attributes.copy()
82
class Hidden(ValueAttributeContainer):
83
"""The Google Calendar hidden element"""
86
_namespace = GCAL_NAMESPACE
87
_children = ValueAttributeContainer._children.copy()
88
_attributes = ValueAttributeContainer._attributes.copy()
91
class Selected(ValueAttributeContainer):
92
"""The Google Calendar selected element"""
95
_namespace = GCAL_NAMESPACE
96
_children = ValueAttributeContainer._children.copy()
97
_attributes = ValueAttributeContainer._attributes.copy()
100
class Timezone(ValueAttributeContainer):
101
"""The Google Calendar timezone element"""
104
_namespace = GCAL_NAMESPACE
105
_children = ValueAttributeContainer._children.copy()
106
_attributes = ValueAttributeContainer._attributes.copy()
109
class Where(atom.AtomBase):
110
"""The Google Calendar Where element"""
113
_namespace = gdata.GDATA_NAMESPACE
114
_children = atom.AtomBase._children.copy()
115
_attributes = atom.AtomBase._attributes.copy()
116
_attributes['valueString'] = 'value_string'
118
def __init__(self, value_string=None, extension_elements=None,
119
extension_attributes=None, text=None):
120
self.value_string = value_string
122
self.extension_elements = extension_elements or []
123
self.extension_attributes = extension_attributes or {}
126
class CalendarListEntry(gdata.GDataEntry, gdata.LinkFinder):
127
"""A Google Calendar meta Entry flavor of an Atom Entry """
129
_tag = gdata.GDataEntry._tag
130
_namespace = gdata.GDataEntry._namespace
131
_children = gdata.GDataEntry._children.copy()
132
_attributes = gdata.GDataEntry._attributes.copy()
133
_children['{%s}color' % GCAL_NAMESPACE] = ('color', Color)
134
_children['{%s}accesslevel' % GCAL_NAMESPACE] = ('access_level',
136
_children['{%s}hidden' % GCAL_NAMESPACE] = ('hidden', Hidden)
137
_children['{%s}selected' % GCAL_NAMESPACE] = ('selected', Selected)
138
_children['{%s}timezone' % GCAL_NAMESPACE] = ('timezone', Timezone)
139
_children['{%s}where' % gdata.GDATA_NAMESPACE] = ('where', Where)
141
def __init__(self, author=None, category=None, content=None,
142
atom_id=None, link=None, published=None,
143
title=None, updated=None,
144
color=None, access_level=None, hidden=None, timezone=None,
147
extension_elements=None, extension_attributes=None, text=None):
148
gdata.GDataEntry.__init__(self, author=author, category=category,
149
content=content, atom_id=atom_id, link=link,
150
published=published, title=title,
151
updated=updated, text=None)
154
self.access_level = access_level
156
self.selected = selected
157
self.timezone = timezone
161
class CalendarListFeed(gdata.GDataFeed, gdata.LinkFinder):
162
"""A Google Calendar meta feed flavor of an Atom Feed"""
164
_tag = gdata.GDataFeed._tag
165
_namespace = gdata.GDataFeed._namespace
166
_children = gdata.GDataFeed._children.copy()
167
_attributes = gdata.GDataFeed._attributes.copy()
168
_children['{%s}entry' % atom.ATOM_NAMESPACE] = ('entry', [CalendarListEntry])
172
class Scope(atom.AtomBase):
173
"""The Google ACL scope element"""
176
_namespace = GACL_NAMESPACE
177
_children = atom.AtomBase._children.copy()
178
_attributes = atom.AtomBase._attributes.copy()
179
_attributes['value'] = 'value'
180
_attributes['type'] = 'type'
182
def __init__(self, extension_elements=None, value=None, scope_type=None,
183
extension_attributes=None, text=None):
185
self.type = scope_type
187
self.extension_elements = extension_elements or []
188
self.extension_attributes = extension_attributes or {}
191
class Role(ValueAttributeContainer):
192
"""The Google Calendar timezone element"""
195
_namespace = GACL_NAMESPACE
196
_children = ValueAttributeContainer._children.copy()
197
_attributes = ValueAttributeContainer._attributes.copy()
200
class CalendarAclEntry(gdata.GDataEntry, gdata.LinkFinder):
201
"""A Google Calendar ACL Entry flavor of an Atom Entry """
203
_tag = gdata.GDataEntry._tag
204
_namespace = gdata.GDataEntry._namespace
205
_children = gdata.GDataEntry._children.copy()
206
_attributes = gdata.GDataEntry._attributes.copy()
207
_children['{%s}scope' % GACL_NAMESPACE] = ('scope', Scope)
208
_children['{%s}role' % GACL_NAMESPACE] = ('role', Role)
210
def __init__(self, author=None, category=None, content=None,
211
atom_id=None, link=None, published=None,
212
title=None, updated=None,
213
scope=None, role=None,
214
extension_elements=None, extension_attributes=None, text=None):
215
gdata.GDataEntry.__init__(self, author=author, category=category,
216
content=content, atom_id=atom_id, link=link,
217
published=published, title=title,
218
updated=updated, text=None)
225
class CalendarAclFeed(gdata.GDataFeed, gdata.LinkFinder):
226
"""A Google Calendar ACL feed flavor of an Atom Feed"""
228
_tag = gdata.GDataFeed._tag
229
_namespace = gdata.GDataFeed._namespace
230
_children = gdata.GDataFeed._children.copy()
231
_attributes = gdata.GDataFeed._attributes.copy()
232
_children['{%s}entry' % atom.ATOM_NAMESPACE] = ('entry', [CalendarAclEntry])
235
class CalendarEventCommentEntry(gdata.GDataEntry, gdata.LinkFinder):
236
"""A Google Calendar event comments entry flavor of an Atom Entry"""
238
_tag = gdata.GDataEntry._tag
239
_namespace = gdata.GDataEntry._namespace
240
_children = gdata.GDataEntry._children.copy()
241
_attributes = gdata.GDataEntry._attributes.copy()
244
class CalendarEventCommentFeed(gdata.GDataFeed, gdata.LinkFinder):
245
"""A Google Calendar event comments feed flavor of an Atom Feed"""
247
_tag = gdata.GDataFeed._tag
248
_namespace = gdata.GDataFeed._namespace
249
_children = gdata.GDataFeed._children.copy()
250
_attributes = gdata.GDataFeed._attributes.copy()
251
_children['{%s}entry' % atom.ATOM_NAMESPACE] = ('entry',
252
[CalendarEventCommentEntry])
255
class ExtendedProperty(atom.AtomBase):
256
"""The Google Calendar extendedProperty element"""
258
_tag = 'extendedProperty'
259
_namespace = gdata.GDATA_NAMESPACE
260
_children = atom.AtomBase._children.copy()
261
_attributes = atom.AtomBase._attributes.copy()
262
_attributes['name'] = 'name'
263
_attributes['value'] = 'value'
265
def __init__(self, name=None, value=None, extension_elements=None,
266
extension_attributes=None, text=None):
270
self.extension_elements = extension_elements or []
271
self.extension_attributes = extension_attributes or {}
274
class Reminder(atom.AtomBase):
275
"""The Google Calendar reminder element"""
278
_namespace = gdata.GDATA_NAMESPACE
279
_children = atom.AtomBase._children.copy()
280
_attributes = atom.AtomBase._attributes.copy()
281
_attributes['absoluteTime'] = 'absolute_time'
282
_attributes['days'] = 'days'
283
_attributes['hours'] = 'hours'
284
_attributes['minutes'] = 'minutes'
286
def __init__(self, absolute_time=None,
287
days=None, hours=None, minutes=None,
288
extension_elements=None,
289
extension_attributes=None, text=None):
290
self.absolute_time = absolute_time
292
self.days = str(days)
295
if hours is not None:
296
self.hours = str(hours)
299
if minutes is not None:
300
self.minutes = str(minutes)
304
self.extension_elements = extension_elements or []
305
self.extension_attributes = extension_attributes or {}
308
class When(atom.AtomBase):
309
"""The Google Calendar When element"""
312
_namespace = gdata.GDATA_NAMESPACE
313
_children = atom.AtomBase._children.copy()
314
_attributes = atom.AtomBase._attributes.copy()
315
_children['{%s}reminder' % gdata.GDATA_NAMESPACE] = ('reminder', [Reminder])
316
_attributes['startTime'] = 'start_time'
317
_attributes['endTime'] = 'end_time'
319
def __init__(self, start_time=None, end_time=None, reminder=None,
320
extension_elements=None, extension_attributes=None, text=None):
321
self.start_time = start_time
322
self.end_time = end_time
323
self.reminder = reminder or []
325
self.extension_elements = extension_elements or []
326
self.extension_attributes = extension_attributes or {}
329
class Recurrence(atom.AtomBase):
330
"""The Google Calendar Recurrence element"""
333
_namespace = gdata.GDATA_NAMESPACE
334
_children = atom.AtomBase._children.copy()
335
_attributes = atom.AtomBase._attributes.copy()
338
class UriEnumElement(atom.AtomBase):
340
_children = atom.AtomBase._children.copy()
341
_attributes = atom.AtomBase._attributes.copy()
343
def __init__(self, tag, enum_map, attrib_name='value',
344
extension_elements=None, extension_attributes=None, text=None):
346
self.enum_map=enum_map
347
self.attrib_name=attrib_name
350
self.extension_elements = extension_elements or []
351
self.extension_attributes = extension_attributes or {}
353
def findKey(self, value):
354
res=[item[0] for item in self.enum_map.items() if item[1] == value]
355
if res is None or len(res) == 0:
359
def _ConvertElementAttributeToMember(self, attribute, value):
360
# Special logic to use the enum_map to set the value of the object's value member.
361
if attribute == self.attrib_name and value != '':
362
self.value = self.enum_map[value]
364
# Find the attribute in this class's list of attributes.
365
if self.__class__._attributes.has_key(attribute):
366
# Find the member of this class which corresponds to the XML attribute
367
# (lookup in current_class._attributes) and set this member to the
368
# desired value (using self.__dict__).
369
setattr(self, self.__class__._attributes[attribute], value)
371
# The current class doesn't map this attribute, so try to parent class.
372
atom.ExtensionContainer._ConvertElementAttributeToMember(self,
376
def _AddMembersToElementTree(self, tree):
377
# Convert the members of this class which are XML child nodes.
378
# This uses the class's _children dictionary to find the members which
379
# should become XML child nodes.
380
member_node_names = [values[0] for tag, values in
381
self.__class__._children.iteritems()]
382
for member_name in member_node_names:
383
member = getattr(self, member_name)
386
elif isinstance(member, list):
387
for instance in member:
388
instance._BecomeChildElement(tree)
390
member._BecomeChildElement(tree)
391
# Special logic to set the desired XML attribute.
392
key = self.findKey(self.value)
394
tree.attrib[self.attrib_name]=key
395
# Convert the members of this class which are XML attributes.
396
for xml_attribute, member_name in self.__class__._attributes.iteritems():
397
member = getattr(self, member_name)
398
if member is not None:
399
tree.attrib[xml_attribute] = member
400
# Lastly, call the parent's _AddMembersToElementTree to get any
401
# extension elements.
402
atom.ExtensionContainer._AddMembersToElementTree(self, tree)
406
class AttendeeStatus(UriEnumElement):
407
"""The Google Calendar attendeeStatus element"""
409
_tag = 'attendeeStatus'
410
_namespace = gdata.GDATA_NAMESPACE
411
_children = UriEnumElement._children.copy()
412
_attributes = UriEnumElement._attributes.copy()
415
'http://schemas.google.com/g/2005#event.accepted' : 'ACCEPTED',
416
'http://schemas.google.com/g/2005#event.declined' : 'DECLINED',
417
'http://schemas.google.com/g/2005#event.invited' : 'INVITED',
418
'http://schemas.google.com/g/2005#event.tentative' : 'TENTATIVE'}
420
def __init__(self, extension_elements=None,
421
extension_attributes=None, text=None):
422
UriEnumElement.__init__(self, 'attendeeStatus', AttendeeStatus.attendee_enum,
423
extension_elements=extension_elements,
424
extension_attributes=extension_attributes,
428
class AttendeeType(UriEnumElement):
429
"""The Google Calendar attendeeType element"""
431
_tag = 'attendeeType'
432
_namespace = gdata.GDATA_NAMESPACE
433
_children = UriEnumElement._children.copy()
434
_attributes = UriEnumElement._attributes.copy()
436
attendee_type_enum = {
437
'http://schemas.google.com/g/2005#event.optional' : 'OPTIONAL',
438
'http://schemas.google.com/g/2005#event.required' : 'REQUIRED' }
440
def __init__(self, extension_elements=None,
441
extension_attributes=None, text=None):
442
UriEnumElement.__init__(self, 'attendeeType',
443
AttendeeType.attendee_type_enum,
444
extension_elements=extension_elements,
445
extension_attributes=extension_attributes,text=text)
448
class Visibility(UriEnumElement):
449
"""The Google Calendar Visibility element"""
452
_namespace = gdata.GDATA_NAMESPACE
453
_children = UriEnumElement._children.copy()
454
_attributes = UriEnumElement._attributes.copy()
457
'http://schemas.google.com/g/2005#event.confidential' : 'CONFIDENTIAL',
458
'http://schemas.google.com/g/2005#event.default' : 'DEFAULT',
459
'http://schemas.google.com/g/2005#event.private' : 'PRIVATE',
460
'http://schemas.google.com/g/2005#event.public' : 'PUBLIC' }
462
def __init__(self, extension_elements=None,
463
extension_attributes=None, text=None):
464
UriEnumElement.__init__(self, 'visibility', Visibility.visibility_enum,
465
extension_elements=extension_elements,
466
extension_attributes=extension_attributes,
470
class Transparency(UriEnumElement):
471
"""The Google Calendar Transparency element"""
473
_tag = 'transparency'
474
_namespace = gdata.GDATA_NAMESPACE
475
_children = UriEnumElement._children.copy()
476
_attributes = UriEnumElement._attributes.copy()
478
transparency_enum = {
479
'http://schemas.google.com/g/2005#event.opaque' : 'OPAQUE',
480
'http://schemas.google.com/g/2005#event.transparent' : 'TRANSPARENT' }
482
def __init__(self, extension_elements=None,
483
extension_attributes=None, text=None):
484
UriEnumElement.__init__(self, tag='transparency',
485
enum_map=Transparency.transparency_enum,
486
extension_elements=extension_elements,
487
extension_attributes=extension_attributes,
491
class Comments(atom.AtomBase):
492
"""The Google Calendar comments element"""
495
_namespace = gdata.GDATA_NAMESPACE
496
_children = atom.AtomBase._children.copy()
497
_attributes = atom.AtomBase._attributes.copy()
498
_children['{%s}feedLink' % gdata.GDATA_NAMESPACE] = ('feed_link',
500
_attributes['rel'] = 'rel'
502
def __init__(self, rel=None, feed_link=None, extension_elements=None,
503
extension_attributes=None, text=None):
505
self.feed_link = feed_link
507
self.extension_elements = extension_elements or []
508
self.extension_attributes = extension_attributes or {}
511
class EventStatus(UriEnumElement):
512
"""The Google Calendar eventStatus element"""
515
_namespace = gdata.GDATA_NAMESPACE
516
_children = UriEnumElement._children.copy()
517
_attributes = UriEnumElement._attributes.copy()
519
status_enum = { 'http://schemas.google.com/g/2005#event.canceled' : 'CANCELED',
520
'http://schemas.google.com/g/2005#event.confirmed' : 'CONFIRMED',
521
'http://schemas.google.com/g/2005#event.tentative' : 'TENTATIVE'}
523
def __init__(self, extension_elements=None,
524
extension_attributes=None, text=None):
525
UriEnumElement.__init__(self, tag='eventStatus',
526
enum_map=EventStatus.status_enum,
527
extension_elements=extension_elements,
528
extension_attributes=extension_attributes,
531
class Who(UriEnumElement):
532
"""The Google Calendar Who element"""
535
_namespace = gdata.GDATA_NAMESPACE
536
_children = UriEnumElement._children.copy()
537
_attributes = UriEnumElement._attributes.copy()
538
_children['{%s}attendeeStatus' % gdata.GDATA_NAMESPACE] = (
539
'attendee_status', AttendeeStatus)
540
_children['{%s}attendeeType' % gdata.GDATA_NAMESPACE] = ('attendee_type',
542
_attributes['valueString'] = 'name'
543
_attributes['email'] = 'email'
545
relEnum = { 'http://schemas.google.com/g/2005#event.attendee' : 'ATTENDEE',
546
'http://schemas.google.com/g/2005#event.organizer' : 'ORGANIZER',
547
'http://schemas.google.com/g/2005#event.performer' : 'PERFORMER',
548
'http://schemas.google.com/g/2005#event.speaker' : 'SPEAKER',
549
'http://schemas.google.com/g/2005#message.bcc' : 'BCC',
550
'http://schemas.google.com/g/2005#message.cc' : 'CC',
551
'http://schemas.google.com/g/2005#message.from' : 'FROM',
552
'http://schemas.google.com/g/2005#message.reply-to' : 'REPLY_TO',
553
'http://schemas.google.com/g/2005#message.to' : 'TO' }
555
def __init__(self, extension_elements=None,
556
extension_attributes=None, text=None):
557
UriEnumElement.__init__(self, 'who', Who.relEnum, attrib_name='rel',
558
extension_elements=extension_elements,
559
extension_attributes=extension_attributes,
563
self.attendee_status=None
564
self.attendee_type=None
568
class OriginalEvent(atom.AtomBase):
569
"""The Google Calendar OriginalEvent element"""
571
_tag = 'originalEvent'
572
_namespace = gdata.GDATA_NAMESPACE
573
_children = atom.AtomBase._children.copy()
574
_attributes = atom.AtomBase._attributes.copy()
575
# TODO: The when tag used to map to a EntryLink, make sure it should really be a When.
576
_children['{%s}when' % gdata.GDATA_NAMESPACE] = ('when', When)
577
_attributes['id'] = 'id'
578
_attributes['href'] = 'href'
580
def __init__(self, id=None, href=None, when=None,
581
extension_elements=None, extension_attributes=None, text=None):
586
self.extension_elements = extension_elements or []
587
self.extension_attributes = extension_attributes or {}
590
def GetCalendarEventEntryClass():
591
return CalendarEventEntry
593
# This class is not completely defined here, because of a circular reference
594
# in which CalendarEventEntryLink and CalendarEventEntry refer to one another.
595
class CalendarEventEntryLink(gdata.EntryLink):
596
"""An entryLink which contains a calendar event entry
598
Within an event's recurranceExceptions, an entry link
599
points to a calendar event entry. This class exists
600
to capture the calendar specific extensions in the entry.
604
_namespace = gdata.GDATA_NAMESPACE
605
_children = gdata.EntryLink._children.copy()
606
_attributes = gdata.EntryLink._attributes.copy()
607
# The CalendarEventEntryLink should like CalendarEventEntry as a child but
608
# that class hasn't been defined yet, so we will wait until after defining
609
# CalendarEventEntry to list it in _children.
612
class RecurrenceException(atom.AtomBase):
613
"""The Google Calendar RecurrenceException element"""
615
_tag = 'recurrenceException'
616
_namespace = gdata.GDATA_NAMESPACE
617
_children = atom.AtomBase._children.copy()
618
_attributes = atom.AtomBase._attributes.copy()
619
_children['{%s}entryLink' % gdata.GDATA_NAMESPACE] = ('entry_link',
620
CalendarEventEntryLink)
621
_children['{%s}originalEvent' % gdata.GDATA_NAMESPACE] = ('original_event',
623
_attributes['specialized'] = 'specialized'
625
def __init__(self, specialized=None, entry_link=None,
626
original_event=None, extension_elements=None,
627
extension_attributes=None, text=None):
628
self.specialized = specialized
629
self.entry_link = entry_link
630
self.original_event = original_event
632
self.extension_elements = extension_elements or []
633
self.extension_attributes = extension_attributes or {}
636
class SendEventNotifications(atom.AtomBase):
637
"""The Google Calendar sendEventNotifications element"""
639
_tag = 'sendEventNotifications'
640
_namespace = GCAL_NAMESPACE
641
_children = atom.AtomBase._children.copy()
642
_attributes = atom.AtomBase._attributes.copy()
643
_attributes['value'] = 'value'
645
def __init__(self, extension_elements=None,
646
value=None, extension_attributes=None, text=None):
649
self.extension_elements = extension_elements or []
650
self.extension_attributes = extension_attributes or {}
652
class QuickAdd(atom.AtomBase):
653
"""The Google Calendar quickadd element"""
656
_namespace = GCAL_NAMESPACE
657
_children = atom.AtomBase._children.copy()
658
_attributes = atom.AtomBase._attributes.copy()
659
_attributes['value'] = 'value'
661
def __init__(self, extension_elements=None,
662
value=None, extension_attributes=None, text=None):
665
self.extension_elements = extension_elements or []
666
self.extension_attributes = extension_attributes or {}
668
def _TransferToElementTree(self, element_tree):
670
element_tree.attrib['value'] = self.value
671
element_tree.tag = GCAL_TEMPLATE % 'quickadd'
672
atom.AtomBase._TransferToElementTree(self, element_tree)
675
def _TakeAttributeFromElementTree(self, attribute, element_tree):
676
if attribute == 'value':
677
self.value = element_tree.attrib[attribute]
678
del element_tree.attrib[attribute]
680
atom.AtomBase._TakeAttributeFromElementTree(self, attribute,
684
class WebContentGadgetPref(atom.AtomBase):
686
_tag = 'webContentGadgetPref'
687
_namespace = GCAL_NAMESPACE
688
_children = atom.AtomBase._children.copy()
689
_attributes = atom.AtomBase._attributes.copy()
690
_attributes['name'] = 'name'
691
_attributes['value'] = 'value'
693
"""The Google Calendar Web Content Gadget Preferences element"""
695
def __init__(self, name=None, value=None, extension_elements=None,
696
extension_attributes=None, text=None):
700
self.extension_elements = extension_elements or []
701
self.extension_attributes = extension_attributes or {}
704
class WebContent(atom.AtomBase):
707
_namespace = GCAL_NAMESPACE
708
_children = atom.AtomBase._children.copy()
709
_attributes = atom.AtomBase._attributes.copy()
710
_children['{%s}webContentGadgetPref' % GCAL_NAMESPACE] = ('gadget_pref',
711
[WebContentGadgetPref])
712
_attributes['url'] = 'url'
713
_attributes['width'] = 'width'
714
_attributes['height'] = 'height'
716
def __init__(self, url=None, width=None, height=None, text=None,
717
gadget_pref=None, extension_elements=None, extension_attributes=None):
722
self.gadget_pref = gadget_pref or []
723
self.extension_elements = extension_elements or []
724
self.extension_attributes = extension_attributes or {}
727
class WebContentLink(atom.Link):
730
_namespace = atom.ATOM_NAMESPACE
731
_children = atom.Link._children.copy()
732
_attributes = atom.Link._attributes.copy()
733
_children['{%s}webContent' % GCAL_NAMESPACE] = ('web_content', WebContent)
735
def __init__(self, title=None, href=None, link_type=None,
737
atom.Link.__init__(self, rel=WEB_CONTENT_LINK_REL, title=title, href=href,
739
self.web_content = web_content
742
class CalendarEventEntry(gdata.BatchEntry):
743
"""A Google Calendar flavor of an Atom Entry """
745
_tag = gdata.BatchEntry._tag
746
_namespace = gdata.BatchEntry._namespace
747
_children = gdata.BatchEntry._children.copy()
748
_attributes = gdata.BatchEntry._attributes.copy()
749
# This class also contains WebContentLinks but converting those members
750
# is handled in a special version of _ConvertElementTreeToMember.
751
_children['{%s}where' % gdata.GDATA_NAMESPACE] = ('where', [Where])
752
_children['{%s}when' % gdata.GDATA_NAMESPACE] = ('when', [When])
753
_children['{%s}who' % gdata.GDATA_NAMESPACE] = ('who', [Who])
754
_children['{%s}extendedProperty' % gdata.GDATA_NAMESPACE] = (
755
'extended_property', [ExtendedProperty])
756
_children['{%s}visibility' % gdata.GDATA_NAMESPACE] = ('visibility',
758
_children['{%s}transparency' % gdata.GDATA_NAMESPACE] = ('transparency',
760
_children['{%s}eventStatus' % gdata.GDATA_NAMESPACE] = ('event_status',
762
_children['{%s}recurrence' % gdata.GDATA_NAMESPACE] = ('recurrence',
764
_children['{%s}recurrenceException' % gdata.GDATA_NAMESPACE] = (
765
'recurrence_exception', [RecurrenceException])
766
_children['{%s}sendEventNotifications' % GCAL_NAMESPACE] = (
767
'send_event_notifications', SendEventNotifications)
768
_children['{%s}quickadd' % GCAL_NAMESPACE] = ('quick_add', QuickAdd)
769
_children['{%s}comments' % gdata.GDATA_NAMESPACE] = ('comments', Comments)
770
_children['{%s}originalEvent' % gdata.GDATA_NAMESPACE] = ('original_event',
773
def __init__(self, author=None, category=None, content=None,
774
atom_id=None, link=None, published=None,
775
title=None, updated=None,
776
transparency=None, comments=None, event_status=None,
777
send_event_notifications=None, visibility=None,
778
recurrence=None, recurrence_exception=None,
779
where=None, when=None, who=None, quick_add=None,
780
extended_property=None, original_event=None,
781
batch_operation=None, batch_id=None, batch_status=None,
782
extension_elements=None, extension_attributes=None, text=None):
784
gdata.BatchEntry.__init__(self, author=author, category=category,
786
atom_id=atom_id, link=link, published=published,
787
batch_operation=batch_operation, batch_id=batch_id,
788
batch_status=batch_status,
789
title=title, updated=updated)
791
self.transparency = transparency
792
self.comments = comments
793
self.event_status = event_status
794
self.send_event_notifications = send_event_notifications
795
self.visibility = visibility
796
self.recurrence = recurrence
797
self.recurrence_exception = recurrence_exception or []
798
self.where = where or []
799
self.when = when or []
801
self.quick_add = quick_add
802
self.extended_property = extended_property or []
803
self.original_event = original_event
805
self.extension_elements = extension_elements or []
806
self.extension_attributes = extension_attributes or {}
808
# We needed to add special logic to _ConvertElementTreeToMember because we
809
# want to make links with a rel of WEB_CONTENT_LINK_REL into a
811
def _ConvertElementTreeToMember(self, child_tree):
812
# Special logic to handle Web Content links
813
if (child_tree.tag == '{%s}link' % atom.ATOM_NAMESPACE and
814
child_tree.attrib['rel'] == WEB_CONTENT_LINK_REL):
815
if self.link is None:
817
self.link.append(atom._CreateClassFromElementTree(WebContentLink,
820
# Find the element's tag in this class's list of child members
821
if self.__class__._children.has_key(child_tree.tag):
822
member_name = self.__class__._children[child_tree.tag][0]
823
member_class = self.__class__._children[child_tree.tag][1]
824
# If the class member is supposed to contain a list, make sure the
825
# matching member is set to a list, then append the new member
826
# instance to the list.
827
if isinstance(member_class, list):
828
if getattr(self, member_name) is None:
829
setattr(self, member_name, [])
830
getattr(self, member_name).append(atom._CreateClassFromElementTree(
831
member_class[0], child_tree))
833
setattr(self, member_name,
834
atom._CreateClassFromElementTree(member_class, child_tree))
836
atom.ExtensionContainer._ConvertElementTreeToMember(self, child_tree)
839
def GetWebContentLink(self):
840
"""Finds the first link with rel set to WEB_CONTENT_REL
843
A gdata.calendar.WebContentLink or none if none of the links had rel
844
equal to WEB_CONTENT_REL
847
for a_link in self.link:
848
if a_link.rel == WEB_CONTENT_LINK_REL:
853
def CalendarEventEntryFromString(xml_string):
854
return atom.CreateClassFromXMLString(CalendarEventEntry, xml_string)
857
def CalendarEventCommentEntryFromString(xml_string):
858
return atom.CreateClassFromXMLString(CalendarEventCommentEntry, xml_string)
861
CalendarEventEntryLink._children = {'{%s}entry' % atom.ATOM_NAMESPACE:
862
('entry', CalendarEventEntry)}
865
def CalendarEventEntryLinkFromString(xml_string):
866
return atom.CreateClassFromXMLString(CalendarEventEntryLink, xml_string)
869
class CalendarEventFeed(gdata.BatchFeed, gdata.LinkFinder):
870
"""A Google Calendar event feed flavor of an Atom Feed"""
872
_tag = gdata.BatchFeed._tag
873
_namespace = gdata.BatchFeed._namespace
874
_children = gdata.BatchFeed._children.copy()
875
_attributes = gdata.BatchFeed._attributes.copy()
876
_children['{%s}entry' % atom.ATOM_NAMESPACE] = ('entry',
877
[CalendarEventEntry])
879
def __init__(self, author=None, category=None, contributor=None,
880
generator=None, icon=None, atom_id=None, link=None, logo=None,
881
rights=None, subtitle=None, title=None, updated=None, entry=None,
882
total_results=None, start_index=None, items_per_page=None,
884
extension_elements=None, extension_attributes=None, text=None):
885
gdata.BatchFeed.__init__(self, author=author, category=category,
886
contributor=contributor, generator=generator,
887
icon=icon, atom_id=atom_id, link=link,
888
logo=logo, rights=rights, subtitle=subtitle,
889
title=title, updated=updated, entry=entry,
890
total_results=total_results,
891
start_index=start_index,
892
items_per_page=items_per_page,
893
interrupted=interrupted,
894
extension_elements=extension_elements,
895
extension_attributes=extension_attributes,
899
def CalendarListEntryFromString(xml_string):
900
return atom.CreateClassFromXMLString(CalendarListEntry, xml_string)
903
def CalendarAclEntryFromString(xml_string):
904
return atom.CreateClassFromXMLString(CalendarAclEntry, xml_string)
907
def CalendarListFeedFromString(xml_string):
908
return atom.CreateClassFromXMLString(CalendarListFeed, xml_string)
911
def CalendarAclFeedFromString(xml_string):
912
return atom.CreateClassFromXMLString(CalendarAclFeed, xml_string)
915
def CalendarEventFeedFromString(xml_string):
916
return atom.CreateClassFromXMLString(CalendarEventFeed, xml_string)
919
def CalendarEventCommentFeedFromString(xml_string):
920
return atom.CreateClassFromXMLString(CalendarEventCommentFeed, xml_string)
923
# Code to create atom feeds from element trees
924
#_CalendarListFeedFromElementTree = atom._AtomInstanceFromElementTree(
925
# CalendarListFeed, 'feed', atom.ATOM_NAMESPACE)
926
#_CalendarListEntryFromElementTree = atom._AtomInstanceFromElementTree(
927
# CalendarListEntry, 'entry', atom.ATOM_NAMESPACE)
928
#_CalendarAclFeedFromElementTree = atom._AtomInstanceFromElementTree(
929
# CalendarAclFeed, 'feed', atom.ATOM_NAMESPACE)
930
#_CalendarAclEntryFromElementTree = atom._AtomInstanceFromElementTree(
931
# CalendarAclEntry, 'entry', atom.ATOM_NAMESPACE)
932
#_CalendarEventFeedFromElementTree = atom._AtomInstanceFromElementTree(
933
# CalendarEventFeed, 'feed', atom.ATOM_NAMESPACE)
934
#_CalendarEventEntryFromElementTree = atom._AtomInstanceFromElementTree(
935
# CalendarEventEntry, 'entry', atom.ATOM_NAMESPACE)
936
#_CalendarEventCommentFeedFromElementTree = atom._AtomInstanceFromElementTree(
937
# CalendarEventCommentFeed, 'feed', atom.ATOM_NAMESPACE)
938
#_CalendarEventCommentEntryFromElementTree = atom._AtomInstanceFromElementTree(
939
# CalendarEventCommentEntry, 'entry', atom.ATOM_NAMESPACE)
940
#_WhereFromElementTree = atom._AtomInstanceFromElementTree(
941
# Where, 'where', gdata.GDATA_NAMESPACE)
942
#_WhenFromElementTree = atom._AtomInstanceFromElementTree(
943
# When, 'when', gdata.GDATA_NAMESPACE)
944
#_WhoFromElementTree = atom._AtomInstanceFromElementTree(
945
# Who, 'who', gdata.GDATA_NAMESPACE)
946
#_VisibilityFromElementTree= atom._AtomInstanceFromElementTree(
947
# Visibility, 'visibility', gdata.GDATA_NAMESPACE)
948
#_TransparencyFromElementTree = atom._AtomInstanceFromElementTree(
949
# Transparency, 'transparency', gdata.GDATA_NAMESPACE)
950
#_CommentsFromElementTree = atom._AtomInstanceFromElementTree(
951
# Comments, 'comments', gdata.GDATA_NAMESPACE)
952
#_EventStatusFromElementTree = atom._AtomInstanceFromElementTree(
953
# EventStatus, 'eventStatus', gdata.GDATA_NAMESPACE)
954
#_SendEventNotificationsFromElementTree = atom._AtomInstanceFromElementTree(
955
# SendEventNotifications, 'sendEventNotifications', GCAL_NAMESPACE)
956
#_QuickAddFromElementTree = atom._AtomInstanceFromElementTree(
957
# QuickAdd, 'quickadd', GCAL_NAMESPACE)
958
#_AttendeeStatusFromElementTree = atom._AtomInstanceFromElementTree(
959
# AttendeeStatus, 'attendeeStatus', gdata.GDATA_NAMESPACE)
960
#_AttendeeTypeFromElementTree = atom._AtomInstanceFromElementTree(
961
# AttendeeType, 'attendeeType', gdata.GDATA_NAMESPACE)
962
#_ExtendedPropertyFromElementTree = atom._AtomInstanceFromElementTree(
963
# ExtendedProperty, 'extendedProperty', gdata.GDATA_NAMESPACE)
964
#_RecurrenceFromElementTree = atom._AtomInstanceFromElementTree(
965
# Recurrence, 'recurrence', gdata.GDATA_NAMESPACE)
966
#_RecurrenceExceptionFromElementTree = atom._AtomInstanceFromElementTree(
967
# RecurrenceException, 'recurrenceException', gdata.GDATA_NAMESPACE)
968
#_OriginalEventFromElementTree = atom._AtomInstanceFromElementTree(
969
# OriginalEvent, 'originalEvent', gdata.GDATA_NAMESPACE)
970
#_ColorFromElementTree = atom._AtomInstanceFromElementTree(
971
# Color, 'color', GCAL_NAMESPACE)
972
#_HiddenFromElementTree = atom._AtomInstanceFromElementTree(
973
# Hidden, 'hidden', GCAL_NAMESPACE)
974
#_SelectedFromElementTree = atom._AtomInstanceFromElementTree(
975
# Selected, 'selected', GCAL_NAMESPACE)
976
#_TimezoneFromElementTree = atom._AtomInstanceFromElementTree(
977
# Timezone, 'timezone', GCAL_NAMESPACE)
978
#_AccessLevelFromElementTree = atom._AtomInstanceFromElementTree(
979
# AccessLevel, 'accesslevel', GCAL_NAMESPACE)
980
#_ReminderFromElementTree = atom._AtomInstanceFromElementTree(
981
# Reminder, 'reminder', gdata.GDATA_NAMESPACE)
982
#_ScopeFromElementTree = atom._AtomInstanceFromElementTree(
983
# Scope, 'scope', GACL_NAMESPACE)
984
#_RoleFromElementTree = atom._AtomInstanceFromElementTree(
985
# Role, 'role', GACL_NAMESPACE)
986
#_WebContentLinkFromElementTree = atom._AtomInstanceFromElementTree(
987
# WebContentLink, 'link', atom.ATOM_NAMESPACE)
988
#_WebContentFromElementTree = atom._AtomInstanceFromElementTree(
989
# WebContent, 'webContent', GCAL_NAMESPACE)
990
#_WebContentGadgetPrefFromElementTree = atom._AtomInstanceFromElementTree(
991
# WebContentGadgetPref, 'webContentGadgetPref', GCAL_NAMESPACE)