Back to index

plone3  3.1.7
interfaces.py
Go to the documentation of this file.
00001 try:
00002     from zope.interface import Interface, Attribute
00003 except ImportError:
00004     class Interface:
00005         """A dummy interface base class"""
00006 
00007     class Attribute:
00008         """A dummy attribute implementation"""
00009         def __init__(self, doc):
00010             self.doc = doc
00011 
00012 _marker = object()
00013 
00014 class IComponent(Interface):
00015     """
00016     Component is the base object for calendar, Event and the other
00017     components defined in RFC 2445.
00018 
00019     A component is like a dictionary with extra methods and attributes.
00020     """
00021 
00022     # MANIPULATORS
00023 
00024     def __setitem__(name, value):
00025         """Set a property.
00026 
00027         name - case insensitive name
00028         value - value of the property to set. This can be either a single
00029         item or a list.
00030 
00031         Some iCalendar properties are set INLINE; these properties
00032         have multiple values on one property line in the iCalendar
00033         representation.  The list can be supplied as a comma separated
00034         string to __setitem__. If special iCalendar characters exist in
00035         an entry, such as the colon (:) and (,), that comma-separated
00036         entry needs to be quoted with double quotes. For example:
00037 
00038         'foo, bar, "baz:hoi"'
00039 
00040         See also set_inline() for an easier way to deal with this case.
00041         """
00042 
00043     def set_inline(name, values, encode=1):
00044         """Set list of INLINE values for property.
00045 
00046         Converts a list of values into valid iCalendar comma seperated
00047         string and sets value to that.
00048 
00049         name - case insensitive name of property
00050         values - list of values to set
00051         encode - if True, encode Python values as iCalendar types first.
00052         """
00053 
00054     def add(name, value):
00055         """Add a property. Can be called multiple times to set a list.
00056 
00057         name - case insensitive name
00058         value - value of property to set or add to list for this property.
00059         """
00060 
00061     def add_component(component):
00062         """Add a nested subcomponent to this component.
00063         """
00064 
00065     # static method, can be called on class directly
00066     def from_string(st, multiple=False):
00067         """Populates the component recursively from a iCalendar string.
00068 
00069         Reads the iCalendar string and constructs components and
00070         subcomponents out of it.
00071         """
00072 
00073     # ACCESSORS
00074     def __getitem__(name):
00075         """Get a property
00076 
00077         name - case insensitive name
00078 
00079         Returns an iCalendar property object such as vText.
00080         """
00081 
00082     def decoded(name, default=_marker):
00083         """Get a property as a python object.
00084 
00085         name - case insensitive name
00086         default - optional argument. If supplied, will use this if
00087         name cannot be found. If not supplied, decoded will raise a
00088         KeyError if name cannot be found.
00089 
00090         Returns python object (such as unicode string, datetime, etc).
00091         """
00092 
00093     def get_inline(name, decode=1):
00094         """Get list of INLINE values from property.
00095 
00096         name - case insensitive name
00097         decode - decode to Python objects.
00098 
00099         Returns list of python objects.
00100         """
00101 
00102     def as_string():
00103         """Render the component in the RFC 2445 (iCalendar) format.
00104 
00105         Returns a string in RFC 2445 format.
00106         """
00107 
00108     subcomponents = Attribute("""
00109         A list of all subcomponents of this component,
00110         added using add_component()""")
00111 
00112     name = Attribute("""
00113         Name of this component (VEVENT, etc)
00114         """)
00115 
00116     def walk(name=None):
00117         """Recursively traverses component and subcomponents.
00118 
00119         name - optional, if given, only return components with that name
00120 
00121         Returns sequence of components.
00122         """
00123 
00124     def property_items():
00125         """Return properties as (name, value) tuples.
00126 
00127         Returns all properties in this comopnent and subcomponents as
00128         name, value tuples.
00129         """
00130 
00131 class IEvent(IComponent):
00132     """A component which conforms to an iCalendar VEVENT.
00133     """
00134 
00135 class ITodo(IComponent):
00136     """A component which conforms to an iCalendar VTODO.
00137     """
00138 
00139 class IJournal(IComponent):
00140     """A component which conforms to an iCalendar VJOURNAL.
00141     """
00142 
00143 class IFreeBusy(IComponent):
00144     """A component which conforms to an iCalendar VFREEBUSY.
00145     """
00146 
00147 class ITimezone(IComponent):
00148     """A component which conforms to an iCalendar VTIMEZONE.
00149     """
00150 
00151 class IAlarm(IComponent):
00152     """A component which conforms to an iCalendar VALARM.
00153     """
00154 
00155 class ICalendar(IComponent):
00156     """A component which conforms to an iCalendar VCALENDAR.
00157     """
00158 
00159 class IPropertyValue(Interface):
00160     """An iCalendar property value.
00161     iCalendar properties have strongly typed values.
00162 
00163     This invariance should always be true:
00164 
00165     assert x == vDataType.from_ical(vDataType(x).ical())
00166     """
00167 
00168     def ical():
00169         """Render property as string, as defined in iCalendar RFC 2445.
00170         """
00171 
00172     # this is a static method
00173     def from_ical(ical):
00174         """Parse property from iCalendar RFC 2445 text.
00175 
00176         Inverse of ical().
00177         """
00178 
00179 class IBinary(IPropertyValue):
00180     """Binary property values are base 64 encoded
00181     """
00182 
00183 class IBoolean(IPropertyValue):
00184     """Boolean property.
00185 
00186     Also behaves like a python int.
00187     """
00188 
00189 class ICalAddress(IPropertyValue):
00190     """Email address.
00191 
00192     Also behaves like a python str.
00193     """
00194 
00195 class IDateTime(IPropertyValue):
00196     """Render and generates iCalendar datetime format.
00197 
00198     Important: if tzinfo is defined it renders itself as 'date with utc time'
00199     Meaning that it has a 'Z' appended, and is in absolute time.
00200     """
00201 
00202 class IDate(IPropertyValue):
00203     """Render and generates iCalendar date format.
00204     """
00205 
00206 class IDuration(IPropertyValue):
00207     """Render and generates timedelta in iCalendar DURATION format.
00208     """
00209 
00210 class IFloat(IPropertyValue):
00211     """Render and generate floats in iCalendar format.
00212 
00213     Also behaves like a python float.
00214     """
00215 
00216 class IInt(IPropertyValue):
00217     """Render and generate ints in iCalendar format.
00218 
00219     Also behaves like a python int.
00220     """
00221 
00222 class IPeriod(IPropertyValue):
00223     """A precise period of time (datetime, datetime).
00224     """
00225 
00226 class IWeekDay(IPropertyValue):
00227     """Render and generate weekday abbreviation.
00228     """
00229 
00230 class IFrequency(IPropertyValue):
00231     """Frequency.
00232     """
00233 
00234 class IRecur(IPropertyValue):
00235     """Render and generate data based on recurrent event representation.
00236 
00237     This acts like a caseless dictionary.
00238     """
00239 
00240 class IText(IPropertyValue):
00241     """Unicode text.
00242     """
00243 
00244 class ITime(IPropertyValue):
00245     """Time.
00246     """
00247 
00248 class IUri(IPropertyValue):
00249     """URI
00250     """
00251 
00252 class IGeo(IPropertyValue):
00253     """Geographical location.
00254     """
00255 
00256 class IUTCOffset(IPropertyValue):
00257     """Offset from UTC.
00258     """
00259 
00260 class IInline(IPropertyValue):
00261     """Inline list.
00262     """