diff options
author | Jan Cholasta <jcholast@redhat.com> | 2015-09-11 14:02:13 +0200 |
---|---|---|
committer | Jan Cholasta <jcholast@redhat.com> | 2015-09-17 11:08:43 +0200 |
commit | ba5201979dfddcb4ca6bb1b68e786cb964e50bb6 (patch) | |
tree | 47b09b736a408be189a899340e07900bb9506c6a /ipalib | |
parent | 23507e6124041ed17f39db211e802495e37520e7 (diff) | |
download | freeipa-ba5201979dfddcb4ca6bb1b68e786cb964e50bb6.tar.gz freeipa-ba5201979dfddcb4ca6bb1b68e786cb964e50bb6.tar.xz freeipa-ba5201979dfddcb4ca6bb1b68e786cb964e50bb6.zip |
Use bytes instead of str where appropriate
Under Python 2, "str" and "bytes" are synonyms.
Reviewed-By: Petr Viktorin <pviktori@redhat.com>
Diffstat (limited to 'ipalib')
-rw-r--r-- | ipalib/cli.py | 4 | ||||
-rw-r--r-- | ipalib/parameters.py | 8 | ||||
-rw-r--r-- | ipalib/plugins/baseldap.py | 4 | ||||
-rw-r--r-- | ipalib/rpc.py | 6 |
4 files changed, 11 insertions, 11 deletions
diff --git a/ipalib/cli.py b/ipalib/cli.py index 347d4c788..b0e138925 100644 --- a/ipalib/cli.py +++ b/ipalib/cli.py @@ -141,7 +141,7 @@ class textui(backend.Backend): """ Decode text from stdin. """ - if type(value) is str: + if type(value) is bytes: encoding = self.__get_encoding(sys.stdin) return value.decode(encoding) elif type(value) in (list, tuple): @@ -166,7 +166,7 @@ class textui(backend.Backend): Convert a binary value to base64. We know a value is binary if it is a python str type, otherwise it is a plain string. """ - if type(value) is str: + if type(value) is bytes: return base64.b64encode(value) elif type(value) is datetime.datetime: return value.strftime(LDAP_GENERALIZED_TIME_FORMAT) diff --git a/ipalib/parameters.py b/ipalib/parameters.py index a03a75d83..176df09ea 100644 --- a/ipalib/parameters.py +++ b/ipalib/parameters.py @@ -1333,7 +1333,7 @@ class Bytes(Data): Also see the `Str` parameter. """ - type = str + type = bytes type_error = _('must be binary data') def __init__(self, name, *rules, **kw): @@ -1348,7 +1348,7 @@ class Bytes(Data): """ Check minlength constraint. """ - assert type(value) is str + assert type(value) is bytes if len(value) < self.minlength: return _('must be at least %(minlength)d bytes') % dict( minlength=self.minlength, @@ -1358,7 +1358,7 @@ class Bytes(Data): """ Check maxlength constraint. """ - assert type(value) is str + assert type(value) is bytes if len(value) > self.maxlength: return _('can be at most %(maxlength)d bytes') % dict( maxlength=self.maxlength, @@ -1368,7 +1368,7 @@ class Bytes(Data): """ Check length constraint. """ - assert type(value) is str + assert type(value) is bytes if len(value) != self.length: return _('must be exactly %(length)d bytes') % dict( length=self.length, diff --git a/ipalib/plugins/baseldap.py b/ipalib/plugins/baseldap.py index 81fae1516..4a0224647 100644 --- a/ipalib/plugins/baseldap.py +++ b/ipalib/plugins/baseldap.py @@ -248,7 +248,7 @@ def entry_to_dict(entry, **options): for attr in entry: if attr.lower() == 'attributelevelrights': value = entry[attr] - elif entry.conn.get_attribute_type(attr) is str: + elif entry.conn.get_attribute_type(attr) is bytes: value = entry.raw[attr] else: value = list(entry.raw[attr]) @@ -1082,7 +1082,7 @@ last, after all sets and adds."""), try: entry_attrs[attr].remove(delval) except ValueError: - if isinstance(delval, str): + if isinstance(delval, bytes): # This is a Binary value, base64 encode it delval = unicode(base64.b64encode(delval)) raise errors.AttrValueNotFound(attr=attr, value=delval) diff --git a/ipalib/rpc.py b/ipalib/rpc.py index 4d39503a7..4d3914d6b 100644 --- a/ipalib/rpc.py +++ b/ipalib/rpc.py @@ -164,7 +164,7 @@ def xml_wrap(value, version): return dict( (k, xml_wrap(v, version)) for (k, v) in value.items() ) - if type(value) is str: + if type(value) is bytes: return Binary(value) if type(value) is Decimal: # transfer Decimal as a string @@ -221,7 +221,7 @@ def xml_unwrap(value, encoding='UTF-8'): if type(value) is str: return value.decode(encoding) if isinstance(value, Binary): - assert type(value.data) is str + assert type(value.data) is bytes return value.data if isinstance(value, DateTime): # xmlprc DateTime is converted to string of %Y%m%dT%H:%M:%S format @@ -290,7 +290,7 @@ def json_encode_binary(val, version): elif isinstance(val, (list, tuple)): new_list = [json_encode_binary(v, version) for v in val] return new_list - elif isinstance(val, str): + elif isinstance(val, bytes): return {'__base64__': base64.b64encode(val)} elif isinstance(val, Decimal): return {'__base64__': base64.b64encode(str(val))} |