##// END OF EJS Templates
more cleanups...
fperez -
Show More
@@ -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 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 # Copyright (C) 2001-2004 Fernando Perez. <fperez@colorado.edu>
11 # Copyright (C) 2001-2004 Fernando Perez. <fperez@colorado.edu>
@@ -860,6 +860,7 b' class LSString(str):'
860
860
861 n = nlstr = property(get_nlstr)
861 n = nlstr = property(get_nlstr)
862
862
863 #----------------------------------------------------------------------------
863 class SList(list):
864 class SList(list):
864 """List derivative with a special access attributes.
865 """List derivative with a special access attributes.
865
866
@@ -895,6 +896,19 b' class SList(list):'
895
896
896 n = nlstr = property(get_nlstr)
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 def raw_input_multi(header='', ps1='==> ', ps2='..> ',terminate_str = '.'):
912 def raw_input_multi(header='', ps1='==> ', ps2='..> ',terminate_str = '.'):
899 """Take multiple lines of input.
913 """Take multiple lines of input.
900
914
@@ -1026,6 +1040,19 b' def qwflat(words,sep=None,maxsplit=-1):'
1026 """Calls qw(words) in flat mode. It's just a convenient shorthand."""
1040 """Calls qw(words) in flat mode. It's just a convenient shorthand."""
1027 return qw(words,1,sep,maxsplit)
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 def list_strings(arg):
1057 def list_strings(arg):
1031 """Always return a list of strings, given a string or list of strings
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 return out_list
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 # Proposed popitem() extension, written as a method
1624 # Proposed popitem() extension, written as a method
1589
1625
1590 class NotGiven: pass
1626 class NotGiven: pass
@@ -6,7 +6,7 b' Requires Python 2.1 or newer.'
6
6
7 This file contains all the classes and helper functions specific to IPython.
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 # Some utility function definitions
82 # Some utility function definitions
83
83
84 # This can be replaced with an isspace() call once we drop 2.2 compatibility
84 def softspace(file, newvalue):
85 _isspace_match = re.compile(r'^\s+$').match
85 """Copied from code.py, to remove the dependency"""
86 def isspace(s):
86 oldvalue = 0
87 return bool(_isspace_match(s))
87 try:
88
88 oldvalue = file.softspace
89 def esc_quotes(strng):
89 except AttributeError:
90 """Return the input string with single and double quotes escaped out"""
90 pass
91
91 try:
92 return strng.replace('"','\\"').replace("'","\\'")
92 file.softspace = newvalue
93
93 except (AttributeError, TypeError):
94 def import_fail_info(mod_name,fns=None):
94 # "attribute-less object" or "read-only attributes"
95 """Inform load failure for a module."""
95 pass
96
96 return oldvalue
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."""
108
97
109 if type(indata) in StringTypes:
98 #****************************************************************************
110 return [qw(indata)]
99 # These special functions get installed in the builtin namespace, to provide
111 else:
100 # programmatic (pure python) access to magics and aliases. This is important
112 return qw(indata)
101 # for logging, user scripting, and more.
113
102
114 def ipmagic(arg_s):
103 def ipmagic(arg_s):
115 """Call a magic function by name.
104 """Call a magic function by name.
@@ -173,21 +162,6 b' def ipalias(arg_s):'
173 else:
162 else:
174 error("Alias `%s` not found." % alias_name)
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 # Local use exceptions
166 # Local use exceptions
193 class SpaceInInput(exceptions.Exception): pass
167 class SpaceInInput(exceptions.Exception): pass
@@ -249,7 +223,6 b' class SyntaxTB(ultraTB.ListTB):'
249 # 'self.magic_', 'self.options_table', 'self.parse', 'self.shell',
223 # 'self.magic_', 'self.options_table', 'self.parse', 'self.shell',
250 # 'self.value']
224 # 'self.value']
251
225
252
253 class InteractiveShell(Magic):
226 class InteractiveShell(Magic):
254 """An enhanced console for Python."""
227 """An enhanced console for Python."""
255
228
@@ -1802,10 +1775,12 b' want to merge them back into the new files.""" % locals()'
1802 """Handle alias input lines. """
1775 """Handle alias input lines. """
1803
1776
1804 theRest = esc_quotes(theRest)
1777 theRest = esc_quotes(theRest)
1805 line_out = "%s%s.call_alias('%s','%s')" % (pre,self.name,iFun,theRest)
1778 # log the ipalias form, which doesn't depend on the instance name
1806 self.log(line_out,continue_prompt)
1779 line_log = 'ipalias("%s %s")' % (iFun,theRest)
1807 self.update_cache(line_out)
1780 self.log(line_log,continue_prompt)
1808 return line_out
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 def handle_shell_escape(self, line, continue_prompt=None,
1785 def handle_shell_escape(self, line, continue_prompt=None,
1811 pre=None,iFun=None,theRest=None):
1786 pre=None,iFun=None,theRest=None):
@@ -6,7 +6,7 b' Requires Python 2.1 or better.'
6
6
7 This file contains the main make_IPython() starter function.
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 # Copyright (C) 2001-2004 Fernando Perez. <fperez@colorado.edu>
12 # Copyright (C) 2001-2004 Fernando Perez. <fperez@colorado.edu>
@@ -49,7 +49,7 b' from IPython import DPyGetOpt'
49 from IPython.Struct import Struct
49 from IPython.Struct import Struct
50 from IPython.OutputTrap import OutputTrap
50 from IPython.OutputTrap import OutputTrap
51 from IPython.ConfigLoader import ConfigLoader
51 from IPython.ConfigLoader import ConfigLoader
52 from IPython.iplib import InteractiveShell,qw_lol,import_fail_info
52 from IPython.iplib import InteractiveShell
53 from IPython.usage import cmd_line_usage,interactive_usage
53 from IPython.usage import cmd_line_usage,interactive_usage
54 from IPython.genutils import *
54 from IPython.genutils import *
55
55
General Comments 0
You need to be logged in to leave comments. Login now