Tryag File Manager
Home
-
Turbo Force
Current Path :
/
proc
/
self
/
root
/
usr
/
lib
/
python2.4
/
lib-old
/
Upload File :
New :
File
Dir
//proc/self/root/usr/lib/python2.4/lib-old/ni.pyo
m๒ =5Dc @ sศ d Z d k Z d k Z d k Z d k Z d k l Z l Z d e f d YZ d e f d YZ d d Z d Z d d Z d Z d Z d Z e d j o e n e d S( sฯ New import scheme with package support. Quick Reference --------------- - To enable package support, execute "import ni" before importing any packages. Importing this module automatically installs the relevant import hooks. - To create a package named spam containing sub-modules ham, bacon and eggs, create a directory spam somewhere on Python's module search path (i.e. spam's parent directory must be one of the directories in sys.path or $PYTHONPATH); then create files ham.py, bacon.py and eggs.py inside spam. - To import module ham from package spam and use function hamneggs() from that module, you can either do import spam.ham # *not* "import spam" !!! spam.ham.hamneggs() or from spam import ham ham.hamneggs() or from spam.ham import hamneggs hamneggs() - Importing just "spam" does not do what you expect: it creates an empty package named spam if one does not already exist, but it does not import spam's submodules. The only submodule that is guaranteed to be imported is spam.__init__, if it exists. Note that spam.__init__ is a submodule of package spam. It can reference to spam's namespace via the '__.' prefix, for instance __.spam_inited = 1 # Set a package-level variable Theory of Operation ------------------- A Package is a module that can contain other modules. Packages can be nested. Package introduce dotted names for modules, like P.Q.M, which could correspond to a file P/Q/M.py found somewhere on sys.path. It is possible to import a package itself, though this makes little sense unless the package contains a module called __init__. A package has two variables that control the namespace used for packages and modules, both initialized to sensible defaults the first time the package is referenced. (1) A package's *module search path*, contained in the per-package variable __path__, defines a list of *directories* where submodules or subpackages of the package are searched. It is initialized to the directory containing the package. Setting this variable to None makes the module search path default to sys.path (this is not quite the same as setting it to sys.path, since the latter won't track later assignments to sys.path). (2) A package's *import domain*, contained in the per-package variable __domain__, defines a list of *packages* that are searched (using their respective module search paths) to satisfy imports. It is initialized to the list consisting of the package itself, its parent package, its parent's parent, and so on, ending with the root package (the nameless package containing all top-level packages and modules, whose module search path is None, implying sys.path). The default domain implements a search algorithm called "expanding search". An alternative search algorithm called "explicit search" fixes the import search path to contain only the root package, requiring the modules in the package to name all imported modules by their full name. The convention of using '__' to refer to the current package (both as a per-module variable and in module names) can be used by packages using explicit search to refer to modules in the same package; this combination is known as "explicit-relative search". The PackageImporter and PackageLoader classes together implement the following policies: - There is a root package, whose name is ''. It cannot be imported directly but may be referenced, e.g. by using '__' from a top-level module. - In each module or package, the variable '__' contains a reference to the parent package; in the root package, '__' points to itself. - In the name for imported modules (e.g. M in "import M" or "from M import ..."), a leading '__' refers to the current package (i.e. the package containing the current module); leading '__.__' and so on refer to the current package's parent, and so on. The use of '__' elsewhere in the module name is not supported. - Modules are searched using the "expanding search" algorithm by virtue of the default value for __domain__. - If A.B.C is imported, A is searched using __domain__; then subpackage B is searched in A using its __path__, and so on. - Built-in modules have priority: even if a file sys.py exists in a package, "import sys" imports the built-in sys module. - The same holds for frozen modules, for better or for worse. - Submodules and subpackages are not automatically loaded when their parent packages is loaded. - The construct "from package import *" is illegal. (It can still be used to import names from a module.) - When "from package import module1, module2, ..." is used, those modules are explicitly loaded. - When a package is loaded, if it has a submodule __init__, that module is loaded. This is the place where required submodules can be loaded, the __path__ variable extended, etc. The __init__ module is loaded even if the package was loaded only in order to create a stub for a sub-package: if "import P.Q.R" is the first reference to P, and P has a submodule __init__, P.__init__ is loaded before P.Q is even searched. Caveats: - It is possible to import a package that has no __init__ submodule; this is not particularly useful but there may be useful applications for it (e.g. to manipulate its search paths from the outside!). - There are no special provisions for os.chdir(). If you plan to use os.chdir() before you have imported all your modules, it is better not to have relative pathnames in sys.path. (This could actually be fixed by changing the implementation of path_join() in the hook to absolutize paths.) - Packages and modules are introduced in sys.modules as soon as their loading is started. When the loading is terminated by an exception, the sys.modules entries remain around. - There are no special measures to support mutually recursive modules, but it will work under the same conditions where it works in the flat module space system. - Sometimes dummy entries (whose value is None) are entered in sys.modules, to indicate that a particular module does not exist -- this is done to speed up the expanding search algorithm when a module residing at a higher level is repeatedly imported (Python promises that importing a previously imported module is cheap!) - Although dynamically loaded extensions are allowed inside packages, the current implementation (hardcoded in the interpreter) of their initialization may cause problems if an extension invokes the interpreter during its initialization. - reload() may find another version of the module only if it occurs on the package search path. Thus, it keeps the connection to the package to which the module belongs, but may find a different file. XXX Need to have an explicit name for '', e.g. '__root__'. N( s ModuleLoaders ModuleImportert PackageLoaderc B sV t Z d Z d Z d Z d Z d Z d Z d Z d Z d Z RS( s๎ A subclass of ModuleLoader with package support. find_module_in_dir() will succeed if there's a subdirectory with the given name; load_module() will create a stub for a package and load its __init__ module if it exists. c C s] | d j o= | i i | | } | i i | o d | d f SqJ n t i | | | S( Nt t PACKAGE( R R R ( t dirt Nonet selft hookst path_joint namet dirnamet path_isdirt ModuleLoadert find_module_in_dir( R R R R ( ( t /usr/lib/python2.4/lib-old/ni.pyR ท s c C sา | \ } } } | \ } } } | d j o | i | | Sn t i i | o t i | } n t i | t i | <} | i | | t i j o! d | j o | i | | Sn t i | | | Sd S( NR t .( t stufft filet filenamet infot sufft modet typeR t load_packageR t syst modulest has_keyt mt impt new_modulet set_parentt C_EXTENSIONt load_dynamicR t load_module( R R R R R R R R R R ( ( R R พ s c C sล | \ } } \ } } } | i d } | | d } t i i | o t i | } n d } t i | t i | <z t i | | | } Wd | o | t i | <n t i | =X| t i | <| S( NR i ( R R R R R R R t rfindt it tailR R R t saveR R R R R ( R R R R R"