diff options
author | Petr Viktorin <pviktori@redhat.com> | 2015-09-21 10:34:15 +0200 |
---|---|---|
committer | Tomas Babej <tbabej@redhat.com> | 2015-10-13 14:16:32 +0200 |
commit | 905d81f500d40b44c8e7f284af11300057e3d1b7 (patch) | |
tree | b5853a08125740b65b01000883ec42274ab12074 /ipalib | |
parent | be876987f527cd9d574f02385ed95e1bd0d5b91b (diff) | |
download | freeipa-905d81f500d40b44c8e7f284af11300057e3d1b7.tar.gz freeipa-905d81f500d40b44c8e7f284af11300057e3d1b7.tar.xz freeipa-905d81f500d40b44c8e7f284af11300057e3d1b7.zip |
ipalib.aci: Port to Python 3
- Don't encode under Python 3, where shlex would choke on bytes
- Sort the attrs dictionary in export_to_string, so the tests are
deterministic. (The iteration order of dicts was always unspecified,
but was always the same in practice under CPython 2.)
Reviewed-By: Tomas Babej <tbabej@redhat.com>
Diffstat (limited to 'ipalib')
-rwxr-xr-x | ipalib/aci.py | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/ipalib/aci.py b/ipalib/aci.py index 687ac6357..a76435f0a 100755 --- a/ipalib/aci.py +++ b/ipalib/aci.py @@ -75,16 +75,16 @@ class ACI: """Output a Directory Server-compatible ACI string""" self.validate() aci = "" - for t in self.target: - op = self.target[t]['operator'] - if type(self.target[t]['expression']) in (tuple, list): + for t, v in sorted(self.target.items()): + op = v['operator'] + if type(v['expression']) in (tuple, list): target = "" - for l in self.target[t]['expression']: + for l in v['expression']: target = target + l + " || " target = target[:-4] aci = aci + "(%s %s \"%s\")" % (t, op, target) else: - aci = aci + "(%s %s \"%s\")" % (t, op, self.target[t]['expression']) + aci = aci + "(%s %s \"%s\")" % (t, op, v['expression']) aci = aci + "(version 3.0;acl \"%s\";%s (%s) %s %s \"%s\"" % (self.name, self.action, ",".join(self.permissions), self.bindrule['keyword'], self.bindrule['operator'], self.bindrule['expression']) + ";)" return aci @@ -97,7 +97,9 @@ class ACI: return s def _parse_target(self, aci): - lexer = shlex.shlex(aci.encode('utf-8')) + if six.PY2: + aci = aci.encode('utf-8') + lexer = shlex.shlex(aci) lexer.wordchars = lexer.wordchars + "." l = [] |