3 #======================================================================
4 # FILE: DerivedProperties.py
10 # $Id: DerivedProperties.py,v 1.4 2001-04-03 15:18:42 ebusboom Exp $
13 # (C) COPYRIGHT 2001, Eric Busboom <eric@softwarestudio.org>
14 # (C) COPYRIGHT 2001, Patrick Lewis <plewis@inetarena.com>
16 # This program is free software; you can redistribute it and/or modify
17 # it under the terms of either:
19 # The LGPL as published by the Free Software Foundation, version
20 # 2.1, available at: http://www.fsf.org/copyleft/lesser.html
24 # The Mozilla Public License Version 1.0. You may obtain a copy of
25 # the License at http://www.mozilla.org/MPL/
26 #======================================================================
28 from Property import Property
30 from Period import Period
31 from Duration import Duration
35 class RDate_Time(Time):
36 def __init__(self,arg): Time.__init__(self,arg,"RDATE")
38 class RDate_Period(Period):
39 def __init__(self,arg): Period.__init__(self,arg,"RDATE")
42 for c in [RDate_Time, RDate_Period]:
44 except Property.ConstructorFailedError, d: pass
45 raise Property.ConstructorFailedError("Failed to construct RDATE from "+str(arg))
49 class Trigger_Time(Time):
50 def __init__(self,arg): Time.__init__(self,arg,"TRIGGER")
52 class Trigger_Duration(Duration):
53 def __init__(self,arg): Duration.__init__(self,arg,"TRIGGER")
56 for c in [Trigger_Duration, Trigger_Time]:
58 except Property.ConstructorFailedError, d: pass
59 raise Property.ConstructorFailedError("Failed to construct TRIGGER from "+str(arg))
63 class Recurrence_Id(Time):
64 """Class for RECURRENCE-ID property.
67 Reccurence_Id(dict) # A normal property dictionary
68 Reccurence_Id("19960401") # An iCalendar string
69 Reccurence_Id(8349873494) # Seconds from epoch
71 If the 'dict' constructor is used, 'name' and 'value_type'
72 entries in dict are ignored and automatically set with the appropriate
76 def __init__(self, dict={}):
77 Time.__init__(self, dict)
78 Property.name(self, 'RECURRENCE-ID')
81 return Property.name(self)
83 def _doParam(self, parameter, v):
86 return self[parameter]
88 # Enumerated parameters
89 def value_parameter(self, v=None):
90 """Sets or gets the VALUE parameter value.
92 The value passed should be either "DATE-TIME" or "DATE". Setting this
93 parameter has no impact on the property's value_type. Doing something
96 rid=Recurrence_Id("19960401") # Sets value & makes value_type="DATE"
97 rid.value_parameter("DATE-TIME") # Sets the parameter VALUE=DATE-TIME
99 Would be allowed (even though it is wrong), so pay attention.
100 Verifying the component will reveal the error.
102 if v!=None and v!="DATE" and v!="DATE-TIME":
103 raise ValueError, "%s is an invalid VALUE parameter value" % str(v)
104 self._doParam("VALUE", v)
106 def tzid(self, v=None):
107 "Sets or gets the TZID parameter value."
108 self._doParam("TZID", v)
110 def range_parameter(self, v=None): # 'range' is a builtin function
111 "Sets or gets the RANGE parameter value."
112 if v!=None and v!="THISANDPRIOR" and v!= "THISANDFUTURE":
113 raise ValueError, "%s is an invalid RANGE parameter value" % str(v)
114 self._doParam("RANGE", v)
116 class Attach(Property):
117 """A class representing an ATTACH property.
120 Attach(uriString [, parameter_dict])
121 Attach(fileObj [, parameter_dict])
124 def __init__(self, value=None, parameter_dict={}):
125 Property.__init__(self, parameter_dict)
126 Property.name(self, 'ATTACH')
129 def value(self, v=None):
130 "Returns or sets the value of the property."
132 if isinstance(v, StringType): # Is a URI
133 self._desc['value']=v
134 Property.value_type(self, 'URI')
139 raise TypeError,"%s must be a URL string or file-ish type"\
141 self._desc['value'] = base64.encodestring(tempStr)
142 Property.value_type(self, 'BINARY')
144 return self._desc['value']
147 "Returns the name of the property."
148 return Property.name(self)
150 def value_type(self):
151 return Property.value_type(self)
153 def fmttype(self, v=None):
154 "Gets or sets the FMTYPE parameter."
158 return self['FMTTYPE']