Skip to content
Myr

Redefine the `unichr` and bytes-variant of `chr` at module level.

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Needed to appease Travis; it's python 2.6 and 2.7 builds are weird and the `__builtins__` dict is not following CPython conventions.

authored by Martijn Pieters · committed by Martijn Pieters · parent 25f2806 · Browse files · 1 file+5 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+5 added−2 removed

  • tests:+5 added−2 removed

1 file+5 added−2 removed

modified:tests/test_utils.py+5 added-2 removed
10 unmodified lines
11import requests.utils12from requests.compat import is_py3, bytes131415if is_py3:16 unichr = chr17 chr = lambda c: bytes([c])181920class GuessJSONUTFTests(unittest.TestCase):21 """Tests for the JSON UTF encoding guessing code."""2223 codecs = (
4 unmodified lines
2829 def test_guess_encoding(self):30 # Throw 4-character ASCII strings (encoded to a UTF encoding)31 # at the guess routine; it should correctly guess all codecs.27 unichr = chr if is_py3 else __builtins__.unichr32 guess = requests.utils.guess_json_utf33 for c in range(33, 127): # printable only34 sample = unichr(c) * 435 for codec in self.codecs:
3 unmodified lines
39 def test_smoke_encoding(self):40 # Throw random 4-byte strings at the guess function.41 # Any guess for a UTF encoding is verified, a decode exception42 # is a test failure.39 chr = (lambda c: bytes([c])) if is_py3 else __builtins__.chr43 guess = requests.utils.guess_json_utf44 for i in range(1000):45 sample = bytes().join(46 [chr(random.randrange(256)) for _ in range(4)])
10 unmodified lines