diff options
author | Brett Cannon <brett@python.org> | 2012-01-25 23:58:03 (GMT) |
---|---|---|
committer | Brett Cannon <brett@python.org> | 2012-01-25 23:58:03 (GMT) |
commit | c264e3ee206d5e5d1cb2aeff2cb0cd864dce83c8 (patch) | |
tree | dd9152609b6e0afb824d9aa731cae056e0cb1cb1 /Lib/importlib/__init__.py | |
parent | b0f30c9891a3ef45d616bf3ae73d764fd539946b (diff) | |
download | cpython-c264e3ee206d5e5d1cb2aeff2cb0cd864dce83c8.zip cpython-c264e3ee206d5e5d1cb2aeff2cb0cd864dce83c8.tar.gz cpython-c264e3ee206d5e5d1cb2aeff2cb0cd864dce83c8.tar.bz2 |
Move some code from importlib.__init__ to importlib._bootstrap that
does not need to be exposed from C code for bootstrapping reasons.
Diffstat (limited to 'Lib/importlib/__init__.py')
-rw-r--r-- | Lib/importlib/__init__.py | 43 |
1 files changed, 11 insertions, 32 deletions
diff --git a/Lib/importlib/__init__.py b/Lib/importlib/__init__.py index 9b20367..9672b36 100644 --- a/Lib/importlib/__init__.py +++ b/Lib/importlib/__init__.py @@ -26,8 +26,15 @@ import os import re import tokenize +# To simplify imports in test code +_w_long = _bootstrap._w_long +_r_long = _bootstrap._r_long + + # Bootstrap help ##################################################### +# TODO: Expose from import.c, else handle encode/decode as _os.environ returns +# bytes. def _case_ok(directory, check): """Check if the directory contains something matching 'check'. @@ -36,37 +43,13 @@ def _case_ok(directory, check): """ if 'PYTHONCASEOK' in os.environ: return True - elif check in os.listdir(directory if directory else os.getcwd()): + if not directory: + directory = os.getcwd() + if check in os.listdir(directory): return True return False - -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 = [] - int_bytes.append(x & 0xFF) - int_bytes.append((x >> 8) & 0xFF) - int_bytes.append((x >> 16) & 0xFF) - int_bytes.append((x >> 24) & 0xFF) - return bytearray(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 +_bootstrap._case_ok = _case_ok # Required built-in modules. @@ -94,10 +77,6 @@ from os import sep # For os.path.join replacement; pull from Include/osdefs.h:SEP . _bootstrap.path_sep = sep -_bootstrap._case_ok = _case_ok -marshal._w_long = _w_long -marshal._r_long = _r_long - # Public API ######################################################### |