# HG changeset patch # User Renato Cunha # Date 1281209918 10800 # Node ID 8bb1481cf08fc8c997522a24dd06585b7d2e1650 # Parent 1fe94103c6ee73e13dc0c590eda7874e96f8bc4d py3kcompat: added fake ord implementation for py3k In py3k, a bytes object __getitem__ will return an int instead of a one-character bytes object. This has negative consequences when we want to ord(), like in the following example: >>> b'foo'[0] 102 >>> ord(b'foo'[0]) Traceback (most recent call last): File "", line 1, in TypeError: ord() expected string of length 1, but int found This patch overrides the default ord() implementation to just return an int that's what is passed as an argument for ord(). Making the above call succeed: >>> ord(b'foo'[0]) 102 diff -r 1fe94103c6ee -r 8bb1481cf08f mercurial/py3kcompat.py --- a/mercurial/py3kcompat.py Sat Aug 14 03:30:35 2010 +0200 +++ b/mercurial/py3kcompat.py Sat Aug 07 16:38:38 2010 -0300 @@ -59,6 +59,13 @@ bvalue = os.environ[key].encode('utf-8', 'surrogateescape') os.environ[bkey] = bvalue +origord = builtins.ord +def fakeord(char): + if isinstance(char, int): + return char + return origord(char) +builtins.ord = fakeord + if __name__ == '__main__': import doctest doctest.testmod()