# HG changeset patch # User Paul Boddie # Date 1495633274 -7200 # Node ID 779e632b6e6982d2349e29e97f349283de18f63e # Parent 13b96d1200609348732ee17b322546b1d661d14d Return calendar objects from stores instead of fragments. diff -r 13b96d120060 -r 779e632b6e69 imiptools/client.py --- a/imiptools/client.py Tue May 23 22:15:05 2017 +0200 +++ b/imiptools/client.py Wed May 24 15:41:14 2017 +0200 @@ -246,10 +246,9 @@ """ if section == "counters": - fragment = self.store.get_counter(self.user, username, uid, recurrenceid) + return self.store.get_counter(self.user, username, uid, recurrenceid) else: - fragment = self.store.get_event(self.user, uid, recurrenceid, section) - return fragment and Object(fragment) + return self.store.get_event(self.user, uid, recurrenceid, section) # Free/busy operations. diff -r 13b96d120060 -r 779e632b6e69 imiptools/handlers/scheduling/quota.py --- a/imiptools/handlers/scheduling/quota.py Tue May 23 22:15:05 2017 +0200 +++ b/imiptools/handlers/scheduling/quota.py Wed May 24 15:41:14 2017 +0200 @@ -3,7 +3,7 @@ """ Quota-related scheduling functionality. -Copyright (C) 2016 Paul Boddie +Copyright (C) 2016, 2017 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -20,7 +20,7 @@ """ from imiptools.dates import get_duration, to_utc_datetime -from imiptools.data import get_uri, uri_dict, Object +from imiptools.data import get_uri, uri_dict from imiptools.handlers.scheduling.common import get_scheduling_conflicts, \ standard_responses from imiptools.period import Endless @@ -103,8 +103,7 @@ # Where an existing version of the object exists, merge the recipient's # attendance information. - fragment = journal.get_event(quota, handler.uid, handler.recurrenceid) - obj = fragment and Object(fragment) + obj = journal.get_event(quota, handler.uid, handler.recurrenceid) if not obj: obj = handler.obj @@ -128,8 +127,7 @@ # Where an existing version of the object exists, remove the recipient's # attendance information. - fragment = journal.get_event(quota, handler.uid, handler.recurrenceid) - obj = fragment and Object(fragment) + obj = journal.get_event(quota, handler.uid, handler.recurrenceid) if not obj: return diff -r 13b96d120060 -r 779e632b6e69 imiptools/stores/database/common.py --- a/imiptools/stores/database/common.py Tue May 23 22:15:05 2017 +0200 +++ b/imiptools/stores/database/common.py Wed May 24 15:41:14 2017 +0200 @@ -22,7 +22,7 @@ from imiptools.stores.common import StoreBase, JournalBase from datetime import datetime -from imiptools.data import parse_string, to_string +from imiptools.data import Object, parse_string, to_string from imiptools.dates import format_datetime, get_datetime, to_timezone from imiptools.freebusy import FreeBusyDatabaseCollection, \ FreeBusyGroupDatabaseCollection, \ @@ -31,6 +31,8 @@ def first(l): return l[0] +# Store classes. + class DatabaseStoreBase(DatabaseOperations): "A database store supporting user-specific locking." @@ -164,7 +166,7 @@ self.cursor.execute(query, values) result = self.cursor.fetchone() - return result and parse_string(result[0], "utf-8") + return result and Object(parse_string(result[0], "utf-8")) def get_complete_event(self, user, uid): @@ -179,7 +181,7 @@ self.cursor.execute(query, values) result = self.cursor.fetchone() - return result and parse_string(result[0], "utf-8") + return result and Object(parse_string(result[0], "utf-8")) def set_complete_event(self, user, uid, node): @@ -273,7 +275,7 @@ self.cursor.execute(query, values) result = self.cursor.fetchone() - return result and parse_string(result[0], "utf-8") + return result and Object(parse_string(result[0], "utf-8")) def set_recurrence(self, user, uid, recurrenceid, node): @@ -678,7 +680,7 @@ self.cursor.execute(query, values) result = self.cursor.fetchone() - return result and parse_string(result[0], "utf-8") + return result and Object(parse_string(result[0], "utf-8")) def set_counter(self, user, other, node, uid, recurrenceid=None): diff -r 13b96d120060 -r 779e632b6e69 imiptools/stores/file.py --- a/imiptools/stores/file.py Tue May 23 22:15:05 2017 +0200 +++ b/imiptools/stores/file.py Wed May 24 15:41:14 2017 +0200 @@ -23,7 +23,7 @@ from datetime import datetime from imiptools.config import settings -from imiptools.data import make_calendar, parse_object, to_stream +from imiptools.data import Object, make_calendar, parse_object, to_stream from imiptools.dates import format_datetime, get_datetime, to_timezone from imiptools.filesys import fix_permissions, FileBase from imiptools.freebusy import FreeBusyPeriod, FreeBusyGroupPeriod, \ @@ -40,6 +40,8 @@ PUBLISH_DIR = settings["PUBLISH_DIR"] JOURNAL_DIR = settings["JOURNAL_DIR"] +# Store classes. + class FileStoreBase(FileBase): "A file store supporting user-specific locking and tabular data." @@ -168,7 +170,7 @@ try: f = open(filename, "rb") try: - return parse_object(f, "utf-8") + return Object(parse_object(f, "utf-8")) finally: f.close() finally: diff -r 13b96d120060 -r 779e632b6e69 tests/list_table.py --- a/tests/list_table.py Tue May 23 22:15:05 2017 +0200 +++ b/tests/list_table.py Wed May 24 15:41:14 2017 +0200 @@ -3,7 +3,7 @@ """ Show the contents of a table. -Copyright (C) 2016 Paul Boddie +Copyright (C) 2016, 2017 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -28,9 +28,9 @@ for row in data: print row or "" -def show_object(data): - if data: - print Object(data).to_string(line_length=1000) +def show_object(obj): + if obj: + print obj.to_string(line_length=1000) def show_periods(data): if data: @@ -95,24 +95,24 @@ elif table == "countered_object": uid = args[0] other = args[1] - data = store.get_counter(user, other, uid) - show_object(data) + obj = store.get_counter(user, other, uid) + show_object(obj) elif table == "object": uid = args[0] - data = store.get_event(user, uid) - show_object(data) + obj = store.get_event(user, uid) + show_object(obj) elif table == "journal_object": uid = args[0] - data = journal.get_event(user, uid) - show_object(data) + obj = journal.get_event(user, uid) + show_object(obj) elif table == "recurrence": uid = args[0] recurrenceid = args[1] - data = store.get_event(user, uid, recurrenceid) - show_object(data) + obj = store.get_event(user, uid, recurrenceid) + show_object(obj) elif table == "cancelled_recurrences": uid = args[0] diff -r 13b96d120060 -r 779e632b6e69 tests/test_handle.py --- a/tests/test_handle.py Tue May 23 22:15:05 2017 +0200 +++ b/tests/test_handle.py Wed May 24 15:41:14 2017 +0200 @@ -3,7 +3,7 @@ """ A handler to help with testing. -Copyright (C) 2014, 2015, 2016 Paul Boddie +Copyright (C) 2014, 2015, 2016, 2017 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -151,20 +151,19 @@ journal = get_journal(store_type, journal_dir) if uid is not None: - fragment = store.get_event(user, uid, recurrenceid) + obj = store.get_event(user, uid, recurrenceid) # Permit new recurrences by getting the parent object. - if not fragment: - fragment = store.get_event(user, uid) + if not obj: + obj = store.get_event(user, uid) - if not fragment: + if not obj: print >>sys.stderr, "No such event:", uid, recurrenceid sys.exit(1) else: - fragment = parse_object(sys.stdin, "utf-8") + obj = Object(parse_object(sys.stdin, "utf-8")) - obj = Object(fragment) handler = TestClient(obj, user, Messenger(), store, None, journal, preferences_dir) response = handler.handle_request(action, start, end, recurrenceid) diff -r 13b96d120060 -r 779e632b6e69 tools/copy_store.py --- a/tools/copy_store.py Tue May 23 22:15:05 2017 +0200 +++ b/tools/copy_store.py Wed May 24 15:41:14 2017 +0200 @@ -59,9 +59,9 @@ # Get event, recurrence information. for uid, recurrenceid in from_store.get_all_events(user, dirname=dirname): - d = from_store.get_event(user, uid, recurrenceid, dirname=dirname) - if d: - to_store.set_event(user, uid, recurrenceid, Object(d).to_node()) + obj = from_store.get_event(user, uid, recurrenceid, dirname=dirname) + if obj: + to_store.set_event(user, uid, recurrenceid, obj.to_node()) if dirname == "cancellations": to_store.cancel_event(user, uid, recurrenceid) else: @@ -72,9 +72,9 @@ if dirname is None: for other in from_store.get_counters(user, uid, recurrenceid): - d = from_store.get_counter(user, other, uid, recurrenceid) - if d: - to_store.set_counter(user, other, Object(d).to_node(), uid, recurrenceid) + obj = from_store.get_counter(user, other, uid, recurrenceid) + if obj: + to_store.set_counter(user, other, obj.to_node(), uid, recurrenceid) else: print >>sys.stderr, "Counter-proposal for %s with UID %s and RECURRENCE-ID %s not found in %s" % ( (user, uid, recurrenceid or "null", dirname or "active events")) diff -r 13b96d120060 -r 779e632b6e69 tools/make_freebusy.py --- a/tools/make_freebusy.py Tue May 23 22:15:05 2017 +0200 +++ b/tools/make_freebusy.py Wed May 24 15:41:14 2017 +0200 @@ -117,7 +117,7 @@ print >>sys.stderr, uid, recurrenceid event = storage.get_event(user, uid, recurrenceid) if event: - objs.append(Object(event)) + objs.append(event) # Build a free/busy collection for the given user.