mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
Use byte literals where appropriate
Reviewed-By: Petr Viktorin <pviktori@redhat.com>
This commit is contained in:
@@ -87,7 +87,7 @@ class update_upload_cacrt(Updater):
|
||||
entry.single_value['cACertificate;binary'] = ca_cert
|
||||
ldap.add_entry(entry)
|
||||
else:
|
||||
if '' in entry['cACertificate;binary']:
|
||||
if b'' in entry['cACertificate;binary']:
|
||||
entry.single_value['cACertificate;binary'] = ca_cert
|
||||
ldap.update_entry(entry)
|
||||
|
||||
|
||||
@@ -1260,7 +1260,7 @@ class ReplicationManager(object):
|
||||
sub = {'suffix': self.suffix, 'fqdn': replica}
|
||||
try:
|
||||
entry.raw['aci'].remove(
|
||||
'(target = "ldap:///cn=*,cn=ca_renewal,cn=ipa,cn=etc,'
|
||||
b'(target = "ldap:///cn=*,cn=ca_renewal,cn=ipa,cn=etc,'
|
||||
'%(suffix)s")(version 3.0; acl "Add CA Certificates for '
|
||||
'renewals"; allow(add) userdn = "ldap:///fqdn=%(fqdn)s,'
|
||||
'cn=computers,cn=accounts,%(suffix)s";)' % sub)
|
||||
@@ -1268,7 +1268,7 @@ class ReplicationManager(object):
|
||||
pass
|
||||
try:
|
||||
entry.raw['aci'].remove(
|
||||
'(target = "ldap:///cn=*,cn=ca_renewal,cn=ipa,cn=etc,'
|
||||
b'(target = "ldap:///cn=*,cn=ca_renewal,cn=ipa,cn=etc,'
|
||||
'%(suffix)s")(targetattr = "userCertificate")'
|
||||
'(version 3.0; acl "Modify CA Certificates for renewals"; '
|
||||
'allow(write) userdn = "ldap:///fqdn=%(fqdn)s,'
|
||||
@@ -1277,7 +1277,7 @@ class ReplicationManager(object):
|
||||
pass
|
||||
try:
|
||||
entry.raw['aci'].remove(
|
||||
'(target = "ldap:///cn=CAcert,cn=ipa,cn=etc,%(suffix)s")'
|
||||
b'(target = "ldap:///cn=CAcert,cn=ipa,cn=etc,%(suffix)s")'
|
||||
'(targetattr = cACertificate)(version 3.0; acl "Modify CA '
|
||||
'Certificate"; allow (write) userdn = "ldap:///fqdn='
|
||||
'%(fqdn)s,cn=computers,cn=accounts,%(suffix)s";)' % sub)
|
||||
@@ -1305,7 +1305,7 @@ class ReplicationManager(object):
|
||||
sub = {'suffix': self.suffix, 'fqdn': replica}
|
||||
try:
|
||||
entry.raw['aci'].remove(
|
||||
'(targetfilter = "(objectClass=nsContainer)")'
|
||||
b'(targetfilter = "(objectClass=nsContainer)")'
|
||||
'(targetattr = "cn || objectClass || ipaConfigString")'
|
||||
'(version 3.0; acl "Read IPA Masters"; allow (read, '
|
||||
'search, compare) userdn = "ldap:///fqdn=%(fqdn)s,'
|
||||
@@ -1314,7 +1314,7 @@ class ReplicationManager(object):
|
||||
pass
|
||||
try:
|
||||
entry.raw['aci'].remove(
|
||||
'(targetfilter = "(objectClass=nsContainer)")'
|
||||
b'(targetfilter = "(objectClass=nsContainer)")'
|
||||
'(targetattr = "ipaConfigString")(version 3.0; acl '
|
||||
'"Modify IPA Masters"; allow (write) userdn = '
|
||||
'"ldap:///fqdn=%(fqdn)s,cn=computers,cn=accounts,'
|
||||
@@ -1343,7 +1343,7 @@ class ReplicationManager(object):
|
||||
sub = {'suffix': self.suffix, 'fqdn': replica}
|
||||
try:
|
||||
entry.raw['aci'].remove(
|
||||
'(targetfilter = "(&(objectClass=ipaCertificate)'
|
||||
b'(targetfilter = "(&(objectClass=ipaCertificate)'
|
||||
'(ipaConfigString=ipaCA))")(targetattr = '
|
||||
'"ipaCertIssuerSerial || cACertificate")(version 3.0; acl '
|
||||
'"Modify CA Certificate Store Entry"; allow (write) '
|
||||
|
||||
@@ -25,12 +25,12 @@ import struct
|
||||
|
||||
|
||||
# A string that should have bytes 'x\00' through '\xff':
|
||||
binary_bytes = ''.join(struct.pack('B', d) for d in range(256))
|
||||
assert '\x00' in binary_bytes and '\xff' in binary_bytes
|
||||
binary_bytes = b''.join(struct.pack('B', d) for d in range(256))
|
||||
assert b'\x00' in binary_bytes and b'\xff' in binary_bytes
|
||||
assert type(binary_bytes) is str and len(binary_bytes) == 256
|
||||
|
||||
# A UTF-8 encoded str:
|
||||
utf8_bytes = '\xd0\x9f\xd0\xb0\xd0\xb2\xd0\xb5\xd0\xbb'
|
||||
utf8_bytes = b'\xd0\x9f\xd0\xb0\xd0\xb2\xd0\xb5\xd0\xbb'
|
||||
|
||||
# The same UTF-8 data decoded (a unicode instance):
|
||||
unicode_str = u'\u041f\u0430\u0432\u0435\u043b'
|
||||
|
||||
@@ -46,7 +46,7 @@ from ipalib import _
|
||||
if six.PY3:
|
||||
unicode = str
|
||||
|
||||
NULLS = (None, '', u'', tuple(), [])
|
||||
NULLS = (None, b'', u'', tuple(), [])
|
||||
|
||||
class test_DefaultFrom(ClassChecker):
|
||||
"""
|
||||
@@ -1636,4 +1636,4 @@ class test_DateTime(ClassChecker):
|
||||
u'1991-31-12Z',
|
||||
u'1991-12-07T25:30:05Z',
|
||||
):
|
||||
raises(ConversionError, o.convert, value)
|
||||
raises(ConversionError, o.convert, value)
|
||||
|
||||
@@ -67,10 +67,10 @@ def test_round_trip():
|
||||
assert_equal(dump_n_load(unicode_str), unicode_str)
|
||||
assert_equal(dump_n_load(Binary(binary_bytes)).data, binary_bytes)
|
||||
assert isinstance(dump_n_load(Binary(binary_bytes)), Binary)
|
||||
assert type(dump_n_load('hello')) is bytes
|
||||
assert type(dump_n_load(b'hello')) is bytes
|
||||
assert type(dump_n_load(u'hello')) is bytes
|
||||
assert_equal(dump_n_load(''), '')
|
||||
assert_equal(dump_n_load(u''), '')
|
||||
assert_equal(dump_n_load(b''), b'')
|
||||
assert_equal(dump_n_load(u''), b'')
|
||||
assert dump_n_load(None) is None
|
||||
|
||||
# Now we test our wrap and unwrap methods in combination with dumps, loads:
|
||||
@@ -81,9 +81,9 @@ def test_round_trip():
|
||||
assert_equal(round_trip(utf8_bytes), utf8_bytes)
|
||||
assert_equal(round_trip(unicode_str), unicode_str)
|
||||
assert_equal(round_trip(binary_bytes), binary_bytes)
|
||||
assert type(round_trip('hello')) is bytes
|
||||
assert type(round_trip(b'hello')) is bytes
|
||||
assert type(round_trip(u'hello')) is unicode
|
||||
assert_equal(round_trip(''), '')
|
||||
assert_equal(round_trip(b''), b'')
|
||||
assert_equal(round_trip(u''), u'')
|
||||
assert round_trip(None) is None
|
||||
compound = [utf8_bytes, None, binary_bytes, (None, unicode_str),
|
||||
@@ -99,13 +99,13 @@ def test_xml_wrap():
|
||||
f = rpc.xml_wrap
|
||||
assert f([], API_VERSION) == tuple()
|
||||
assert f({}, API_VERSION) == dict()
|
||||
b = f('hello', API_VERSION)
|
||||
b = f(b'hello', API_VERSION)
|
||||
assert isinstance(b, Binary)
|
||||
assert b.data == 'hello'
|
||||
assert b.data == b'hello'
|
||||
u = f(u'hello', API_VERSION)
|
||||
assert type(u) is unicode
|
||||
assert u == u'hello'
|
||||
value = f([dict(one=False, two=u'hello'), None, 'hello'], API_VERSION)
|
||||
value = f([dict(one=False, two=u'hello'), None, b'hello'], API_VERSION)
|
||||
|
||||
|
||||
def test_xml_unwrap():
|
||||
@@ -120,8 +120,8 @@ def test_xml_unwrap():
|
||||
assert value == utf8_bytes
|
||||
assert f(utf8_bytes) == unicode_str
|
||||
assert f(unicode_str) == unicode_str
|
||||
value = f([True, Binary('hello'), dict(one=1, two=utf8_bytes, three=None)])
|
||||
assert value == (True, 'hello', dict(one=1, two=unicode_str, three=None))
|
||||
value = f([True, Binary(b'hello'), dict(one=1, two=utf8_bytes, three=None)])
|
||||
assert value == (True, b'hello', dict(one=1, two=unicode_str, three=None))
|
||||
assert type(value[1]) is bytes
|
||||
assert type(value[2]['two']) is unicode
|
||||
|
||||
@@ -134,7 +134,7 @@ def test_xml_dumps():
|
||||
params = (binary_bytes, utf8_bytes, unicode_str, None)
|
||||
|
||||
# Test serializing an RPC request:
|
||||
data = f(params, API_VERSION, 'the_method')
|
||||
data = f(params, API_VERSION, b'the_method')
|
||||
(p, m) = loads(data)
|
||||
assert_equal(m, u'the_method')
|
||||
assert type(p) is tuple
|
||||
@@ -165,7 +165,7 @@ def test_xml_loads():
|
||||
wrapped = rpc.xml_wrap(params, API_VERSION)
|
||||
|
||||
# Test un-serializing an RPC request:
|
||||
data = dumps(wrapped, 'the_method', allow_none=True)
|
||||
data = dumps(wrapped, b'the_method', allow_none=True)
|
||||
(p, m) = f(data)
|
||||
assert_equal(m, u'the_method')
|
||||
assert_equal(p, params)
|
||||
|
||||
@@ -306,7 +306,7 @@ class test_LDAPEntry(object):
|
||||
assert nice == [2, 3, u'5']
|
||||
assert raw == ['3', '5', '2']
|
||||
|
||||
raw = ['a', 'b']
|
||||
raw = [b'a', b'b']
|
||||
e.raw['test'] = raw
|
||||
assert e['test'] is not nice
|
||||
assert e['test'] == [u'a', u'b']
|
||||
@@ -314,7 +314,7 @@ class test_LDAPEntry(object):
|
||||
nice = 'not list'
|
||||
e['test'] = nice
|
||||
assert e['test'] is nice
|
||||
assert e.raw['test'] == ['not list']
|
||||
assert e.raw['test'] == [b'not list']
|
||||
|
||||
e.raw['test'].append('second')
|
||||
assert e['test'] == ['not list', u'second']
|
||||
|
||||
@@ -201,13 +201,13 @@ def test_entry_to_dict():
|
||||
DN('cn=test'),
|
||||
textattr=[u'text'],
|
||||
dnattr=[DN('cn=test')],
|
||||
binaryattr=['\xffabcd'],
|
||||
binaryattr=[b'\xffabcd'],
|
||||
attributelevelrights=rights)
|
||||
the_dict = {
|
||||
u'dn': u'cn=test',
|
||||
u'textattr': [u'text'],
|
||||
u'dnattr': [u'cn=test'],
|
||||
u'binaryattr': ['\xffabcd'],
|
||||
u'binaryattr': [b'\xffabcd'],
|
||||
u'attributelevelrights': rights}
|
||||
assert_deepequal(
|
||||
baseldap.entry_to_dict(entry, all=True, raw=True),
|
||||
|
||||
Reference in New Issue
Block a user