# HG changeset patch # User Paul Boddie # Date 1463146898 -7200 # Node ID b432c9a47d8a7163cf62ccf28b7997102e1bdec2 # Parent 3e7784f3d9c9465eb7a3a5647dd08463332c50b2 Moved the standard responses to a new module and tidied up translator usage. diff -r 3e7784f3d9c9 -r b432c9a47d8a imiptools/handlers/scheduling/__init__.py --- a/imiptools/handlers/scheduling/__init__.py Fri May 13 14:31:57 2016 +0200 +++ b/imiptools/handlers/scheduling/__init__.py Fri May 13 15:41:38 2016 +0200 @@ -1,7 +1,7 @@ #!/usr/bin/env python """ -Common scheduling functionality. +Autonomous scheduling functionality. Copyright (C) 2015, 2016 Paul Boddie diff -r 3e7784f3d9c9 -r b432c9a47d8a imiptools/handlers/scheduling/common.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/imiptools/handlers/scheduling/common.py Fri May 13 15:41:38 2016 +0200 @@ -0,0 +1,40 @@ +#!/usr/bin/env python + +""" +Common scheduling functionality. + +Copyright (C) 2016 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 +Foundation; either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see . +""" + +def standard_responses(handler, response): + + """ + Using 'handler' to translate descriptions, return a tuple containing the + 'response' and a suitable description. + """ + + _ = handler.get_translator() + + if response == "ACCEPTED": + return response, _("The recipient has scheduled the requested period.") + elif response == "COUNTER": + return response, _("The recipient has suggested a different period.") + elif response == "DELEGATED": + return response, _("The recipient has delegated the requested period.") + else: + return response, _("The recipient is unavailable in the requested period.") + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r 3e7784f3d9c9 -r b432c9a47d8a imiptools/handlers/scheduling/freebusy.py --- a/imiptools/handlers/scheduling/freebusy.py Fri May 13 14:31:57 2016 +0200 +++ b/imiptools/handlers/scheduling/freebusy.py Fri May 13 15:41:38 2016 +0200 @@ -21,6 +21,7 @@ from imiptools.data import uri_values from imiptools.dates import ValidityError, to_timezone +from imiptools.handlers.scheduling.common import standard_responses def schedule_in_freebusy(handler, args, freebusy=None): @@ -34,8 +35,6 @@ free/busy records will be used. """ - _ = handler.get_translator() - # If newer than any old version, discard old details from the # free/busy record and check for suitability. @@ -60,8 +59,6 @@ returning an indication of the kind of response to be returned. """ - _ = handler.get_translator() - obj = handler.obj.copy() # Check any constraints on the request. @@ -222,22 +219,6 @@ response = response == "ACCEPTED" and (changed and "COUNTER" or "ACCEPTED") or "DECLINED" return standard_responses(handler, response) -def standard_responses(handler, response): - - """ - Using 'handler' to translate descriptions, return a tuple containing the - 'response' and a suitable description. - """ - - _ = handler.get_translator() - - if response == "ACCEPTED": - return response, _("The recipient has scheduled the requested period.") - elif response == "COUNTER": - return response, _("The recipient has suggested a different period.") - else: - return response, _("The recipient is unavailable in the requested period.") - # Registry of scheduling functions. scheduling_functions = {