1.1 --- a/imiptools/period.py Thu Apr 21 23:41:54 2016 +0200
1.2 +++ b/imiptools/period.py Fri Apr 22 00:06:13 2016 +0200
1.3 @@ -34,6 +34,15 @@
1.4 if x is None: return y
1.5 else: return x
1.6
1.7 +def from_strings(t, encoding):
1.8 + return tuple([from_string(s, encoding) for s in t])
1.9 +
1.10 +def from_string(s, encoding):
1.11 + if s:
1.12 + return unicode(s, encoding)
1.13 + else:
1.14 + return s
1.15 +
1.16 def to_string(s, encoding):
1.17 if s:
1.18 return s.encode(encoding)
1.19 @@ -862,6 +871,9 @@
1.20 self.cursor = cursor
1.21 self.table_name = table_name
1.22
1.23 + def make_period(self, t):
1.24 + return FreeBusyPeriod(*from_strings(t, "utf-8"))
1.25 +
1.26 # List emulation methods.
1.27
1.28 def __nonzero__(self):
1.29 @@ -874,7 +886,7 @@
1.30 "table" : self.table_name
1.31 })
1.32 self.cursor.execute(query, values)
1.33 - return iter(map(lambda t: FreeBusyPeriod(*t), self.cursor.fetchall()))
1.34 + return iter(map(lambda t: self.make_period(t), self.cursor.fetchall()))
1.35
1.36 def __len__(self):
1.37 query, values = self.get_query(
1.38 @@ -958,7 +970,7 @@
1.39
1.40 self.cursor.execute(query, values)
1.41
1.42 - return map(lambda t: FreeBusyPeriod(*t), removed)
1.43 + return map(lambda t: self.make_period(t), removed)
1.44
1.45 def remove_additional_periods(self, uid, recurrenceids=None):
1.46
1.47 @@ -997,7 +1009,7 @@
1.48
1.49 self.cursor.execute(query, values)
1.50
1.51 - return map(lambda t: FreeBusyPeriod(*t), removed)
1.52 + return map(lambda t: self.make_period(t), removed)
1.53
1.54 def remove_affected_period(self, uid, start):
1.55
1.56 @@ -1035,7 +1047,7 @@
1.57
1.58 self.cursor.execute(query, values)
1.59
1.60 - return map(lambda t: FreeBusyPeriod(*t), removed)
1.61 + return map(lambda t: self.make_period(t), removed)
1.62
1.63 def periods_from(self, period):
1.64
1.65 @@ -1058,7 +1070,7 @@
1.66
1.67 self.cursor.execute(query, values)
1.68
1.69 - return map(lambda t: FreeBusyPeriod(*t), self.cursor.fetchall())
1.70 + return map(lambda t: self.make_period(t), self.cursor.fetchall())
1.71
1.72 def periods_until(self, period):
1.73
1.74 @@ -1081,7 +1093,7 @@
1.75
1.76 self.cursor.execute(query, values)
1.77
1.78 - return map(lambda t: FreeBusyPeriod(*t), self.cursor.fetchall())
1.79 + return map(lambda t: self.make_period(t), self.cursor.fetchall())
1.80
1.81 def get_overlapping(self, period):
1.82
1.83 @@ -1101,7 +1113,7 @@
1.84
1.85 self.cursor.execute(query, values)
1.86
1.87 - return map(lambda t: FreeBusyPeriod(*t), self.cursor.fetchall())
1.88 + return map(lambda t: self.make_period(t), self.cursor.fetchall())
1.89
1.90 def remove_overlapping(self, period):
1.91