Show More
@@ -253,8 +253,8 b' class Demo(object):' | |||||
253 | # load user data and initialize data structures |
|
253 | # load user data and initialize data structures | |
254 | self.reload() |
|
254 | self.reload() | |
255 |
|
255 | |||
256 |
def |
|
256 | def fload(self): | |
257 | """Reload source from disk and initialize state.""" |
|
257 | """Load file object.""" | |
258 | # read data and parse into blocks |
|
258 | # read data and parse into blocks | |
259 | if hasattr(self, 'fobj') and self.fobj is not None: |
|
259 | if hasattr(self, 'fobj') and self.fobj is not None: | |
260 | self.fobj.close() |
|
260 | self.fobj.close() | |
@@ -265,6 +265,10 b' class Demo(object):' | |||||
265 | # Assume it's a string or something that can be converted to one |
|
265 | # Assume it's a string or something that can be converted to one | |
266 | self.fobj = open(self.fname) |
|
266 | self.fobj = open(self.fname) | |
267 |
|
267 | |||
|
268 | def reload(self): | |||
|
269 | """Reload source from disk and initialize state.""" | |||
|
270 | self.fload() | |||
|
271 | ||||
268 | self.src = self.fobj.read() |
|
272 | self.src = self.fobj.read() | |
269 | src_b = [b.strip() for b in self.re_stop.split(self.src) if b] |
|
273 | src_b = [b.strip() for b in self.re_stop.split(self.src) if b] | |
270 | self._silent = [bool(self.re_silent.findall(b)) for b in src_b] |
|
274 | self._silent = [bool(self.re_silent.findall(b)) for b in src_b] | |
@@ -504,14 +508,20 b' class LineDemo(Demo):' | |||||
504 | This class doesn't require any markup at all, and it's meant for simple |
|
508 | This class doesn't require any markup at all, and it's meant for simple | |
505 | scripts (with no nesting or any kind of indentation) which consist of |
|
509 | scripts (with no nesting or any kind of indentation) which consist of | |
506 | multiple lines of input to be executed, one at a time, as if they had been |
|
510 | multiple lines of input to be executed, one at a time, as if they had been | |
507 |
typed in the interactive prompt. |
|
511 | typed in the interactive prompt. | |
|
512 | ||||
|
513 | Note: the input can not have *any* indentation, which means that only | |||
|
514 | single-lines of input are accepted, not even function definitions are | |||
|
515 | valid.""" | |||
508 |
|
516 | |||
509 | def reload(self): |
|
517 | def reload(self): | |
510 | """Reload source from disk and initialize state.""" |
|
518 | """Reload source from disk and initialize state.""" | |
511 | # read data and parse into blocks |
|
519 | # read data and parse into blocks | |
512 | src_b = [l for l in self.fobj.readline() if l.strip()] |
|
520 | self.fload() | |
|
521 | lines = self.fobj.readlines() | |||
|
522 | src_b = [l for l in lines if l.strip()] | |||
513 | nblocks = len(src_b) |
|
523 | nblocks = len(src_b) | |
514 |
self.src = |
|
524 | self.src = ''.join(lines) | |
515 | self._silent = [False]*nblocks |
|
525 | self._silent = [False]*nblocks | |
516 | self._auto = [True]*nblocks |
|
526 | self._auto = [True]*nblocks | |
517 | self.auto_all = True |
|
527 | self.auto_all = True |
General Comments 0
You need to be logged in to leave comments.
Login now