diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2014-12-12 08:51:19 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2014-12-12 08:51:19 -0500 |
commit | 59889252937e31ab4c3b734922c63dd529e26e03 (patch) | |
tree | 94b7823a9ab7f04f52c8e37cdc29453376b3edc4 /coverage/backward.py | |
parent | c76154ce75adbebb461d4cb0a524e6c08b4ed5f7 (diff) | |
download | python-coveragepy-59889252937e31ab4c3b734922c63dd529e26e03.tar.gz |
Source is always Unicode in HTML code. More refactoring to come.
Diffstat (limited to 'coverage/backward.py')
-rw-r--r-- | coverage/backward.py | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/coverage/backward.py b/coverage/backward.py index 50b21f3..dfc169d 100644 --- a/coverage/backward.py +++ b/coverage/backward.py @@ -20,6 +20,12 @@ try: except NameError: string_class = str +# What's a Unicode string called? +try: + unicode_class = unicode +except NameError: + unicode_class = str + # Where do pickles come from? try: import cPickle as pickle @@ -66,6 +72,11 @@ if sys.version_info >= (3, 0): """Convert bytes `b` to a string.""" return b.decode('utf8') + def unicode_literal(s): + """Make a plain string literal into unicode.""" + # In Python 3, string literals already are unicode. + return s + def binary_bytes(byte_values): """Produce a byte string with the ints from `byte_values`.""" return bytes(byte_values) @@ -88,6 +99,11 @@ else: """Convert bytes `b` to a string (no-op in 2.x).""" return b + def unicode_literal(s): + """Make a plain string literal into unicode.""" + # In Python 2, s is a byte string. + return s.decode('utf8') + def binary_bytes(byte_values): """Produce a byte string with the ints from `byte_values`.""" return "".join(chr(b) for b in byte_values) @@ -117,13 +133,14 @@ try: except ImportError: importlib = None -# we only want to use importlib if it has everything we need. +# We only want to use importlib if it has everything we need. try: importlib_util_find_spec = importlib.util.find_spec except Exception: import imp importlib_util_find_spec = None +# What is the .pyc magic number for this version of Python? try: PYC_MAGIC_NUMBER = importlib.util.MAGIC_NUMBER except AttributeError: |