From b5c049ae2e62f24c6dfce618b94f567671e238ea Mon Sep 17 00:00:00 2001 From: Martin Kosek Date: Wed, 9 Nov 2011 14:10:08 +0100 Subject: Allow custom server backend encoding Server framework does not support encoding of native Python type values stored in Param classes and sub-classes. When backend (LDAP) value encoding differs from Python type value representation user has to has to hard-code the encoders in his processing. This patch introduces a method Param.encode which is used in server context to encode native Python Param values. The new encode method is used for Bool parameter to convert native Python bool type value (True, False) to LDAP value ("TRUE", "FALSE"). https://fedorahosted.org/freeipa/ticket/2039 --- ipalib/frontend.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'ipalib/frontend.py') diff --git a/ipalib/frontend.py b/ipalib/frontend.py index 61e7f493..851de437 100644 --- a/ipalib/frontend.py +++ b/ipalib/frontend.py @@ -428,6 +428,8 @@ class Command(HasParam): if not self.api.env.in_server and 'version' not in params: params['version'] = API_VERSION self.validate(**params) + if self.api.env.in_server: + params = self.encode(**params) (args, options) = self.params_2_args_options(**params) ret = self.run(*args, **options) if ( @@ -648,6 +650,14 @@ class Command(HasParam): (k, self.params[k].convert(v)) for (k, v) in kw.iteritems() ) + def encode(self, **kw): + """ + Return a dictionary of encoded values. + """ + return dict( + (k, self.params[k].encode(v)) for (k, v) in kw.iteritems() + ) + def __convert_iter(self, kw): for param in self.params(): if kw.get(param.name, None) is None: -- cgit