diff options
author | Peter Wu <peter@lekensteyn.nl> | 2015-06-28 00:33:57 +0200 |
---|---|---|
committer | Peter Wu <peter@lekensteyn.nl> | 2015-06-29 22:46:58 +0000 |
commit | b1ab36a81341535d46ef049113957d90baaf25f8 (patch) | |
tree | 2f0cb2c45abbcdc4b86150c899be52cf8340cf8a /tools/asn2wrs.py | |
parent | a6f9cf568238a25116973be69da2556b56d27d7f (diff) |
tools/asn2wrs.py: fix isdn-sup generation with Py3
Python 3 has removed the cmp function for sort functions, relying on a
key function instead.
Tested with Python 2.7.10 and 3.4.3.
Change-Id: Id571b836304528ecc3b23a0f8a2843c4538c3e1b
Reviewed-on: https://code.wireshark.org/review/9212
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Diffstat (limited to 'tools/asn2wrs.py')
-rwxr-xr-x | tools/asn2wrs.py | 26 |
1 files changed, 10 insertions, 16 deletions
diff --git a/tools/asn2wrs.py b/tools/asn2wrs.py index a319961084..064029798f 100755 --- a/tools/asn2wrs.py +++ b/tools/asn2wrs.py @@ -73,8 +73,6 @@ import traceback import lex import yacc -from functools import partial - if sys.version_info[0] < 3: from string import maketrans @@ -1937,19 +1935,6 @@ class EthCtx: #--- eth_output_table ----------------------------------------------------- def eth_output_table(self, fx, rep): - def cmp_fn(a, b, cmp_flds, objs): - if not cmp_flds: return 0 - obja = objs[a] - objb = objs[b] - res = 0 - for f in cmp_flds: - if f[0] == '#': - f = f[1:] - res = int(obja[f]) - int(objb[f]) - else: - res = cmp(obja[f], objb[f]) - if res: break - return res if rep['type'] == 'HDR': fx.write('\n') if rep['var']: @@ -1985,7 +1970,16 @@ class EthCtx: objs[ident] = obj objs_ord.append(ident) if (sort_flds): - objs_ord.sort(cmp=partial(cmp_fn, cmp_flds=sort_flds, objs=objs)) + # Sort identifiers according to the matching object in objs. + # The order is determined by sort_flds, keys prefixed by a + # '#' are compared numerically. + def obj_key_fn(name): + obj = objs[name] + return list( + int(obj[f[1:]]) if f[0] == '#' else obj[f] + for f in sort_flds + ) + objs_ord.sort(key=obj_key_fn) for ident in objs_ord: obj = objs[ident] try: |