# HG changeset patch # User Augie Fackler # Date 2018-04-27 15:06:49 # Node ID 2ae6a31343628073af839e092ba9866bdebd155b # Parent 2efefde3af70c6c91d88c004392cd7917706eff7 cborutil: port to Python 3 The only problem lurking in here was sorts of mismatched types. The sorts are only for output stability in our tests (sigh), so we just build a phony sort key using the __name__ of types so that we only compare like types against each other. By pure luck, my awful sort key matches the behavior we get "for free" in Python 2, so no test output changes. Differential Revision: https://phab.mercurial-scm.org/D3504 diff --git a/mercurial/utils/cborutil.py b/mercurial/utils/cborutil.py --- a/mercurial/utils/cborutil.py +++ b/mercurial/utils/cborutil.py @@ -140,12 +140,15 @@ def streamencodearrayfromiter(it): yield BREAK +def _mixedtypesortkey(v): + return type(v).__name__, v + def streamencodeset(s): # https://www.iana.org/assignments/cbor-tags/cbor-tags.xhtml defines # semantic tag 258 for finite sets. yield encodelength(MAJOR_TYPE_SEMANTIC, 258) - for chunk in streamencodearray(sorted(s)): + for chunk in streamencodearray(sorted(s, key=_mixedtypesortkey)): yield chunk def streamencodemap(d): @@ -155,7 +158,8 @@ def streamencodemap(d): """ yield encodelength(MAJOR_TYPE_MAP, len(d)) - for key, value in sorted(d.iteritems()): + for key, value in sorted(d.iteritems(), + key=lambda x: _mixedtypesortkey(x[0])): for chunk in streamencode(key): yield chunk for chunk in streamencode(value):