From 833088955c0e6c606bc8ea96a05ddf6c3a34bc6b Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Thu, 22 Jan 2009 17:03:48 -0700 Subject: More xmlrpc tweaks: xmlserver.execute() now logs non-public exceptions; xmlclient.forward() now handles socket error; fixed some Python 2.4 problems in lite-xmlrpc2.py --- ipalib/cli.py | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) (limited to 'ipalib/cli.py') diff --git a/ipalib/cli.py b/ipalib/cli.py index 62b8b9304..6b3ab7e5b 100644 --- a/ipalib/cli.py +++ b/ipalib/cli.py @@ -34,12 +34,11 @@ import struct import frontend import backend -import errors -import errors2 import plugable import util +from errors2 import PublicError, CommandError from constants import CLI_TAB -from parameters import Password +from parameters import Password, Bytes def to_cli(name): @@ -120,9 +119,10 @@ class textui(backend.Backend): """ Decode text from stdin. """ - assert type(str_buffer) is str - encoding = self.__get_encoding(sys.stdin) - return str_buffer.decode(encoding) + if type(str_buffer) is str: + encoding = self.__get_encoding(sys.stdin) + return str_buffer.decode(encoding) + return str_buffer def encode(self, unicode_text): """ @@ -535,7 +535,7 @@ class CLI(object): print '' self.api.log.info('operation aborted') sys.exit() - except errors2.PublicError, e: + except PublicError, e: self.api.log.error(e.strerror) sys.exit(e.errno) @@ -573,7 +573,7 @@ class CLI(object): return key = self.cmd_argv[0] if key not in self: - raise errors.UnknownCommandError(key) + raise CommandError(name=key) self.run_cmd(self[key]) # FIXME: Stuff that might need special handling still: @@ -782,7 +782,17 @@ class CLI(object): list(self.cmd_argv[1:]), KWCollector() ) options = kwc.__todict__() - return cmd.args_options_2_params(*args, **options) + kw = cmd.args_options_2_params(*args, **options) + return dict(self.params_iter(cmd, kw)) + + def params_iter(self, cmd, kw): + for (key, value) in kw.iteritems(): + param = cmd.params[key] + if isinstance(param, Bytes): + yield (key, value) + else: + yield (key, self.textui.decode(value)) + def build_parser(self, cmd): parser = optparse.OptionParser( -- cgit