[Python-checkins] r58284 - sandbox/trunk/import_in_py/Py3K/_importlib.py sandbox/trunk/import_in_py/Py3K/importlib.py

brett.cannon python-checkins at python.org
Sat Sep 29 08:48:57 CEST 2007


Author: brett.cannon
Date: Sat Sep 29 08:48:57 2007
New Revision: 58284

Modified:
   sandbox/trunk/import_in_py/Py3K/_importlib.py
   sandbox/trunk/import_in_py/Py3K/importlib.py
Log:
Use marshal._r_long and _w_long instead of own implementation.


Modified: sandbox/trunk/import_in_py/Py3K/_importlib.py
==============================================================================
--- sandbox/trunk/import_in_py/Py3K/_importlib.py	(original)
+++ sandbox/trunk/import_in_py/Py3K/_importlib.py	Sat Sep 29 08:48:57 2007
@@ -62,7 +62,6 @@
 # Injected modules are 'warnings', 'imp', 'sys', 'marshal', 'errno', and '_os'
 # (a.k.a. 'posix', 'nt' or 'os2').
 # Injected attribute is path_sep.
-# XXX Temporarily injected functions are _r_long, _w_long.
 
 
 # XXX Could also expose Modules/getpath.c:joinpath()
@@ -501,7 +500,7 @@
         try:
             with open(self._bytecode_path(), 'rb') as bytecode_file:
                 data = bytecode_file.read()
-            return data[:4], _r_long(data[4:8]), data[8:]
+            return data[:4], marshal._r_long(data[4:8]), data[8:]
         except AttributeError:
             return None
 
@@ -521,7 +520,7 @@
         try:
             with open(bytecode_path, 'wb') as bytecode_file:
                 bytecode_file.write(imp.get_magic())
-                bytecode_file.write(_w_long(timestamp))
+                bytecode_file.write(marshal._w_long(timestamp))
                 bytecode_file.write(data)
                 return True
         except IOError as exc:

Modified: sandbox/trunk/import_in_py/Py3K/importlib.py
==============================================================================
--- sandbox/trunk/import_in_py/Py3K/importlib.py	(original)
+++ sandbox/trunk/import_in_py/Py3K/importlib.py	Sat Sep 29 08:48:57 2007
@@ -46,34 +46,6 @@
     __builtins__['__import__'] = original__import__
 
 
-def _w_long(x):
-    """Convert a 32-bit integer to little-endian.
-
-    XXX Temporary until marshal's long functions are exposed.
-
-    """
-    x = int(x)
-    int_bytes = bytes()
-    int_bytes.append(x & 0xFF)
-    int_bytes.append((x >> 8) & 0xFF)
-    int_bytes.append((x >> 16) & 0xFF)
-    int_bytes.append((x >> 24) & 0xFF)
-    return int_bytes
-
-
-def _r_long(int_bytes):
-    """Convert 4 bytes in little-endian to an integer.
-
-    XXX Temporary until marshal's long function are exposed.
-
-    """
-    x = int_bytes[0]
-    x |= int_bytes[1] << 8
-    x |= int_bytes[2] << 16
-    x |= int_bytes[3] << 24
-    return x
-
-
 # Required built-in modules.
 try:
     import posix as _os
@@ -97,8 +69,6 @@
 
 
 from os import sep
-_importlib._r_long = _r_long  #XXX Expose original from marshal.
-_importlib._w_long = _w_long  #XXX Expose original from marshal.
 # For os.path.join replacement; pull from Include/osdefs.h:SEP .
 _importlib.path_sep = sep
 


More information about the Python-checkins mailing list