# HG changeset patch # User Paul Boddie # Date 1485874421 -3600 # Node ID d4f61598478b2caf674549f8c75011a757b1033f # Parent 85c4f9eea50f4d09109f2e5f56240ee64f32cdd1 Updated config-related operations to use the settings dictionary. diff -r 85c4f9eea50f -r d4f61598478b imiptools/__init__.py --- a/imiptools/__init__.py Tue Jan 31 15:49:14 2017 +0100 +++ b/imiptools/__init__.py Tue Jan 31 15:53:41 2017 +0100 @@ -3,7 +3,7 @@ """ A processing framework for iMIP content. -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 @@ -20,7 +20,7 @@ """ from email import message_from_file -from imiptools import config +from imiptools.config import settings from imiptools.client import Client from imiptools.content import handle_itip_part from imiptools.data import get_address, get_addresses, get_uri @@ -106,7 +106,7 @@ # None and deduced from the object content later. else: - senders = [sender for sender in get_addresses(get_all_values(msg, "From") or []) if sender != config.MESSAGE_SENDER] + senders = [sender for sender in get_addresses(get_all_values(msg, "From") or []) if sender != settings["MESSAGE_SENDER"]] Recipient(senders and senders[0] or None, messenger, store, publisher, journal, preferences_dir, self.handlers, self.outgoing_only, self.debug ).process(msg, senders) @@ -189,7 +189,7 @@ getvalue = lambda value, default=None: value and value[0] or default self.messenger = Messenger(lmtp_socket=getvalue(lmtp), local_smtp=local_smtp, sender=getvalue(senders)) - self.store_type = getvalue(store_type, config.STORE_TYPE) + self.store_type = getvalue(store_type, settings["STORE_TYPE"]) self.store_dir = getvalue(store_dir) self.publishing_dir = getvalue(publishing_dir) self.preferences_dir = getvalue(preferences_dir) @@ -198,7 +198,7 @@ # If debug mode is set, extend the line length for convenience. if self.debug: - config.CALENDAR_LINE_LENGTH = 1000 + settings["CALENDAR_LINE_LENGTH"] = 1000 # Process the input. @@ -381,7 +381,7 @@ # Determine whether to wrap, accompany or replace the message. prefs = self.get_preferences() - incoming = prefs.get("incoming", config.INCOMING_DEFAULT) + incoming = prefs.get("incoming", settings["INCOMING_DEFAULT"]) if incoming == "message-only": messages = [msg] diff -r 85c4f9eea50f -r d4f61598478b imiptools/client.py --- a/imiptools/client.py Tue Jan 31 15:49:14 2017 +0100 +++ b/imiptools/client.py Tue Jan 31 15:53:41 2017 +0100 @@ -3,7 +3,7 @@ """ Common calendar client utilities. -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 @@ -20,7 +20,7 @@ """ from datetime import datetime, timedelta -from imiptools import config +from imiptools.config import settings from imiptools.data import Object, check_delegation, get_address, get_uri, \ get_window_end, is_new_object, make_freebusy, \ make_uid, to_part, uri_dict, uri_item, uri_items, \ @@ -50,11 +50,11 @@ self.user = user self.messenger = messenger - self.store = store or get_store(config.STORE_TYPE, config.STORE_DIR) - self.journal = journal or get_journal(config.STORE_TYPE, config.JOURNAL_DIR) + self.store = store or get_store(settings["STORE_TYPE"], settings["STORE_DIR"]) + self.journal = journal or get_journal(settings["STORE_TYPE"], settings["JOURNAL_DIR"]) try: - self.publisher = publisher or get_publisher(config.PUBLISH_DIR) + self.publisher = publisher or get_publisher(settings["PUBLISH_DIR"]) except OSError: self.publisher = None @@ -120,56 +120,56 @@ "Return participation in the calendar system." prefs = self.get_preferences() - return prefs and prefs.get("participating", config.PARTICIPATING_DEFAULT) != "no" or False + return prefs and prefs.get("participating", settings["PARTICIPATING_DEFAULT"]) != "no" or False def is_sharing(self): "Return whether free/busy information is being generally shared." prefs = self.get_preferences() - return prefs and prefs.get("freebusy_sharing", config.SHARING_DEFAULT) == "share" or False + return prefs and prefs.get("freebusy_sharing", settings["SHARING_DEFAULT"]) == "share" or False def is_bundling(self): "Return whether free/busy information is being bundled in messages." prefs = self.get_preferences() - return prefs and prefs.get("freebusy_bundling", config.BUNDLING_DEFAULT) == "always" or False + return prefs and prefs.get("freebusy_bundling", settings["BUNDLING_DEFAULT"]) == "always" or False def is_notifying(self): "Return whether recipients are notified about free/busy payloads." prefs = self.get_preferences() - return prefs and prefs.get("freebusy_messages", config.NOTIFYING_DEFAULT) == "notify" or False + return prefs and prefs.get("freebusy_messages", settings["NOTIFYING_DEFAULT"]) == "notify" or False def is_publishing(self): "Return whether free/busy information is being published as Web resources." prefs = self.get_preferences() - return prefs and prefs.get("freebusy_publishing", config.PUBLISHING_DEFAULT) == "publish" or False + return prefs and prefs.get("freebusy_publishing", settings["PUBLISHING_DEFAULT"]) == "publish" or False def is_refreshing(self): "Return whether a recipient supports requests to refresh event details." prefs = self.get_preferences() - return prefs and prefs.get("event_refreshing", config.REFRESHING_DEFAULT) == "always" or False + return prefs and prefs.get("event_refreshing", settings["REFRESHING_DEFAULT"]) == "always" or False def allow_add(self): return self.get_add_method_response() in ("add", "refresh") def get_add_method_response(self): prefs = self.get_preferences() - return prefs and prefs.get("add_method_response", config.ADD_RESPONSE_DEFAULT) or "refresh" + return prefs and prefs.get("add_method_response", settings["ADD_RESPONSE_DEFAULT"]) or "refresh" def get_offer_period(self): "Decode a specification in the iCalendar duration format." prefs = self.get_preferences() - duration = prefs and prefs.get("freebusy_offers", config.FREEBUSY_OFFER_DEFAULT) + duration = prefs and prefs.get("freebusy_offers", settings["FREEBUSY_OFFER_DEFAULT"]) # NOTE: Should probably report an error somehow if None. @@ -177,10 +177,10 @@ def get_organiser_replacement(self): prefs = self.get_preferences() - return prefs and prefs.get("organiser_replacement", config.ORGANISER_REPLACEMENT_DEFAULT) or "attendee" + return prefs and prefs.get("organiser_replacement", settings["ORGANISER_REPLACEMENT_DEFAULT"]) or "attendee" def have_manager(self): - return config.MANAGER_INTERFACE + return settings["MANAGER_INTERFACE"] def get_permitted_values(self): @@ -307,13 +307,13 @@ "Return an encoded MIME part for the given 'method' and 'fragments'." - return to_part(method, fragments, line_length=config.CALENDAR_LINE_LENGTH) + return to_part(method, fragments, line_length=settings["CALENDAR_LINE_LENGTH"]) def object_to_part(self, method, obj): "Return an encoded MIME part for the given 'method' and 'obj'." - return obj.to_part(method, line_length=config.CALENDAR_LINE_LENGTH) + return obj.to_part(method, line_length=settings["CALENDAR_LINE_LENGTH"]) # Preparation of messages communicating the state of events.