##// END OF EJS Templates
Move arg_split to genutils, so it can be used for other things.
fptest -
Show More
@@ -1,7 +1,7 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 """Magic functions for InteractiveShell.
2 """Magic functions for InteractiveShell.
3
3
4 $Id: Magic.py 1829 2006-10-16 08:04:11Z vivainio $"""
4 $Id: Magic.py 1845 2006-10-27 20:35:47Z fptest $"""
5
5
6 #*****************************************************************************
6 #*****************************************************************************
7 # Copyright (C) 2001 Janko Hauser <jhauser@zscout.de> and
7 # Copyright (C) 2001 Janko Hauser <jhauser@zscout.de> and
@@ -26,7 +26,6 b' import inspect'
26 import os
26 import os
27 import pdb
27 import pdb
28 import pydoc
28 import pydoc
29 import shlex
30 import sys
29 import sys
31 import re
30 import re
32 import tempfile
31 import tempfile
@@ -62,17 +61,6 b' def on_off(tag):'
62
61
63 class Bunch: pass
62 class Bunch: pass
64
63
65 def arg_split(s,posix=True):
66 """Split a command line's arguments in a shell-like manner.
67
68 This is a modified version of the standard library's shlex.split()
69 function, but with a default of posix=False for splitting, so that quotes
70 in inputs are respected."""
71
72 lex = shlex.shlex(s, posix=posix)
73 lex.whitespace_split = True
74 return list(lex)
75
76 #***************************************************************************
64 #***************************************************************************
77 # Main class implementing Magic functionality
65 # Main class implementing Magic functionality
78 class Magic:
66 class Magic:
@@ -1489,7 +1477,7 b' Currently the magic system has the following functions:\\n"""'
1489 # Since '%run foo' emulates 'python foo.py' at the cmd line, we must
1477 # Since '%run foo' emulates 'python foo.py' at the cmd line, we must
1490 # set the __file__ global in the script's namespace
1478 # set the __file__ global in the script's namespace
1491 prog_ns['__file__'] = filename
1479 prog_ns['__file__'] = filename
1492
1480
1493 # pickle fix. See iplib for an explanation. But we need to make sure
1481 # pickle fix. See iplib for an explanation. But we need to make sure
1494 # that, if we overwrite __main__, we replace it at the end
1482 # that, if we overwrite __main__, we replace it at the end
1495 if prog_ns['__name__'] == '__main__':
1483 if prog_ns['__name__'] == '__main__':
@@ -1553,7 +1541,8 b' Currently the magic system has the following functions:\\n"""'
1553 nruns = 1
1541 nruns = 1
1554 if nruns == 1:
1542 if nruns == 1:
1555 t0 = clock2()
1543 t0 = clock2()
1556 runner(filename,prog_ns,prog_ns,exit_ignore=exit_ignore)
1544 runner(filename,prog_ns,prog_ns,
1545 exit_ignore=exit_ignore)
1557 t1 = clock2()
1546 t1 = clock2()
1558 t_usr = t1[0]-t0[0]
1547 t_usr = t1[0]-t0[0]
1559 t_sys = t1[1]-t1[1]
1548 t_sys = t1[1]-t1[1]
@@ -1564,7 +1553,8 b' Currently the magic system has the following functions:\\n"""'
1564 runs = range(nruns)
1553 runs = range(nruns)
1565 t0 = clock2()
1554 t0 = clock2()
1566 for nr in runs:
1555 for nr in runs:
1567 runner(filename,prog_ns,prog_ns,exit_ignore=exit_ignore)
1556 runner(filename,prog_ns,prog_ns,
1557 exit_ignore=exit_ignore)
1568 t1 = clock2()
1558 t1 = clock2()
1569 t_usr = t1[0]-t0[0]
1559 t_usr = t1[0]-t0[0]
1570 t_sys = t1[1]-t1[1]
1560 t_sys = t1[1]-t1[1]
@@ -5,7 +5,7 b' General purpose utilities.'
5 This is a grab-bag of stuff I find useful in most programs I write. Some of
5 This is a grab-bag of stuff I find useful in most programs I write. Some of
6 these things are also convenient when working at the command line.
6 these things are also convenient when working at the command line.
7
7
8 $Id: genutils.py 1349 2006-06-04 00:57:43Z fperez $"""
8 $Id: genutils.py 1845 2006-10-27 20:35:47Z fptest $"""
9
9
10 #*****************************************************************************
10 #*****************************************************************************
11 # Copyright (C) 2001-2006 Fernando Perez. <fperez@colorado.edu>
11 # Copyright (C) 2001-2006 Fernando Perez. <fperez@colorado.edu>
@@ -24,6 +24,7 b' import __main__'
24 import commands
24 import commands
25 import os
25 import os
26 import re
26 import re
27 import shlex
27 import shutil
28 import shutil
28 import sys
29 import sys
29 import tempfile
30 import tempfile
@@ -233,6 +234,17 b' def timing(func,*args,**kw):'
233 #****************************************************************************
234 #****************************************************************************
234 # file and system
235 # file and system
235
236
237 def arg_split(s,posix=False):
238 """Split a command line's arguments in a shell-like manner.
239
240 This is a modified version of the standard library's shlex.split()
241 function, but with a default of posix=False for splitting, so that quotes
242 in inputs are respected."""
243
244 lex = shlex.shlex(s, posix=posix)
245 lex.whitespace_split = True
246 return list(lex)
247
236 def system(cmd,verbose=0,debug=0,header=''):
248 def system(cmd,verbose=0,debug=0,header=''):
237 """Execute a system command, return its exit status.
249 """Execute a system command, return its exit status.
238
250
General Comments 0
You need to be logged in to leave comments. Login now