The dom.scope module¶
The Scope class finds included documents.
-
class
Scope(doc, parent=None, factory=None, node=None)[source]¶ Bases:
objectA Scope helps finding files included by a parce Document.
Initialize Scope with a parce Document. The
urlattribute of the document helps finding included files. That url should be absolute.The
parentis specified when a new Scope is created byinclude_scope().The
factorykeyword parameter and attribute is a callable that should return aparce.Documentfor a filename. If you don’t specify a factory, a default one is used that loads a Document from the file system, and if found, caches it using a cache based on the file’s mtime.Specify a factory to use other caching, deferred loading, or to look for a document in a list of open documents in a GUI editor etc.
If desired, add absolute urls to the
include_pathinstance attribute, indicating folders where to search for includeable files.-
parent= None¶ The parent Scope (None for the root Scope)
-
factory= None¶ A callable returning a
parce.Documentfor a filename.
-
node= None¶ The node that was specified to
include_scope().
-
include_path= None¶ A list of directories to search for include-d files.
-
relative_include= None¶ Whether to search in the directory of an included file for new includes.
-
include_scope(url, node=None)[source]¶ Return a child scope for the url.
If the
urlis relative, it is resolved against our document’s url (ifrelative_includeis True), the root scope’s url and the urls in theinclude_path.A
nodecan be given, that’s simply put in thenodeattribute of the returned child scope. It can be used to look further in the document that included the current document, to find e.g. a variable definition.Returns None if no includable document could be found. This scope inherits the factory, the include_path and the relative_include setting of ourselves.
-
urls(url)[source]¶ Return a list of unique urls representing possibly includable files.
The list results from the filename of our document (if set and if
relative_includeis True), the filename of the document that started the include chain, and the include path.The urls are not checked for existence.
-