|
def | __init__ (self, show=True, collect=1, clean=False) |
|
def | setShowIncludes (self, show) |
|
def | setCollect (self, collect) |
|
def | setClean (self, clean) |
|
def | __call__ (self, fn, *args, **kw) |
|
def | block (self, fn) |
|
def | unblock (self, fn) |
|
Definition at line 76 of file Include.py.
◆ __init__()
def python.Include.Include.__init__ |
( |
|
self, |
|
|
|
show = True , |
|
|
|
collect = 1 , |
|
|
|
clean = False |
|
) |
| |
Definition at line 79 of file Include.py.
79 def __init__( self, show = True, collect = 1, clean = False ):
83 self.msg = Logging.logging.getLogger(
'Athena' )
89 self._workspace = __main__.__dict__
◆ __call__()
def python.Include.Include.__call__ |
( |
|
self, |
|
|
|
fn, |
|
|
* |
args, |
|
|
** |
kw |
|
) |
| |
Include <fn> in the current scope by executing it globally.
Definition at line 112 of file Include.py.
112 def __call__( self, fn, *args, **kw ):
113 """Include <fn> in the current scope by executing it globally."""
116 if isinstance(fn, str)
and len(fn) == 0:
117 raise IncludeError(
"can not 'include' empty filenames")
121 self.msg.
debug(
'file "%s" is blocked; not included', fn )
125 name =
FindFile( os.path.expanduser( os.path.expandvars( fn ) ), optionsPath, os.R_OK )
127 name =
FindFile( os.path.basename( fn ), optionsPath, os.R_OK )
129 self.msg.warning(
'using %s instead of %s', name, fn )
131 raise IncludeError(
'include file %s can not be found' % fn )
133 self.msg.
debug(
'located %s as %s', fn, name )
142 self.msg.
info(
'including file "%s" with ID %d', fn, self.fid )
144 self.msg.
info(
'including file "%s"', fn )
145 self._fcurrent = name
148 if show
and self._doTrace( name ):
150 _filecache[ name ] =
open( name,
'r' ).readlines()
151 _linecache[ name ] = 0, self.fid
154 from past.builtins
import execfile
155 sys.settrace( self._trace_include )
156 execfile( name, self._workspace, self._workspace )
157 sys.settrace( sys._getframe(0).f_trace )
160 ncur, fid = _linecache[ name ]
161 buf = _filecache[ name ]
162 for i
in range( ncur, len(buf) ):
163 self._oneline( fid, i, silentMarker, buf )
165 del _filecache[ name ]
166 del _linecache[ name ]
168 self.msg.
info(
'end of "%s"', fn )
173 exec(compile(
open(name).
read(), name,
'exec'), self._workspace, self._workspace)
176 if hasattr( self,
'_collect' ):
177 if not self._collect % 10:
◆ _doTrace()
def python.Include.Include._doTrace |
( |
|
self, |
|
|
|
fn |
|
) |
| |
|
private |
Definition at line 197 of file Include.py.
197 def _doTrace( self, fn ):
206 for tracePattern
in excludeTracePattern:
207 if fnmatch.fnmatch( fn, tracePattern ):
212 for tracePattern
in includeTracePattern:
213 if fnmatch.fnmatch( fn, tracePattern ):
◆ _oneline()
def python.Include.Include._oneline |
( |
|
self, |
|
|
|
fid, |
|
|
|
lineno, |
|
|
|
detail, |
|
|
|
buf |
|
) |
| |
|
private |
Definition at line 285 of file Include.py.
285 def _oneline( self, fid, lineno, detail, buf ):
286 print (marker, fidMarker % fid, lineMarker % lineno, detail,)
291 if not buf
or not buf[ lineno ]:
296 line = buf[ lineno ].rstrip()
297 while line
and ( line[-1] ==
'(' or line[-1] ==
'\\' ):
305 print (marker, fidMarker % fid, lineMarker % lineno, detail,)
306 line = buf[ lineno ].rstrip()
315 log.warning(
'index (%d) out of range while scanning include file %d', lineno, fid )
◆ _trace_include()
def python.Include.Include._trace_include |
( |
|
self, |
|
|
|
frame, |
|
|
|
event, |
|
|
|
arg |
|
) |
| |
|
private |
Definition at line 223 of file Include.py.
223 def _trace_include( self, frame, event, arg ):
224 fn = frame.f_code.co_filename
225 if fn.find (
'importlib._bootstrap') >= 0:
226 return self._trace_include
228 if not os.path.exists( fn ):
231 if not ( fn
and self._doTrace( fn ) ):
232 return self._trace_include
234 if fn
not in _filecache:
239 if 'import' in _filecache[ f.f_code.co_filename ][ f.f_lineno ]:
240 return self._trace_include
247 _filecache[ fn ] =
open( fn,
'r' ).readlines()
or '\n'
248 _linecache[ fn ] = sys.maxsize, self.fid
252 aln = lno - 1 > 0
and lno - 1
or 0
254 ncur, fid = _linecache[ fn ]
255 buf = _filecache[ fn ]
257 if self._fcurrent != fn:
262 for i
in range( ncur, aln ):
263 self._oneline( fid, i, silentMarker, buf )
266 self._oneline( fid, aln, activeMarker, buf )
268 self._oneline( fid, aln, tracedMarker, buf )
271 _linecache[ fn ] = lno, fid
273 elif event ==
'call':
275 self._oneline( fid, aln, callMarker, buf )
277 elif event ==
'return':
279 fln = frame.f_code.co_firstlineno - 1
280 self._oneline( fid, fln, returnMarker,
None )
282 return self._trace_include
◆ block()
def python.Include.Include.block |
( |
|
self, |
|
|
|
fn |
|
) |
| |
Disallow the given filename(s) from being included again.
Definition at line 183 of file Include.py.
183 def block( self, fn ):
184 """Disallow the given filename(s) from being included again."""
◆ setClean()
def python.Include.Include.setClean |
( |
|
self, |
|
|
|
clean |
|
) |
| |
Definition at line 103 of file Include.py.
103 def setClean( self, clean ):
106 if self._workspace
is __main__.__dict__:
108 self._workspace.
update( __main__.__dict__ )
110 self._workspace = __main__.__dict__
◆ setCollect()
def python.Include.Include.setCollect |
( |
|
self, |
|
|
|
collect |
|
) |
| |
Definition at line 97 of file Include.py.
97 def setCollect( self, collect ):
98 if collect
and not hasattr( self,
'_collect' ):
100 elif not collect
and hasattr( self,
'_collect' ):
◆ setShowIncludes()
def python.Include.Include.setShowIncludes |
( |
|
self, |
|
|
|
show |
|
) |
| |
Definition at line 94 of file Include.py.
94 def setShowIncludes( self, show ):
◆ unblock()
def python.Include.Include.unblock |
( |
|
self, |
|
|
|
fn |
|
) |
| |
Re-allow the given filename from being included.
Definition at line 191 of file Include.py.
191 def unblock( self, fn ):
192 """Re-allow the given filename from being included."""
◆ _collect
python.Include.Include._collect |
|
private |
◆ _fcurrent
python.Include.Include._fcurrent |
|
private |
◆ _once
python.Include.Include._once |
|
private |
◆ _show
python.Include.Include._show |
|
private |
◆ _workspace
python.Include.Include._workspace |
|
private |
◆ fid
int python.Include.Include.fid = 0 |
|
static |
◆ msg
python.Include.Include.msg |
The documentation for this class was generated from the following file: