1.1 --- a/imiptools/data.py Tue Dec 20 16:43:44 2016 +0100
1.2 +++ b/imiptools/data.py Tue Dec 20 23:21:56 2016 +0100
1.3 @@ -27,8 +27,8 @@
1.4 get_datetime_tzid, \
1.5 get_duration, get_period, get_period_item, \
1.6 get_recurrence_start_point, \
1.7 - get_time, get_tzid, to_datetime, to_timezone, \
1.8 - to_utc_datetime
1.9 + get_time, get_timestamp, get_tzid, to_datetime, \
1.10 + to_timezone, to_utc_datetime
1.11 from imiptools.period import FreeBusyPeriod, Period, RecurringPeriod
1.12 from vCalendar import iterwrite, parse, ParseError, to_dict, to_node
1.13 from vRecurrence import get_parameters, get_rule
1.14 @@ -61,6 +61,10 @@
1.15 Then, the specific object must be presented as follows:
1.16
1.17 object = Object({"VEVENT" : event})
1.18 +
1.19 + A convienience function is also provided to initialise objects:
1.20 +
1.21 + object = new_object("VEVENT")
1.22 """
1.23
1.24 self.objtype, (self.details, self.attr) = fragment.items()[0]
1.25 @@ -119,8 +123,19 @@
1.26
1.27 # Structure access.
1.28
1.29 + def add(self, obj):
1.30 +
1.31 + "Add 'obj' to the structure."
1.32 +
1.33 + name = obj.objtype
1.34 + if not self.details.has_key(name):
1.35 + l = self.details[name] = []
1.36 + else:
1.37 + l = self.details[name]
1.38 + l.append((obj.details, obj.attr))
1.39 +
1.40 def copy(self):
1.41 - return Object(to_dict(self.to_node()))
1.42 + return Object(self.to_dict())
1.43
1.44 def get_items(self, name, all=True):
1.45 return get_items(self.details, name, all)
1.46 @@ -163,6 +178,9 @@
1.47
1.48 # Serialisation.
1.49
1.50 + def to_dict(self):
1.51 + return to_dict(self.to_node())
1.52 +
1.53 def to_node(self):
1.54 return to_node({self.objtype : [(self.details, self.attr)]})
1.55
1.56 @@ -714,6 +732,19 @@
1.57 finally:
1.58 out.close()
1.59
1.60 +def new_object(object_type):
1.61 +
1.62 + "Make a new object of the given 'object_type'."
1.63 +
1.64 + return Object({object_type : ({}, {})})
1.65 +
1.66 +def make_uid(user):
1.67 +
1.68 + "Return a unique identifier for a new object by the given 'user'."
1.69 +
1.70 + utcnow = get_timestamp()
1.71 + return "imip-agent-%s-%s" % (utcnow, get_address(user))
1.72 +
1.73 # Structure access functions.
1.74
1.75 def get_items(d, name, all=True):