PageRenderTime 18ms CodeModel.GetById 6ms app.highlight 8ms RepoModel.GetById 2ms app.codeStats 0ms

/gdata/calendar_resource/data.py

http://radioappz.googlecode.com/
Python | 202 lines | 67 code | 42 blank | 93 comment | 12 complexity | 7630148003132f2ffabc41557f74c8f6 MD5 | raw file
  1#!/usr/bin/python
  2#
  3# Copyright 2009 Google Inc. All Rights Reserved.
  4#
  5# Licensed under the Apache License, Version 2.0 (the "License");
  6# you may not use this file except in compliance with the License.
  7# You may obtain a copy of the License at
  8#
  9#      http://www.apache.org/licenses/LICENSE-2.0
 10#
 11# Unless required by applicable law or agreed to in writing, software
 12# distributed under the License is distributed on an "AS IS" BASIS,
 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14# See the License for the specific language governing permissions and
 15# limitations under the License.
 16
 17"""Data model classes for parsing and generating XML for the Calendar
 18Resource API."""
 19
 20
 21__author__ = 'Vic Fryzel <vf@google.com>'
 22
 23
 24import atom.core
 25import atom.data
 26import gdata.apps
 27import gdata.data
 28
 29
 30# This is required to work around a naming conflict between the Google
 31# Spreadsheets API and Python's built-in property function
 32pyproperty = property
 33
 34
 35# The apps:property name of the resourceId property
 36RESOURCE_ID_NAME = 'resourceId'
 37# The apps:property name of the resourceCommonName property
 38RESOURCE_COMMON_NAME_NAME = 'resourceCommonName'
 39# The apps:property name of the resourceDescription property
 40RESOURCE_DESCRIPTION_NAME = 'resourceDescription'
 41# The apps:property name of the resourceType property
 42RESOURCE_TYPE_NAME = 'resourceType'
 43
 44
 45class AppsProperty(atom.core.XmlElement):
 46  """Represents an <apps:property> element in a Calendar Resource feed."""
 47  _qname = gdata.apps.APPS_TEMPLATE % 'property'
 48  name = 'name'
 49  value = 'value'
 50
 51
 52class CalendarResourceEntry(gdata.data.GDEntry):
 53  """Represents a Calendar Resource entry in object form."""
 54
 55  property = [AppsProperty]
 56
 57  def _GetProperty(self, name):
 58    """Get the apps:property value with the given name.
 59
 60    Args:
 61      name: string Name of the apps:property value to get.
 62
 63    Returns:
 64      The apps:property value with the given name, or None if the name was
 65      invalid.
 66    """
 67
 68    value = None
 69    for p in self.property:
 70      if p.name == name:
 71        value = p.value
 72        break
 73    return value
 74  
 75  def _SetProperty(self, name, value):
 76    """Set the apps:property value with the given name to the given value.
 77
 78    Args:
 79      name: string Name of the apps:property value to set.
 80      value: string Value to give the apps:property value with the given name.
 81    """
 82
 83    found = False
 84    for i in range(len(self.property)):
 85      if self.property[i].name == name:
 86        self.property[i].value = value
 87        found = True
 88        break
 89    if not found:
 90      self.property.append(AppsProperty(name=name, value=value))
 91
 92  def GetResourceId(self):
 93    """Get the resource ID of this Calendar Resource object.
 94
 95    Returns:
 96      The resource ID of this Calendar Resource object as a string or None.
 97    """
 98
 99    return self._GetProperty(RESOURCE_ID_NAME)
100
101  def SetResourceId(self, value):
102    """Set the resource ID of this Calendar Resource object.
103
104    Args:
105      value: string The new resource ID value to give this object.
106    """
107
108    self._SetProperty(RESOURCE_ID_NAME, value)
109
110  resource_id = pyproperty(GetResourceId, SetResourceId)
111
112  def GetResourceCommonName(self):
113    """Get the common name of this Calendar Resource object.
114
115    Returns:
116      The common name of this Calendar Resource object as a string or None.
117    """
118
119    return self._GetProperty(RESOURCE_COMMON_NAME_NAME)
120
121  def SetResourceCommonName(self, value):
122    """Set the common name of this Calendar Resource object.
123
124    Args:
125      value: string The new common name value to give this object.
126    """
127
128    self._SetProperty(RESOURCE_COMMON_NAME_NAME, value)
129
130  resource_common_name = pyproperty(GetResourceCommonName,
131    SetResourceCommonName)
132
133  def GetResourceDescription(self):
134    """Get the description of this Calendar Resource object.
135
136    Returns:
137      The description of this Calendar Resource object as a string or None.
138    """
139
140    return self._GetProperty(RESOURCE_DESCRIPTION_NAME)
141
142  def SetResourceDescription(self, value):
143    """Set the description of this Calendar Resource object.
144    
145    Args:
146      value: string The new description value to give this object.
147    """
148
149    self._SetProperty(RESOURCE_DESCRIPTION_NAME, value)
150
151  resource_description = pyproperty(GetResourceDescription,
152    SetResourceDescription)
153
154  def GetResourceType(self):
155    """Get the type of this Calendar Resource object.
156
157    Returns:
158      The type of this Calendar Resource object as a string or None.
159    """
160
161    return self._GetProperty(RESOURCE_TYPE_NAME)
162
163  def SetResourceType(self, value):
164    """Set the type value of this Calendar Resource object.
165
166    Args:
167      value: string The new type value to give this object.
168    """
169
170    self._SetProperty(RESOURCE_TYPE_NAME, value)
171
172  resource_type = pyproperty(GetResourceType, SetResourceType)
173
174  def __init__(self, resource_id=None, resource_common_name=None,
175    resource_description=None, resource_type=None, *args, **kwargs):
176    """Constructs a new CalendarResourceEntry object with the given arguments.
177
178    Args:
179      resource_id: string (optional) The resource ID to give this new object.
180      resource_common_name: string (optional) The common name to give this new
181                            object.
182      resource_description: string (optional) The description to give this new
183                            object.
184      resource_type: string (optional) The type to give this new object.
185      args: The other parameters to pass to gdata.entry.GDEntry constructor. 
186      kwargs: The other parameters to pass to gdata.entry.GDEntry constructor. 
187    """
188    super(CalendarResourceEntry, self).__init__(*args, **kwargs)
189    if resource_id:
190      self.resource_id = resource_id
191    if resource_common_name:
192      self.resource_common_name = resource_common_name
193    if resource_description:
194      self.resource_description = resource_description
195    if resource_type:
196      self.resource_type = resource_type
197
198
199class CalendarResourceFeed(gdata.data.GDFeed):
200  """Represents a feed of CalendarResourceEntry objects."""
201
202  entry = [CalendarResourceEntry]