|
1 #!/usr/bin/env python |
|
2 # |
|
3 # Copyright 2007 Google Inc. |
|
4 # |
|
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 |
|
8 # |
|
9 # http://www.apache.org/licenses/LICENSE-2.0 |
|
10 # |
|
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. |
|
16 # |
|
17 |
|
18 """Stub replacement for Python's imp module.""" |
|
19 |
|
20 |
|
21 import os |
|
22 import sys |
|
23 |
|
24 |
|
25 PY_SOURCE, PY_COMPILED, C_EXTENSION = 1, 2, 3 |
|
26 PKG_DIRECTORY, C_BUILTIN, PY_FROZEN = 5, 6, 7 |
|
27 |
|
28 |
|
29 def get_magic(): |
|
30 return '\0\0\0\0' |
|
31 |
|
32 |
|
33 def get_suffixes(): |
|
34 return [('.py', 'U', PY_SOURCE)] |
|
35 |
|
36 |
|
37 def new_module(name): |
|
38 return type(sys.modules[__name__])(name) |
|
39 |
|
40 |
|
41 def lock_held(): |
|
42 """Return False since threading is not supported.""" |
|
43 return False |
|
44 |
|
45 def acquire_lock(): |
|
46 """Acquiring the lock is a no-op since no threading is supported.""" |
|
47 pass |
|
48 |
|
49 def release_lock(): |
|
50 """There is no lock to release since acquiring is a no-op when there is no |
|
51 threading.""" |
|
52 pass |
|
53 |
|
54 |
|
55 def is_builtin(name): |
|
56 return name in sys.builtin_module_names |
|
57 |
|
58 |
|
59 def is_frozen(name): |
|
60 return False |
|
61 |
|
62 |
|
63 class NullImporter(object): |
|
64 |
|
65 def __init__(self, path_string): |
|
66 if not path_string: |
|
67 raise ImportError("empty pathname") |
|
68 elif os.path.isdir(path_string): |
|
69 raise ImportError("existing directory") |
|
70 |
|
71 def find_module(self, fullname): |
|
72 return None |