Load /Users/solydzajs/Desktop/google_appengine into
[Melange.git] / thirdparty / google_appengine / google / appengine / dist / py_imp.py
bloba6a0f3889b39af2a6a12a7aa120057b67c39d87c
1 #!/usr/bin/env python
3 # Copyright 2007 Google Inc.
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
18 """Stub replacement for Python's imp module."""
21 import os
22 import sys
25 PY_SOURCE, PY_COMPILED, C_EXTENSION = 1, 2, 3
26 PKG_DIRECTORY, C_BUILTIN, PY_FROZEN = 5, 6, 7
29 def get_magic():
30 """Return the magic string used to recognize byte-compiled code files."""
31 return '\0\0\0\0'
34 _PY_SOURCE_SUFFIX = ('.py', 'U', PY_SOURCE)
35 _PKG_DIRECTORY_SUFFIX = ('', '', PKG_DIRECTORY)
38 def get_suffixes():
39 """Return a list that describes the files that find_module() looks for."""
40 return [_PY_SOURCE_SUFFIX]
43 def find_module(name, path=None):
44 """Try to find the named module on the given search path or sys.path."""
45 if path == None:
46 path = sys.path
48 for directory in path:
49 filename = os.path.join(directory, '%s.py' % name)
50 if os.path.exists(filename):
51 return open(filename, 'U'), filename, _PY_SOURCE_SUFFIX
53 dirname = os.path.join(directory, name)
54 filename = os.path.join(dirname, '__init__.py')
55 if os.path.exists(filename):
56 return None, dirname, _PKG_DIRECTORY_SUFFIX
58 raise ImportError('No module named %s' % name)
61 def load_module(name, file_, pathname, description):
62 """Load or reload the specified module.
64 Please note that this function has only rudimentary supported on App Engine:
65 Only loading packages is supported.
66 """
67 suffix, mode, type_ = description
68 if type_ == PKG_DIRECTORY:
69 if name in sys.modules:
70 mod = sys.modules[name]
71 else:
72 mod = new_module(name)
73 sys.modules[name] = mod
74 filename = os.path.join(pathname, '__init__.py')
75 mod.__file__ = filename
76 execfile(filename, mod.__dict__, mod.__dict__)
77 return mod
78 else:
79 raise NotImplementedError('Only importing packages is supported on '
80 'App Engine')
83 def new_module(name):
84 """Return a new empty module object."""
85 return type(sys)(name)
88 def lock_held():
89 """Return False since threading is not supported."""
90 return False
93 def acquire_lock():
94 """Acquiring the lock is a no-op since no threading is supported."""
95 pass
98 def release_lock():
99 """There is no lock to release since acquiring is a no-op when there is no
100 threading."""
101 pass
104 def init_builtin(name):
105 raise NotImplementedError('This function is not supported on App Engine.')
108 def init_frozen(name):
109 raise NotImplementedError('This function is not supported on App Engine.')
112 def is_builtin(name):
113 return name in sys.builtin_module_names
116 def is_frozen(name):
117 return False
120 def load_compiled(name, pathname, file_=None):
121 raise NotImplementedError('This function is not supported on App Engine.')
124 def load_dynamic(name, pathname, file_=None):
125 raise NotImplementedError('This function is not supported on App Engine.')
128 def load_source(name, pathname, file_=None):
129 raise NotImplementedError('This function is not supported on App Engine.')
132 class NullImporter(object):
133 """Null importer object"""
135 def __init__(self, path_string):
136 if not path_string:
137 raise ImportError("empty pathname")
138 elif os.path.isdir(path_string):
139 raise ImportError("existing directory")
141 def find_module(self, fullname):
142 return None