##// END OF EJS Templates
Small fixes as per @certik's review.
Fernando Perez -
Show More
@@ -109,7 +109,7 b' class AutoMagics(Magics):'
109 109 else:
110 110 arg = 'toggle'
111 111
112 if not arg in (0, 1, 2,'toggle'):
112 if not arg in (0, 1, 2, 'toggle'):
113 113 error('Valid modes: (0->Off, 1->Smart, 2->Full')
114 114 return
115 115
@@ -71,7 +71,7 b' class BasicMagics(Magics):'
71 71 mode = parameter_s.split()[0][1:]
72 72 if mode == 'rest':
73 73 rest_docs = []
74 except:
74 except IndexError:
75 75 pass
76 76
77 77 magic_docs = []
@@ -249,7 +249,7 b' class CodeMagics(Magics):'
249 249 filename = make_filename(args)
250 250 datafile = 1
251 251 warn('Could not find file where `%s` is defined.\n'
252 'Opening a file named `%s`' % (args,filename))
252 'Opening a file named `%s`' % (args, filename))
253 253 # Now, make sure we can actually read the source (if it was
254 254 # in a temp file it's gone by now).
255 255 if datafile:
@@ -259,8 +259,8 b' class CodeMagics(Magics):'
259 259 except IOError:
260 260 filename = make_filename(args)
261 261 if filename is None:
262 warn('The file `%s` where `%s` was defined cannot '
263 'be read.' % (filename,data))
262 warn('The file `%s` where `%s` was defined '
263 'cannot be read.' % (filename, data))
264 264 return
265 265 use_temp = False
266 266
@@ -448,9 +448,9 b' class NamespaceMagics(Magics):'
448 448 vdtype = var.dtype
449 449
450 450 if vbytes < 100000:
451 print aformat % (vshape,vsize,vdtype,vbytes)
451 print aformat % (vshape, vsize, vdtype, vbytes)
452 452 else:
453 print aformat % (vshape,vsize,vdtype,vbytes),
453 print aformat % (vshape, vsize, vdtype, vbytes),
454 454 if vbytes < Mb:
455 455 print '(%s kb)' % (vbytes/kb,)
456 456 else:
@@ -463,7 +463,7 b' class NamespaceMagics(Magics):'
463 463 'backslashreplace')
464 464 except:
465 465 vstr = "<object with id %d (str() failed)>" % id(var)
466 vstr = vstr.replace('\n','\\n')
466 vstr = vstr.replace('\n', '\\n')
467 467 if len(vstr) < 50:
468 468 print vstr
469 469 else:
@@ -316,7 +316,7 b' class OSMagics(Magics):'
316 316
317 317 if ps in bkms:
318 318 target = bkms[ps]
319 print '(bookmark:%s) -> %s' % (ps,target)
319 print '(bookmark:%s) -> %s' % (ps, target)
320 320 ps = target
321 321 else:
322 322 if 'b' in opts:
@@ -522,24 +522,24 b' class OSMagics(Magics):'
522 522 .s (or .spstr): value as space-separated string.
523 523 """
524 524
525 opts,args = self.parse_options(parameter_s,'lv')
525 opts,args = self.parse_options(parameter_s, 'lv')
526 526 # Try to get a variable name and command to run
527 527 try:
528 528 # the variable name must be obtained from the parse_options
529 529 # output, which uses shlex.split to strip options out.
530 var,_ = args.split('=',1)
530 var,_ = args.split('=', 1)
531 531 var = var.strip()
532 532 # But the command has to be extracted from the original input
533 533 # parameter_s, not on what parse_options returns, to avoid the
534 534 # quote stripping which shlex.split performs on it.
535 _,cmd = parameter_s.split('=',1)
535 _,cmd = parameter_s.split('=', 1)
536 536 except ValueError:
537 537 var,cmd = '',''
538 538 # If all looks ok, proceed
539 539 split = 'l' in opts
540 540 out = self.shell.getoutput(cmd, split=split)
541 541 if 'v' in opts:
542 print '%s ==\n%s' % (var,pformat(out))
542 print '%s ==\n%s' % (var, pformat(out))
543 543 if var:
544 544 self.shell.user_ns.update({var:out})
545 545 else:
@@ -127,7 +127,7 b' class StoreMagics(Magics):'
127 127 vars = self.db.keys('autorestore/*')
128 128 vars.sort()
129 129 if vars:
130 size = max(map(len,vars))
130 size = max(map(len, vars))
131 131 else:
132 132 size = 0
133 133
@@ -137,7 +137,7 b' class StoreMagics(Magics):'
137 137 for var in vars:
138 138 justkey = os.path.basename(var)
139 139 # print 30 first characters from every var
140 print fmt % (justkey,repr(get(var,'<unavailable>'))[:50])
140 print fmt % (justkey, repr(get(var, '<unavailable>'))[:50])
141 141
142 142 # default action - store the variable
143 143 else:
@@ -145,17 +145,17 b' class StoreMagics(Magics):'
145 145 if len(args) > 1 and args[1].startswith('>'):
146 146 fnam = os.path.expanduser(args[1].lstrip('>').lstrip())
147 147 if args[1].startswith('>>'):
148 fil = open(fnam,'a')
148 fil = open(fnam, 'a')
149 149 else:
150 fil = open(fnam,'w')
150 fil = open(fnam, 'w')
151 151 obj = ip.ev(args[0])
152 152 print "Writing '%s' (%s) to file '%s'." % (args[0],
153 153 obj.__class__.__name__, fnam)
154 154
155 155
156 if not isinstance (obj,basestring):
156 if not isinstance (obj, basestring):
157 157 from pprint import pprint
158 pprint(obj,fil)
158 pprint(obj, fil)
159 159 else:
160 160 fil.write(obj)
161 161 if not obj.endswith('\n'):
General Comments 0
You need to be logged in to leave comments. Login now