# HG changeset patch # User Paul Boddie # Date 1461276373 -7200 # Node ID 5eadf6e5f94047b1c43d05ba4680b29ab898a6ab # Parent a82971fddeab7ddaa2bff521d76312022cea214e Convert strings originating from the database to Unicode for free/busy periods. diff -r a82971fddeab -r 5eadf6e5f940 imiptools/period.py --- a/imiptools/period.py Thu Apr 21 23:41:54 2016 +0200 +++ b/imiptools/period.py Fri Apr 22 00:06:13 2016 +0200 @@ -34,6 +34,15 @@ if x is None: return y else: return x +def from_strings(t, encoding): + return tuple([from_string(s, encoding) for s in t]) + +def from_string(s, encoding): + if s: + return unicode(s, encoding) + else: + return s + def to_string(s, encoding): if s: return s.encode(encoding) @@ -862,6 +871,9 @@ self.cursor = cursor self.table_name = table_name + def make_period(self, t): + return FreeBusyPeriod(*from_strings(t, "utf-8")) + # List emulation methods. def __nonzero__(self): @@ -874,7 +886,7 @@ "table" : self.table_name }) self.cursor.execute(query, values) - return iter(map(lambda t: FreeBusyPeriod(*t), self.cursor.fetchall())) + return iter(map(lambda t: self.make_period(t), self.cursor.fetchall())) def __len__(self): query, values = self.get_query( @@ -958,7 +970,7 @@ self.cursor.execute(query, values) - return map(lambda t: FreeBusyPeriod(*t), removed) + return map(lambda t: self.make_period(t), removed) def remove_additional_periods(self, uid, recurrenceids=None): @@ -997,7 +1009,7 @@ self.cursor.execute(query, values) - return map(lambda t: FreeBusyPeriod(*t), removed) + return map(lambda t: self.make_period(t), removed) def remove_affected_period(self, uid, start): @@ -1035,7 +1047,7 @@ self.cursor.execute(query, values) - return map(lambda t: FreeBusyPeriod(*t), removed) + return map(lambda t: self.make_period(t), removed) def periods_from(self, period): @@ -1058,7 +1070,7 @@ self.cursor.execute(query, values) - return map(lambda t: FreeBusyPeriod(*t), self.cursor.fetchall()) + return map(lambda t: self.make_period(t), self.cursor.fetchall()) def periods_until(self, period): @@ -1081,7 +1093,7 @@ self.cursor.execute(query, values) - return map(lambda t: FreeBusyPeriod(*t), self.cursor.fetchall()) + return map(lambda t: self.make_period(t), self.cursor.fetchall()) def get_overlapping(self, period): @@ -1101,7 +1113,7 @@ self.cursor.execute(query, values) - return map(lambda t: FreeBusyPeriod(*t), self.cursor.fetchall()) + return map(lambda t: self.make_period(t), self.cursor.fetchall()) def remove_overlapping(self, period):