##// END OF EJS Templates
more cleanups...
fperez -
Show More
@@ -5,7 +5,7 b' General purpose utilities.'
5 5 This is a grab-bag of stuff I find useful in most programs I write. Some of
6 6 these things are also convenient when working at the command line.
7 7
8 $Id: genutils.py 960 2005-12-28 06:51:01Z fperez $"""
8 $Id: genutils.py 967 2005-12-29 09:02:13Z fperez $"""
9 9
10 10 #*****************************************************************************
11 11 # Copyright (C) 2001-2004 Fernando Perez. <fperez@colorado.edu>
@@ -860,6 +860,7 b' class LSString(str):'
860 860
861 861 n = nlstr = property(get_nlstr)
862 862
863 #----------------------------------------------------------------------------
863 864 class SList(list):
864 865 """List derivative with a special access attributes.
865 866
@@ -895,6 +896,19 b' class SList(list):'
895 896
896 897 n = nlstr = property(get_nlstr)
897 898
899 #----------------------------------------------------------------------------
900 # This can be replaced with an isspace() call once we drop 2.2 compatibility
901 _isspace_match = re.compile(r'^\s+$').match
902 def isspace(s):
903 return bool(_isspace_match(s))
904
905 #----------------------------------------------------------------------------
906 def esc_quotes(strng):
907 """Return the input string with single and double quotes escaped out"""
908
909 return strng.replace('"','\\"').replace("'","\\'")
910
911 #----------------------------------------------------------------------------
898 912 def raw_input_multi(header='', ps1='==> ', ps2='..> ',terminate_str = '.'):
899 913 """Take multiple lines of input.
900 914
@@ -1026,6 +1040,19 b' def qwflat(words,sep=None,maxsplit=-1):'
1026 1040 """Calls qw(words) in flat mode. It's just a convenient shorthand."""
1027 1041 return qw(words,1,sep,maxsplit)
1028 1042
1043 #----------------------------------------------------------------------------
1044 def qw_lol(indata):
1045 """qw_lol('a b') -> [['a','b']],
1046 otherwise it's just a call to qw().
1047
1048 We need this to make sure the modules_some keys *always* end up as a
1049 list of lists."""
1050
1051 if type(indata) in StringTypes:
1052 return [qw(indata)]
1053 else:
1054 return qw(indata)
1055
1029 1056 #-----------------------------------------------------------------------------
1030 1057 def list_strings(arg):
1031 1058 """Always return a list of strings, given a string or list of strings
@@ -1585,6 +1612,15 b' def map_method(method,object_list,*argseq,**kw):'
1585 1612 return out_list
1586 1613
1587 1614 #----------------------------------------------------------------------------
1615 def import_fail_info(mod_name,fns=None):
1616 """Inform load failure for a module."""
1617
1618 if fns == None:
1619 warn("Loading of %s failed.\n" % (mod_name,))
1620 else:
1621 warn("Loading of %s from %s failed.\n" % (fns,mod_name))
1622
1623 #----------------------------------------------------------------------------
1588 1624 # Proposed popitem() extension, written as a method
1589 1625
1590 1626 class NotGiven: pass
@@ -6,7 +6,7 b' Requires Python 2.1 or newer.'
6 6
7 7 This file contains all the classes and helper functions specific to IPython.
8 8
9 $Id: iplib.py 966 2005-12-29 08:34:07Z fperez $
9 $Id: iplib.py 967 2005-12-29 09:02:13Z fperez $
10 10 """
11 11
12 12 #*****************************************************************************
@@ -81,35 +81,24 b' raw_input_original = raw_input'
81 81 #****************************************************************************
82 82 # Some utility function definitions
83 83
84 # This can be replaced with an isspace() call once we drop 2.2 compatibility
85 _isspace_match = re.compile(r'^\s+$').match
86 def isspace(s):
87 return bool(_isspace_match(s))
88
89 def esc_quotes(strng):
90 """Return the input string with single and double quotes escaped out"""
91
92 return strng.replace('"','\\"').replace("'","\\'")
93
94 def import_fail_info(mod_name,fns=None):
95 """Inform load failure for a module."""
96
97 if fns == None:
98 warn("Loading of %s failed.\n" % (mod_name,))
99 else:
100 warn("Loading of %s from %s failed.\n" % (fns,mod_name))
101
102 def qw_lol(indata):
103 """qw_lol('a b') -> [['a','b']],
104 otherwise it's just a call to qw().
105
106 We need this to make sure the modules_some keys *always* end up as a
107 list of lists."""
84 def softspace(file, newvalue):
85 """Copied from code.py, to remove the dependency"""
86 oldvalue = 0
87 try:
88 oldvalue = file.softspace
89 except AttributeError:
90 pass
91 try:
92 file.softspace = newvalue
93 except (AttributeError, TypeError):
94 # "attribute-less object" or "read-only attributes"
95 pass
96 return oldvalue
108 97
109 if type(indata) in StringTypes:
110 return [qw(indata)]
111 else:
112 return qw(indata)
98 #****************************************************************************
99 # These special functions get installed in the builtin namespace, to provide
100 # programmatic (pure python) access to magics and aliases. This is important
101 # for logging, user scripting, and more.
113 102
114 103 def ipmagic(arg_s):
115 104 """Call a magic function by name.
@@ -173,21 +162,6 b' def ipalias(arg_s):'
173 162 else:
174 163 error("Alias `%s` not found." % alias_name)
175 164
176 def softspace(file, newvalue):
177 """Copied from code.py, to remove the dependency"""
178 oldvalue = 0
179 try:
180 oldvalue = file.softspace
181 except AttributeError:
182 pass
183 try:
184 file.softspace = newvalue
185 except (AttributeError, TypeError):
186 # "attribute-less object" or "read-only attributes"
187 pass
188 return oldvalue
189
190
191 165 #****************************************************************************
192 166 # Local use exceptions
193 167 class SpaceInInput(exceptions.Exception): pass
@@ -249,7 +223,6 b' class SyntaxTB(ultraTB.ListTB):'
249 223 # 'self.magic_', 'self.options_table', 'self.parse', 'self.shell',
250 224 # 'self.value']
251 225
252
253 226 class InteractiveShell(Magic):
254 227 """An enhanced console for Python."""
255 228
@@ -1802,10 +1775,12 b' want to merge them back into the new files.""" % locals()'
1802 1775 """Handle alias input lines. """
1803 1776
1804 1777 theRest = esc_quotes(theRest)
1805 line_out = "%s%s.call_alias('%s','%s')" % (pre,self.name,iFun,theRest)
1806 self.log(line_out,continue_prompt)
1807 self.update_cache(line_out)
1808 return line_out
1778 # log the ipalias form, which doesn't depend on the instance name
1779 line_log = 'ipalias("%s %s")' % (iFun,theRest)
1780 self.log(line_log,continue_prompt)
1781 self.update_cache(line_log)
1782 # this is what actually gets executed
1783 return "%s%s.call_alias('%s','%s')" % (pre,self.name,iFun,theRest)
1809 1784
1810 1785 def handle_shell_escape(self, line, continue_prompt=None,
1811 1786 pre=None,iFun=None,theRest=None):
@@ -6,7 +6,7 b' Requires Python 2.1 or better.'
6 6
7 7 This file contains the main make_IPython() starter function.
8 8
9 $Id: ipmaker.py 966 2005-12-29 08:34:07Z fperez $"""
9 $Id: ipmaker.py 967 2005-12-29 09:02:13Z fperez $"""
10 10
11 11 #*****************************************************************************
12 12 # Copyright (C) 2001-2004 Fernando Perez. <fperez@colorado.edu>
@@ -49,7 +49,7 b' from IPython import DPyGetOpt'
49 49 from IPython.Struct import Struct
50 50 from IPython.OutputTrap import OutputTrap
51 51 from IPython.ConfigLoader import ConfigLoader
52 from IPython.iplib import InteractiveShell,qw_lol,import_fail_info
52 from IPython.iplib import InteractiveShell
53 53 from IPython.usage import cmd_line_usage,interactive_usage
54 54 from IPython.genutils import *
55 55
General Comments 0
You need to be logged in to leave comments. Login now