DebugClients/Python3/coverage/backward.py

changeset 5051
3586ebd9fac8
parent 4489
d0d6e4ad31bd
--- a/DebugClients/Python3/coverage/backward.py	Sat Jul 23 13:33:54 2016 +0200
+++ b/DebugClients/Python3/coverage/backward.py	Sun Jul 24 12:01:01 2016 +0200
@@ -49,6 +49,15 @@
 except NameError:
     range = range
 
+# shlex.quote is new, but there's an undocumented implementation in "pipes",
+# who knew!?
+try:
+    from shlex import quote as shlex_quote
+except ImportError:
+    # Useful function, available under a different (undocumented) name
+    # in Python versions earlier than 3.3.
+    from pipes import quote as shlex_quote
+
 # A function to iterate listlessly over a dict's items.
 try:
     {}.iteritems
@@ -84,10 +93,6 @@
         """Produce a byte string with the ints from `byte_values`."""
         return bytes(byte_values)
 
-    def byte_to_int(byte_value):
-        """Turn an element of a bytes object into an int."""
-        return byte_value
-
     def bytes_to_ints(bytes_value):
         """Turn a bytes object into a sequence of ints."""
         # In Python 3, iterating bytes gives ints.
@@ -102,10 +107,6 @@
         """Produce a byte string with the ints from `byte_values`."""
         return "".join(chr(b) for b in byte_values)
 
-    def byte_to_int(byte_value):
-        """Turn an element of a bytes object into an int."""
-        return ord(byte_value)
-
     def bytes_to_ints(bytes_value):
         """Turn a bytes object into a sequence of ints."""
         for byte in bytes_value:
@@ -142,11 +143,12 @@
     PYC_MAGIC_NUMBER = imp.get_magic()
 
 
-def import_local_file(modname):
+def import_local_file(modname, modfile=None):
     """Import a local file as a module.
 
     Opens a file in the current directory named `modname`.py, imports it
-    as `modname`, and returns the module object.
+    as `modname`, and returns the module object.  `modfile` is the file to
+    import if it isn't in the current directory.
 
     """
     try:
@@ -154,7 +156,8 @@
     except ImportError:
         SourceFileLoader = None
 
-    modfile = modname + '.py'
+    if modfile is None:
+        modfile = modname + '.py'
     if SourceFileLoader:
         mod = SourceFileLoader(modname, modfile).load_module()
     else:

eric ide

mercurial