just alignment of custom_import

This commit is contained in:
mdipierro
2012-10-11 09:23:36 -05:00
parent 5358ad271e
commit 1d03233c83
3 changed files with 18 additions and 26 deletions
+1 -1
View File
@@ -1 +1 @@
Version 2.1.0 (2012-10-11 08:27:52) dev Version 2.1.0 (2012-10-11 09:23:31) dev
+14 -22
View File
@@ -22,7 +22,6 @@ def is_tracking_changes():
@return: True: neo_importer is tracking changes made to Python source @return: True: neo_importer is tracking changes made to Python source
files. False: neo_import does not reload Python modules. files. False: neo_import does not reload Python modules.
""" """
global _is_tracking_changes global _is_tracking_changes
return _is_tracking_changes return _is_tracking_changes
@@ -73,12 +72,9 @@ class _BaseImporter(object):
""" """
The import method itself. The import method itself.
""" """
return self._STANDARD_PYTHON_IMPORTER(name, return self._STANDARD_PYTHON_IMPORTER(
globals, name,globals,locals,fromlist,level)
locals,
fromlist,
level)
def end(self): def end(self):
""" """
Needed for clean up. Needed for clean up.
@@ -232,16 +228,12 @@ class _Web2pyImporter(_BaseImporter):
self.super_class.__init__() self.super_class.__init__()
self.web2py_path = web2py_path self.web2py_path = web2py_path
self.__web2py_path_os_path_sep = self.web2py_path+os.path.sep self.__web2py_path_os_path_sep = self.web2py_path+os.path.sep
self.__web2py_path_os_path_sep_len = len(self.__web2py_path_os_path_sep) self.__web2py_path_os_path_sep_len = \
len(self.__web2py_path_os_path_sep)
self.__RE_APP_DIR = re.compile( self.__RE_APP_DIR = re.compile(
self._RE_ESCAPED_PATH_SEP.join( \ self._RE_ESCAPED_PATH_SEP.join(( \
( \ #"^" + re.escape(web2py_path),# Not working with Python 2.5
#"^" + re.escape(web2py_path), # Not working with Python 2.5 "^(" + "applications","[^","]+)","")))
"^(" + "applications",
"[^",
"]+)",
"",
) ))
def _matchAppDir(self, file_path): def _matchAppDir(self, file_path):
""" """
@@ -270,8 +262,8 @@ class _Web2pyImporter(_BaseImporter):
and not name.startswith("applications.") \ and not name.startswith("applications.") \
and isinstance(globals, dict): and isinstance(globals, dict):
# Get the name of the file do the import # Get the name of the file do the import
caller_file_name = os.path.join(self.web2py_path, \ caller_file_name = os.path.join(
globals.get("__file__", "")) self.web2py_path, globals.get("__file__", ""))
# Is the path in an application directory? # Is the path in an application directory?
match_app_dir = self._matchAppDir(caller_file_name) match_app_dir = self._matchAppDir(caller_file_name)
if match_app_dir: if match_app_dir:
@@ -293,11 +285,11 @@ class _Web2pyImporter(_BaseImporter):
except ImportError, e: except ImportError, e:
try: try:
return self.super_class.__call__(name, globals, locals, return self.super_class.__call__(name, globals, locals,
fromlist, level) fromlist, level)
except ImportError, e1: except ImportError, e1:
raise e raise e
return self.super_class.__call__(name, globals, locals, return self.super_class.__call__(name, globals, locals,
fromlist, level) fromlist, level)
def __import__dot(self, prefix, name, globals, locals, fromlist, def __import__dot(self, prefix, name, globals, locals, fromlist,
level): level):
@@ -311,8 +303,8 @@ class _Web2pyImporter(_BaseImporter):
result = None result = None
for name in name.split("."): for name in name.split("."):
new_mod = super(_Web2pyImporter, self).__call__(prefix, globals, new_mod = super(_Web2pyImporter, self).__call__(
locals, [name], level) prefix, globals,locals, [name], level)
try: try:
result = result or new_mod.__dict__[name] result = result or new_mod.__dict__[name]
except KeyError, e: except KeyError, e:
+3 -3
View File
@@ -19,7 +19,7 @@ import optparse
import glob import glob
import traceback import traceback
import fileutils import fileutils
import settings from settings import global_settings
from utils import web2py_uuid from utils import web2py_uuid
from compileapp import build_environment, read_pyc, run_models_in from compileapp import build_environment, read_pyc, run_models_in
from restricted import RestrictedError from restricted import RestrictedError
@@ -27,7 +27,7 @@ from globals import Request, Response, Session
from storage import Storage from storage import Storage
from admin import w2p_unpack from admin import w2p_unpack
from dal import BaseAdapter from dal import BaseAdapter
from custom_import import custom_import_install
logger = logging.getLogger("web2py") logger = logging.getLogger("web2py")
@@ -112,7 +112,7 @@ def env(
request.env.path_info = '/%s/%s/%s' % (a, c, f) request.env.path_info = '/%s/%s/%s' % (a, c, f)
request.env.http_host = '127.0.0.1:8000' request.env.http_host = '127.0.0.1:8000'
request.env.remote_addr = '127.0.0.1' request.env.remote_addr = '127.0.0.1'
request.env.web2py_runtime_gae = settings.global_settings.web2py_runtime_gae request.env.web2py_runtime_gae = global_settings.web2py_runtime_gae
for k,v in extra_request.items(): for k,v in extra_request.items():
request[k] = v request[k] = v