|
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 75 of file Include.py.
◆ __init__()
def python.Include.Include.__init__ |
( |
|
self, |
|
|
|
show = True , |
|
|
|
collect = 1 , |
|
|
|
clean = False |
|
) |
| |
Definition at line 78 of file Include.py.
78 def __init__( self, show = True, collect = 1, clean = False ):
82 self.msg = Logging.logging.getLogger(
'Athena' )
88 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 111 of file Include.py.
111 def __call__( self, fn, *args, **kw ):
112 """Include <fn> in the current scope by executing it globally."""
115 if isinstance(fn, str)
and len(fn) == 0:
116 raise IncludeError(
"can not 'include' empty filenames")
120 self.msg.
debug(
'file "%s" is blocked; not included', fn )
124 name =
FindFile( os.path.expanduser( os.path.expandvars( fn ) ), optionsPath, os.R_OK )
126 name =
FindFile( os.path.basename( fn ), optionsPath, os.R_OK )
128 self.msg.warning(
'using %s instead of %s', name, fn )
130 raise IncludeError(
'include file %s can not be found' % fn )
132 self.msg.
debug(
'located %s as %s', fn, name )
141 self.msg.
info(
'including file "%s" with ID %d', fn, self.fid )
143 self.msg.
info(
'including file "%s"', fn )
144 self._fcurrent = name
147 if show
and self._doTrace( name ):
149 _filecache[ name ] =
open( name,
'r' ).readlines()
150 _linecache[ name ] = 0, self.fid
153 from past.builtins
import execfile
154 sys.settrace( self._trace_include )
155 execfile( name, self._workspace, self._workspace )
156 sys.settrace( sys._getframe(0).f_trace )
159 ncur, fid = _linecache[ name ]
160 buf = _filecache[ name ]
161 for i
in range( ncur, len(buf) ):
162 self._oneline( fid, i, silentMarker, buf )
164 del _filecache[ name ]
165 del _linecache[ name ]
167 self.msg.
info(
'end of "%s"', fn )
172 exec(compile(
open(name).
read(), name,
'exec'), self._workspace, self._workspace)
175 if hasattr( self,
'_collect' ):
176 if not self._collect % 10:
◆ _doTrace()
def python.Include.Include._doTrace |
( |
|
self, |
|
|
|
fn |
|
) |
| |
|
private |
Definition at line 196 of file Include.py.
196 def _doTrace( self, fn ):
205 for tracePattern
in excludeTracePattern:
206 if fnmatch.fnmatch( fn, tracePattern ):
211 for tracePattern
in includeTracePattern:
212 if fnmatch.fnmatch( fn, tracePattern ):
◆ _oneline()
def python.Include.Include._oneline |
( |
|
self, |
|
|
|
fid, |
|
|
|
lineno, |
|
|
|
detail, |
|
|
|
buf |
|
) |
| |
|
private |
Definition at line 284 of file Include.py.
284 def _oneline( self, fid, lineno, detail, buf ):
285 print (marker, fidMarker % fid, lineMarker % lineno, detail,)
290 if not buf
or not buf[ lineno ]:
295 line = buf[ lineno ].rstrip()
296 while line
and ( line[-1] ==
'(' or line[-1] ==
'\\' ):
304 print (marker, fidMarker % fid, lineMarker % lineno, detail,)
305 line = buf[ lineno ].rstrip()
314 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 222 of file Include.py.
222 def _trace_include( self, frame, event, arg ):
223 fn = frame.f_code.co_filename
224 if fn.find (
'importlib._bootstrap') >= 0:
225 return self._trace_include
227 if not os.path.exists( fn ):
230 if not ( fn
and self._doTrace( fn ) ):
231 return self._trace_include
233 if fn
not in _filecache:
238 if 'import' in _filecache[ f.f_code.co_filename ][ f.f_lineno ]:
239 return self._trace_include
246 _filecache[ fn ] =
open( fn,
'r' ).readlines()
or '\n'
247 _linecache[ fn ] = sys.maxsize, self.fid
251 aln = lno - 1 > 0
and lno - 1
or 0
253 ncur, fid = _linecache[ fn ]
254 buf = _filecache[ fn ]
256 if self._fcurrent != fn:
261 for i
in range( ncur, aln ):
262 self._oneline( fid, i, silentMarker, buf )
265 self._oneline( fid, aln, activeMarker, buf )
267 self._oneline( fid, aln, tracedMarker, buf )
270 _linecache[ fn ] = lno, fid
272 elif event ==
'call':
274 self._oneline( fid, aln, callMarker, buf )
276 elif event ==
'return':
278 fln = frame.f_code.co_firstlineno - 1
279 self._oneline( fid, fln, returnMarker,
None )
281 return self._trace_include
◆ block()
def python.Include.Include.block |
( |
|
self, |
|
|
|
fn |
|
) |
| |
Disallow the given filename(s) from being included again.
Definition at line 182 of file Include.py.
182 def block( self, fn ):
183 """Disallow the given filename(s) from being included again."""
◆ setClean()
def python.Include.Include.setClean |
( |
|
self, |
|
|
|
clean |
|
) |
| |
Definition at line 102 of file Include.py.
102 def setClean( self, clean ):
105 if self._workspace
is __main__.__dict__:
107 self._workspace.update( __main__.__dict__ )
109 self._workspace = __main__.__dict__
◆ setCollect()
def python.Include.Include.setCollect |
( |
|
self, |
|
|
|
collect |
|
) |
| |
Definition at line 96 of file Include.py.
96 def setCollect( self, collect ):
97 if collect
and not hasattr( self,
'_collect' ):
99 elif not collect
and hasattr( self,
'_collect' ):
◆ setShowIncludes()
def python.Include.Include.setShowIncludes |
( |
|
self, |
|
|
|
show |
|
) |
| |
Definition at line 93 of file Include.py.
93 def setShowIncludes( self, show ):
◆ unblock()
def python.Include.Include.unblock |
( |
|
self, |
|
|
|
fn |
|
) |
| |
Re-allow the given filename from being included.
Definition at line 190 of file Include.py.
190 def unblock( self, fn ):
191 """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: