From ca3f3041106dbaa8462aeb78c35b640b169d694a Mon Sep 17 00:00:00 2001 From: Jan Cholasta Date: Mon, 23 Jan 2012 09:50:41 -0500 Subject: Base64-decode unicode values in Bytes parameters. Fix wrong handling of strings in --setattr/--addattr/--delattr. These changes make it possible to use Bytes in --setattr/--addattr/ --delattr without errors. Fixes managing SSH keys on command-line https://fedorahosted.org/freeipa/ticket/754 --- ipalib/parameters.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'ipalib/parameters.py') diff --git a/ipalib/parameters.py b/ipalib/parameters.py index d918a5737..c533f9d0b 100644 --- a/ipalib/parameters.py +++ b/ipalib/parameters.py @@ -101,6 +101,10 @@ a more detailed description for clarity. import re import decimal +import base64 +import csv +from xmlrpclib import MAXINT, MININT + from types import NoneType from util import make_repr from text import _ as ugettext @@ -109,8 +113,6 @@ from errors import ConversionError, RequirementError, ValidationError from errors import PasswordMismatch from constants import NULLS, TYPE_ERROR, CALLABLE_ERROR from text import Gettext, FixMe -import csv -from xmlrpclib import MAXINT, MININT class DefaultFrom(ReadOnly): @@ -1440,6 +1442,14 @@ class Bytes(Data): length=self.length, ) + def _convert_scalar(self, value, index=None): + if isinstance(value, unicode): + try: + value = base64.b64decode(value) + except TypeError: + raise ConversionError(name=self.name, index=index, error=self.type_error) + return super(Bytes, self)._convert_scalar(value, index) + class Str(Data): """ -- cgit