##// END OF EJS Templates
Fix broken demo reload()....
Mark E. Smith -
Show More
@@ -222,7 +222,6 b' class Demo(object):'
222 """
222 """
223 if hasattr(src, "read"):
223 if hasattr(src, "read"):
224 # It seems to be a file or a file-like object
224 # It seems to be a file or a file-like object
225 self.fobj = src
226 self.fname = "from a file-like object"
225 self.fname = "from a file-like object"
227 if title == '':
226 if title == '':
228 self.title = "from a file-like object"
227 self.title = "from a file-like object"
@@ -230,7 +229,6 b' class Demo(object):'
230 self.title = title
229 self.title = title
231 else:
230 else:
232 # Assume it's a string or something that can be converted to one
231 # Assume it's a string or something that can be converted to one
233 self.fobj = open(src)
234 self.fname = src
232 self.fname = src
235 if title == '':
233 if title == '':
236 (filepath, filename) = os.path.split(src)
234 (filepath, filename) = os.path.split(src)
@@ -239,6 +237,7 b' class Demo(object):'
239 self.title = title
237 self.title = title
240 self.sys_argv = [src] + shlex.split(arg_str)
238 self.sys_argv = [src] + shlex.split(arg_str)
241 self.auto_all = auto_all
239 self.auto_all = auto_all
240 self.src = src
242
241
243 # get a few things from ipython. While it's a bit ugly design-wise,
242 # get a few things from ipython. While it's a bit ugly design-wise,
244 # it ensures that things like color scheme and the like are always in
243 # it ensures that things like color scheme and the like are always in
@@ -257,6 +256,15 b' class Demo(object):'
257 def reload(self):
256 def reload(self):
258 """Reload source from disk and initialize state."""
257 """Reload source from disk and initialize state."""
259 # read data and parse into blocks
258 # read data and parse into blocks
259 if hasattr(self, 'fobj') and self.fobj is not None:
260 self.fobj.close()
261 if hasattr(self.src, "read"):
262 # It seems to be a file or a file-like object
263 self.fobj = self.src
264 else:
265 # Assume it's a string or something that can be converted to one
266 self.fobj = open(self.fname)
267
260 self.src = self.fobj.read()
268 self.src = self.fobj.read()
261 src_b = [b.strip() for b in self.re_stop.split(self.src) if b]
269 src_b = [b.strip() for b in self.re_stop.split(self.src) if b]
262 self._silent = [bool(self.re_silent.findall(b)) for b in src_b]
270 self._silent = [bool(self.re_silent.findall(b)) for b in src_b]
General Comments 0
You need to be logged in to leave comments. Login now