From d5b0bc1b544a137b6767b13f88f5e688dab15226 Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Wed, 13 Aug 2008 00:40:13 +0000 Subject: 125: Added some generic auto-import stuff --- ipalib/util.py | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 ipalib/util.py (limited to 'ipalib/util.py') diff --git a/ipalib/util.py b/ipalib/util.py new file mode 100644 index 00000000..b6240951 --- /dev/null +++ b/ipalib/util.py @@ -0,0 +1,57 @@ +# Authors: +# Jason Gerard DeRose +# +# Copyright (C) 2008 Red Hat +# see file 'COPYING' for use and warranty information +# +# 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; version 2 only +# +# 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, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +""" + +""" + +import os +from os import path + +__import__('Plugins', globals(), locals(), [], -1) + + + +def import_plugins(): + plugins = 'Plugins' + d = path.join(path.dirname(path.abspath(__file__)), plugins) + assert path.isdir(d) and not path.islink(d), 'not regular dir: %r' % d + print d + suffix = '.py' + for name in os.listdir(d): + if not name.endswith(suffix): + continue + if name.startswith('__init__.'): + continue + print name + mod = name[:len(suffix)+1] + __import__( + '%s.%s' % (plugins, mod), + globals(), + locals(), + [], + -1 + ) + + + + +if __name__ == '__main__': + pass + import_plugins() -- cgit From 66bbe8bf2f253faa69c0556b47812a4a91e24a63 Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Wed, 13 Aug 2008 01:20:01 +0000 Subject: 132: Removed test util.py file --- ipalib/util.py | 57 --------------------------------------------------------- 1 file changed, 57 deletions(-) delete mode 100644 ipalib/util.py (limited to 'ipalib/util.py') diff --git a/ipalib/util.py b/ipalib/util.py deleted file mode 100644 index b6240951..00000000 --- a/ipalib/util.py +++ /dev/null @@ -1,57 +0,0 @@ -# Authors: -# Jason Gerard DeRose -# -# Copyright (C) 2008 Red Hat -# see file 'COPYING' for use and warranty information -# -# 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; version 2 only -# -# 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, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -""" - -""" - -import os -from os import path - -__import__('Plugins', globals(), locals(), [], -1) - - - -def import_plugins(): - plugins = 'Plugins' - d = path.join(path.dirname(path.abspath(__file__)), plugins) - assert path.isdir(d) and not path.islink(d), 'not regular dir: %r' % d - print d - suffix = '.py' - for name in os.listdir(d): - if not name.endswith(suffix): - continue - if name.startswith('__init__.'): - continue - print name - mod = name[:len(suffix)+1] - __import__( - '%s.%s' % (plugins, mod), - globals(), - locals(), - [], - -1 - ) - - - - -if __name__ == '__main__': - pass - import_plugins() -- cgit From d84e27f0d41aa13cfa5dd154ee476bd7c5e8b072 Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Thu, 2 Oct 2008 19:09:13 -0600 Subject: Added ipalib/util.py with xmlrpc_marshal() and xmlrpc_unmarshal() functions; added corresponding unit tests --- ipalib/util.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 ipalib/util.py (limited to 'ipalib/util.py') diff --git a/ipalib/util.py b/ipalib/util.py new file mode 100644 index 00000000..b60bfc8a --- /dev/null +++ b/ipalib/util.py @@ -0,0 +1,41 @@ +# Authors: +# Jason Gerard DeRose +# +# Copyright (C) 2008 Red Hat +# see file 'COPYING' for use and warranty information +# +# 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; version 2 only +# +# 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, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +""" +Various utility functions. +""" + +def xmlrpc_marshal(*args, **kw): + """ + Marshal (args, kw) into ((kw,) + args). + """ + return ((kw,) + args) + + +def xmlrpc_unmarshal(*params): + """ + Unmarshal (params) into (args, kw). + """ + if len(params) > 0: + kw = params[0] + if type(kw) is not dict: + raise TypeError('first xmlrpc argument must be dict') + else: + kw = {} + return (params[1:], kw) -- cgit From 1daf319a19f902d7c7bef37af065cac81be9189e Mon Sep 17 00:00:00 2001 From: Rob Crittenden Date: Wed, 22 Oct 2008 17:54:04 -0400 Subject: Implement the host commands In order for this to work against a v1 database the update host.update needs to be applied --- ipalib/util.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'ipalib/util.py') diff --git a/ipalib/util.py b/ipalib/util.py index b60bfc8a..184c6d7c 100644 --- a/ipalib/util.py +++ b/ipalib/util.py @@ -20,6 +20,7 @@ """ Various utility functions. """ +import krbV def xmlrpc_marshal(*args, **kw): """ @@ -39,3 +40,11 @@ def xmlrpc_unmarshal(*params): else: kw = {} return (params[1:], kw) + +def get_current_principal(): + try: + return krbV.default_context().default_ccache().principal().name + except krbV.Krb5Error: + #TODO: do a kinit + print "Unable to get kerberos principal" + return None -- cgit From 03accc5fb382777d9bbdb245f3211d5c06489f6e Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Mon, 27 Oct 2008 00:23:43 -0600 Subject: Copied plugin loading function from load_plugins.py to util.py; API.load_plugins() method now calls functions in util --- ipalib/util.py | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'ipalib/util.py') diff --git a/ipalib/util.py b/ipalib/util.py index 184c6d7c..d7e2c2a4 100644 --- a/ipalib/util.py +++ b/ipalib/util.py @@ -20,7 +20,11 @@ """ Various utility functions. """ + import krbV +import os +from os import path +import imp def xmlrpc_marshal(*args, **kw): """ @@ -41,6 +45,7 @@ def xmlrpc_unmarshal(*params): kw = {} return (params[1:], kw) + def get_current_principal(): try: return krbV.default_context().default_ccache().principal().name @@ -48,3 +53,49 @@ def get_current_principal(): #TODO: do a kinit print "Unable to get kerberos principal" return None + + +# FIXME: This function has no unit test +def find_modules_in_dir(src_dir): + """ + Iterate through module names found in ``src_dir``. + """ + if not (path.abspath(src_dir) == src_dir and path.isdir(src_dir)): + return + if path.islink(src_dir): + return + suffix = '.py' + for name in sorted(os.listdir(src_dir)): + if not name.endswith(suffix): + continue + py_file = path.join(src_dir, name) + if path.islink(py_file) or not path.isfile(py_file): + continue + module = name[:-len(suffix)] + if module == '__init__': + continue + yield module + + +# FIXME: This function has no unit test +def load_plugins_in_dir(src_dir): + """ + Import each Python module found in ``src_dir``. + """ + for module in find_modules_in_dir(src_dir): + imp.load_module(module, *imp.find_module(module, [src_dir])) + + +# FIXME: This function has no unit test +def import_plugins_subpackage(name): + """ + Import everythig in ``plugins`` sub-package of package named ``name``. + """ + try: + plugins = __import__(name + '.plugins').plugins + except ImportError: + return + src_dir = path.dirname(path.abspath(plugins.__file__)) + for name in find_modules_in_dir(src_dir): + full_name = '%s.%s' % (plugins.__name__, name) + __import__(full_name) -- cgit From 316bd855d5720f4babfb79d20c391de3f8958a60 Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Tue, 28 Oct 2008 01:39:02 -0600 Subject: Added util.configure_logging() function; API.bootstrap() now calls util.configure_logging() --- ipalib/util.py | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'ipalib/util.py') diff --git a/ipalib/util.py b/ipalib/util.py index d7e2c2a4..e65f15ca 100644 --- a/ipalib/util.py +++ b/ipalib/util.py @@ -21,10 +21,13 @@ Various utility functions. """ -import krbV +import logging import os from os import path import imp +import krbV +from constants import LOGGING_CONSOLE_FORMAT, LOGGING_FILE_FORMAT + def xmlrpc_marshal(*args, **kw): """ @@ -99,3 +102,34 @@ def import_plugins_subpackage(name): for name in find_modules_in_dir(src_dir): full_name = '%s.%s' % (plugins.__name__, name) __import__(full_name) + + +def configure_logging(log_file, verbose): + """ + Configure standard logging. + """ + # Check that directory log_file is in exists: + log_dir = path.dirname(log_file) + if not path.isdir(log_dir): + os.makedirs(log_dir) + + # Set logging level: + level = logging.INFO + if verbose: + level -= 10 + + log = logging.getLogger('ipa') + + # Configure console handler + console = logging.StreamHandler() + console.setLevel(level) + console.setFormatter(logging.Formatter(LOGGING_CONSOLE_FORMAT)) + log.addHandler(console) + + # Configure file handler + file_handler = logging.FileHandler(log_file) + file_handler.setLevel(level) + file_handler.setFormatter(logging.Formatter(LOGGING_FILE_FORMAT)) + log.addHandler(file_handler) + + return log -- cgit From a9f1c74a7fb7619cfcdb9f5eaf0f62745b1b551e Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Tue, 28 Oct 2008 01:45:02 -0600 Subject: util.configure_logging() now only configures file logging if it can create the log_dir --- ipalib/util.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'ipalib/util.py') diff --git a/ipalib/util.py b/ipalib/util.py index e65f15ca..280910dc 100644 --- a/ipalib/util.py +++ b/ipalib/util.py @@ -108,11 +108,6 @@ def configure_logging(log_file, verbose): """ Configure standard logging. """ - # Check that directory log_file is in exists: - log_dir = path.dirname(log_file) - if not path.isdir(log_dir): - os.makedirs(log_dir) - # Set logging level: level = logging.INFO if verbose: @@ -127,6 +122,13 @@ def configure_logging(log_file, verbose): log.addHandler(console) # Configure file handler + log_dir = path.dirname(log_file) + if not path.isdir(log_dir): + try: + os.makedirs(log_dir) + except OSError: + log.warn('Could not create log_dir %r', log_dir) + return log file_handler = logging.FileHandler(log_file) file_handler.setLevel(level) file_handler.setFormatter(logging.Formatter(LOGGING_FILE_FORMAT)) -- cgit From fbcb55bd11d17dbff8ec3c7c99cf7b3bb91d3752 Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Tue, 28 Oct 2008 02:10:56 -0600 Subject: lite-xmlrpc.py now uses api.bootstrap() property, logs to api.logger --- ipalib/util.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'ipalib/util.py') diff --git a/ipalib/util.py b/ipalib/util.py index 280910dc..d577524b 100644 --- a/ipalib/util.py +++ b/ipalib/util.py @@ -114,10 +114,10 @@ def configure_logging(log_file, verbose): level -= 10 log = logging.getLogger('ipa') + log.setLevel(level) # Configure console handler console = logging.StreamHandler() - console.setLevel(level) console.setFormatter(logging.Formatter(LOGGING_CONSOLE_FORMAT)) log.addHandler(console) @@ -130,7 +130,6 @@ def configure_logging(log_file, verbose): log.warn('Could not create log_dir %r', log_dir) return log file_handler = logging.FileHandler(log_file) - file_handler.setLevel(level) file_handler.setFormatter(logging.Formatter(LOGGING_FILE_FORMAT)) log.addHandler(file_handler) -- cgit From cdfb7bfd5ebc1f5e44f4ee60cec14354040a0a72 Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Fri, 31 Oct 2008 13:27:42 -0600 Subject: Logging is now configured in API.bootstrap(); removed depreciated util.configure_logging() function --- ipalib/util.py | 33 --------------------------------- 1 file changed, 33 deletions(-) (limited to 'ipalib/util.py') diff --git a/ipalib/util.py b/ipalib/util.py index d577524b..3222c5a7 100644 --- a/ipalib/util.py +++ b/ipalib/util.py @@ -21,7 +21,6 @@ Various utility functions. """ -import logging import os from os import path import imp @@ -102,35 +101,3 @@ def import_plugins_subpackage(name): for name in find_modules_in_dir(src_dir): full_name = '%s.%s' % (plugins.__name__, name) __import__(full_name) - - -def configure_logging(log_file, verbose): - """ - Configure standard logging. - """ - # Set logging level: - level = logging.INFO - if verbose: - level -= 10 - - log = logging.getLogger('ipa') - log.setLevel(level) - - # Configure console handler - console = logging.StreamHandler() - console.setFormatter(logging.Formatter(LOGGING_CONSOLE_FORMAT)) - log.addHandler(console) - - # Configure file handler - log_dir = path.dirname(log_file) - if not path.isdir(log_dir): - try: - os.makedirs(log_dir) - except OSError: - log.warn('Could not create log_dir %r', log_dir) - return log - file_handler = logging.FileHandler(log_file) - file_handler.setFormatter(logging.Formatter(LOGGING_FILE_FORMAT)) - log.addHandler(file_handler) - - return log -- cgit From a23d41a57f43c3a0f298d3918ae1712181fa544e Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Fri, 31 Oct 2008 18:17:08 -0600 Subject: Reoganized global option functionality to it is easy for any script to use the environment-related global options; lite-xmlrpc.py now uses same global options --- ipalib/util.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'ipalib/util.py') diff --git a/ipalib/util.py b/ipalib/util.py index 3222c5a7..48a3a129 100644 --- a/ipalib/util.py +++ b/ipalib/util.py @@ -24,6 +24,7 @@ Various utility functions. import os from os import path import imp +import optparse import krbV from constants import LOGGING_CONSOLE_FORMAT, LOGGING_FILE_FORMAT @@ -101,3 +102,24 @@ def import_plugins_subpackage(name): for name in find_modules_in_dir(src_dir): full_name = '%s.%s' % (plugins.__name__, name) __import__(full_name) + + +def add_global_options(parser=None): + """ + Add global options to an optparse.OptionParser instance. + """ + if parser is None: + parser = optparse.OptionParser() + parser.add_option('-e', dest='env', metavar='KEY=VAL', action='append', + help='Set environment variable KEY to VAL', + ) + parser.add_option('-c', dest='conf', metavar='FILE', + help='Load configuration from FILE', + ) + parser.add_option('-d', '--debug', action='store_true', + help='Produce full debuging output', + ) + parser.add_option('-v', '--verbose', action='store_true', + help='Produce more verbose output', + ) + return parser -- cgit From 5269d1396c2e299d7fc66b55df7a84d482927549 Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Fri, 31 Oct 2008 18:55:32 -0600 Subject: Logging formats are now env variables; added log_format_stderr_debug format used when env.debug is True --- ipalib/util.py | 1 - 1 file changed, 1 deletion(-) (limited to 'ipalib/util.py') diff --git a/ipalib/util.py b/ipalib/util.py index 48a3a129..c1652065 100644 --- a/ipalib/util.py +++ b/ipalib/util.py @@ -26,7 +26,6 @@ from os import path import imp import optparse import krbV -from constants import LOGGING_CONSOLE_FORMAT, LOGGING_FILE_FORMAT def xmlrpc_marshal(*args, **kw): -- cgit From 242a8183a7cc002f496421352e8346db4232648b Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Fri, 31 Oct 2008 20:25:33 -0600 Subject: Added custom log formatter util.LogFormatter that makes the human-readable time stamp in UTC --- ipalib/util.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'ipalib/util.py') diff --git a/ipalib/util.py b/ipalib/util.py index c1652065..12f9c781 100644 --- a/ipalib/util.py +++ b/ipalib/util.py @@ -25,6 +25,8 @@ import os from os import path import imp import optparse +import logging +import time import krbV @@ -122,3 +124,10 @@ def add_global_options(parser=None): help='Produce more verbose output', ) return parser + + +class LogFormatter(logging.Formatter): + """ + Log formatter that uses UTC for all timestamps. + """ + converter = time.gmtime -- cgit From 09161e399a61e2a548e9efb3c3abb2c7b47d5520 Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Wed, 12 Nov 2008 01:47:37 -0700 Subject: Command.get_default() will now fill-in None for all missing non-required params --- ipalib/util.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'ipalib/util.py') diff --git a/ipalib/util.py b/ipalib/util.py index 12f9c781..9bc43254 100644 --- a/ipalib/util.py +++ b/ipalib/util.py @@ -34,6 +34,12 @@ def xmlrpc_marshal(*args, **kw): """ Marshal (args, kw) into ((kw,) + args). """ + kw = dict( + filter(lambda item: item[1] is not None, kw.iteritems()) + ) + args = tuple( + filter(lambda value: value is not None, args) + ) return ((kw,) + args) -- cgit From 8ad5502354a364db606b72455c5514cb56e918ba Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Thu, 13 Nov 2008 21:07:47 -0700 Subject: Added util.make_repr() function; added corresponding unit tests --- ipalib/util.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'ipalib/util.py') diff --git a/ipalib/util.py b/ipalib/util.py index 9bc43254..89e2c5a7 100644 --- a/ipalib/util.py +++ b/ipalib/util.py @@ -137,3 +137,12 @@ class LogFormatter(logging.Formatter): Log formatter that uses UTC for all timestamps. """ converter = time.gmtime + + +def make_repr(name, *args, **kw): + """ + Construct a standard representation of a class instance. + """ + args = [repr(a) for a in args] + kw = ['%s=%r' % (k, kw[k]) for k in sorted(kw)] + return '%s(%s)' % (name, ', '.join(args + kw)) -- cgit From cfe4ec2175c42f208ae23401991febb8525bdd9b Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Wed, 19 Nov 2008 16:11:23 -0700 Subject: Added util.xmlrpc_wrap(), util.xmlrpc_unwrap() functions an corresponding unit tests --- ipalib/util.py | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) (limited to 'ipalib/util.py') diff --git a/ipalib/util.py b/ipalib/util.py index 89e2c5a7..60b9409f 100644 --- a/ipalib/util.py +++ b/ipalib/util.py @@ -27,9 +27,12 @@ import imp import optparse import logging import time +from types import NoneType +from xmlrpclib import Binary import krbV + def xmlrpc_marshal(*args, **kw): """ Marshal (args, kw) into ((kw,) + args). @@ -56,6 +59,67 @@ def xmlrpc_unmarshal(*params): return (params[1:], kw) +def xmlrpc_wrap(value): + """ + Wrap all ``str`` in ``xmlrpclib.Binary``. + + Because ``xmlrpclib.dumps()`` will itself convert all ``unicode`` instances + into UTF-8 encoded ``str`` instances, we don't do it here. + + So in total, when encoding data for an XML-RPC request, the following + transformations occur: + + * All ``str`` instances are treated as binary data and are wrapped in + an ``xmlrpclib.Binary()`` instance. + + * Only ``unicode`` instances are treated as character data. They get + converted to UTF-8 encoded ``str`` instances (although as mentioned, + not by this function). + + Also see `xmlrpc_unwrap`. + """ + if type(value) in (list, tuple): + return tuple(xmlrpc_wrap(v) for v in value) + if type(value) is dict: + return dict( + (k, xmlrpc_wrap(v)) for (k, v) in value.iteritems() + ) + if type(value) is str: + return Binary(value) + assert type(value) in (unicode, int, float, bool, NoneType) + return value + + +def xmlrpc_unwrap(value, encoding='UTF-8'): + """ + Unwrap all ``xmlrpc.Binary``, decode all ``str`` into ``unicode``. + + When decoding data from an XML-RPC request, the following transformations + occur: + + * The binary payloads of all ``xmlrpclib.Binary`` instances are + returned as ``str`` instances. + + * All ``str`` instances are treated as UTF-8 encoded character data. + They are decoded and the resulting ``unicode`` instance is returned. + + Also see `xmlrpc_wrap`. + """ + if type(value) in (list, tuple): + return tuple(xmlrpc_unwrap(v, encoding) for v in value) + if type(value) is dict: + return dict( + (k, xmlrpc_unwrap(v, encoding)) for (k, v) in value.iteritems() + ) + if type(value) is str: + return value.decode(encoding) + if isinstance(value, Binary): + assert type(value.data) is str + return value.data + assert type(value) in (int, float, bool, NoneType) + return value + + def get_current_principal(): try: return krbV.default_context().default_ccache().principal().name -- cgit From 75bdea29be8ea53c8e005e9020f3f2d1c7dcf689 Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Thu, 20 Nov 2008 12:41:06 -0700 Subject: Added test_util.test_round_trip() test that tests use of xmlrpc_wrap() and xmlrpc_unwrap() with dumps(), loads(); fixed a bug in xmlrpc_unwrap() --- ipalib/util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ipalib/util.py') diff --git a/ipalib/util.py b/ipalib/util.py index 60b9409f..223422fe 100644 --- a/ipalib/util.py +++ b/ipalib/util.py @@ -116,7 +116,7 @@ def xmlrpc_unwrap(value, encoding='UTF-8'): if isinstance(value, Binary): assert type(value.data) is str return value.data - assert type(value) in (int, float, bool, NoneType) + assert type(value) in (unicode, int, float, bool, NoneType) return value -- cgit From 4591057203e61a4ab304b8730ffede6560f74d4b Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Mon, 8 Dec 2008 15:15:50 -0700 Subject: Removed depreciated rpc code from ipalib.util; removed corresponding unit tests in test_util --- ipalib/util.py | 61 ---------------------------------------------------------- 1 file changed, 61 deletions(-) (limited to 'ipalib/util.py') diff --git a/ipalib/util.py b/ipalib/util.py index 223422fe..4a58d7fb 100644 --- a/ipalib/util.py +++ b/ipalib/util.py @@ -59,67 +59,6 @@ def xmlrpc_unmarshal(*params): return (params[1:], kw) -def xmlrpc_wrap(value): - """ - Wrap all ``str`` in ``xmlrpclib.Binary``. - - Because ``xmlrpclib.dumps()`` will itself convert all ``unicode`` instances - into UTF-8 encoded ``str`` instances, we don't do it here. - - So in total, when encoding data for an XML-RPC request, the following - transformations occur: - - * All ``str`` instances are treated as binary data and are wrapped in - an ``xmlrpclib.Binary()`` instance. - - * Only ``unicode`` instances are treated as character data. They get - converted to UTF-8 encoded ``str`` instances (although as mentioned, - not by this function). - - Also see `xmlrpc_unwrap`. - """ - if type(value) in (list, tuple): - return tuple(xmlrpc_wrap(v) for v in value) - if type(value) is dict: - return dict( - (k, xmlrpc_wrap(v)) for (k, v) in value.iteritems() - ) - if type(value) is str: - return Binary(value) - assert type(value) in (unicode, int, float, bool, NoneType) - return value - - -def xmlrpc_unwrap(value, encoding='UTF-8'): - """ - Unwrap all ``xmlrpc.Binary``, decode all ``str`` into ``unicode``. - - When decoding data from an XML-RPC request, the following transformations - occur: - - * The binary payloads of all ``xmlrpclib.Binary`` instances are - returned as ``str`` instances. - - * All ``str`` instances are treated as UTF-8 encoded character data. - They are decoded and the resulting ``unicode`` instance is returned. - - Also see `xmlrpc_wrap`. - """ - if type(value) in (list, tuple): - return tuple(xmlrpc_unwrap(v, encoding) for v in value) - if type(value) is dict: - return dict( - (k, xmlrpc_unwrap(v, encoding)) for (k, v) in value.iteritems() - ) - if type(value) is str: - return value.decode(encoding) - if isinstance(value, Binary): - assert type(value.data) is str - return value.data - assert type(value) in (unicode, int, float, bool, NoneType) - return value - - def get_current_principal(): try: return krbV.default_context().default_ccache().principal().name -- cgit