##// END OF EJS Templates
Change functions,...
Srinivas Reddy Thatiparthy -
Show More
@@ -20,7 +20,7 b' Authors:'
20
20
21 from traitlets.config.configurable import Configurable
21 from traitlets.config.configurable import Configurable
22
22
23 from IPython.utils.py3compat import builtin_mod, iteritems
23 from IPython.utils.py3compat import builtin_mod
24 from traitlets import Instance
24 from traitlets import Instance
25
25
26 #-----------------------------------------------------------------------------
26 #-----------------------------------------------------------------------------
@@ -90,14 +90,14 b' class BuiltinTrap(Configurable):'
90 """Store ipython references in the __builtin__ namespace."""
90 """Store ipython references in the __builtin__ namespace."""
91
91
92 add_builtin = self.add_builtin
92 add_builtin = self.add_builtin
93 for name, func in iteritems(self.auto_builtins):
93 for name, func in self.auto_builtins.items():
94 add_builtin(name, func)
94 add_builtin(name, func)
95
95
96 def deactivate(self):
96 def deactivate(self):
97 """Remove any builtins which might have been added by add_builtins, or
97 """Remove any builtins which might have been added by add_builtins, or
98 restore overwritten ones to their previous values."""
98 restore overwritten ones to their previous values."""
99 remove_builtin = self.remove_builtin
99 remove_builtin = self.remove_builtin
100 for key, val in iteritems(self._orig_builtins):
100 for key, val in self._orig_builtins.items():
101 remove_builtin(key, val)
101 remove_builtin(key, val)
102 self._orig_builtins.clear()
102 self._orig_builtins.clear()
103 self._builtins_added = False
103 self._builtins_added = False
@@ -68,7 +68,7 b' from IPython.paths import get_ipython_dir'
68 from IPython.utils.path import get_home_dir, get_py_filename, ensure_dir_exists
68 from IPython.utils.path import get_home_dir, get_py_filename, ensure_dir_exists
69 from IPython.utils.process import system, getoutput
69 from IPython.utils.process import system, getoutput
70 from IPython.utils.py3compat import (builtin_mod, unicode_type, string_types,
70 from IPython.utils.py3compat import (builtin_mod, unicode_type, string_types,
71 with_metaclass, iteritems)
71 with_metaclass)
72 from IPython.utils.strdispatch import StrDispatch
72 from IPython.utils.strdispatch import StrDispatch
73 from IPython.utils.syspathcontext import prepended_to_syspath
73 from IPython.utils.syspathcontext import prepended_to_syspath
74 from IPython.utils.text import format_screen, LSString, SList, DollarFormatter
74 from IPython.utils.text import format_screen, LSString, SList, DollarFormatter
@@ -733,7 +733,7 b' class InteractiveShell(SingletonConfigurable):'
733 def restore_sys_module_state(self):
733 def restore_sys_module_state(self):
734 """Restore the state of the sys module."""
734 """Restore the state of the sys module."""
735 try:
735 try:
736 for k, v in iteritems(self._orig_sys_module_state):
736 for k, v in self._orig_sys_module_state.items():
737 setattr(sys, k, v)
737 setattr(sys, k, v)
738 except AttributeError:
738 except AttributeError:
739 pass
739 pass
@@ -1255,7 +1255,7 b' class InteractiveShell(SingletonConfigurable):'
1255 # Also check in output history
1255 # Also check in output history
1256 ns_refs.append(self.history_manager.output_hist)
1256 ns_refs.append(self.history_manager.output_hist)
1257 for ns in ns_refs:
1257 for ns in ns_refs:
1258 to_delete = [n for n, o in iteritems(ns) if o is obj]
1258 to_delete = [n for n, o in ns.items() if o is obj]
1259 for name in to_delete:
1259 for name in to_delete:
1260 del ns[name]
1260 del ns[name]
1261
1261
@@ -1347,7 +1347,7 b' class InteractiveShell(SingletonConfigurable):'
1347 variables : dict
1347 variables : dict
1348 A dictionary mapping object names (as strings) to the objects.
1348 A dictionary mapping object names (as strings) to the objects.
1349 """
1349 """
1350 for name, obj in iteritems(variables):
1350 for name, obj in variables.items():
1351 if name in self.user_ns and self.user_ns[name] is obj:
1351 if name in self.user_ns and self.user_ns[name] is obj:
1352 del self.user_ns[name]
1352 del self.user_ns[name]
1353 self.user_ns_hidden.pop(name, None)
1353 self.user_ns_hidden.pop(name, None)
@@ -2382,7 +2382,7 b' class InteractiveShell(SingletonConfigurable):'
2382 user_ns = self.user_ns
2382 user_ns = self.user_ns
2383 global_ns = self.user_global_ns
2383 global_ns = self.user_global_ns
2384
2384
2385 for key, expr in iteritems(expressions):
2385 for key, expr in expressions.items():
2386 try:
2386 try:
2387 value = self._format_user_obj(eval(expr, global_ns, user_ns))
2387 value = self._format_user_obj(eval(expr, global_ns, user_ns))
2388 except:
2388 except:
@@ -24,7 +24,7 b' from IPython.core.inputsplitter import ESC_MAGIC, ESC_MAGIC2'
24 from decorator import decorator
24 from decorator import decorator
25 from IPython.utils.ipstruct import Struct
25 from IPython.utils.ipstruct import Struct
26 from IPython.utils.process import arg_split
26 from IPython.utils.process import arg_split
27 from IPython.utils.py3compat import string_types, iteritems
27 from IPython.utils.py3compat import string_types
28 from IPython.utils.text import dedent
28 from IPython.utils.text import dedent
29 from traitlets import Bool, Dict, Instance, observe
29 from traitlets import Bool, Dict, Instance, observe
30 from logging import error
30 from logging import error
@@ -344,7 +344,7 b' class MagicsManager(Configurable):'
344 docs = {}
344 docs = {}
345 for m_type in self.magics:
345 for m_type in self.magics:
346 m_docs = {}
346 m_docs = {}
347 for m_name, m_func in iteritems(self.magics[m_type]):
347 for m_name, m_func in self.magics[m_type].items():
348 if m_func.__doc__:
348 if m_func.__doc__:
349 if brief:
349 if brief:
350 m_docs[m_name] = m_func.__doc__.split('\n', 1)[0]
350 m_docs[m_name] = m_func.__doc__.split('\n', 1)[0]
@@ -510,7 +510,7 b' class Magics(Configurable):'
510 for mtype in magic_kinds:
510 for mtype in magic_kinds:
511 tab = self.magics[mtype] = {}
511 tab = self.magics[mtype] = {}
512 cls_tab = class_magics[mtype]
512 cls_tab = class_magics[mtype]
513 for magic_name, meth_name in iteritems(cls_tab):
513 for magic_name, meth_name in cls_tab.items():
514 if isinstance(meth_name, string_types):
514 if isinstance(meth_name, string_types):
515 # it's a method name, grab it
515 # it's a method name, grab it
516 tab[magic_name] = getattr(self, meth_name)
516 tab[magic_name] = getattr(self, meth_name)
@@ -36,7 +36,7 b' from IPython.core.magic import (Magics, magics_class, line_magic, cell_magic,'
36 line_cell_magic, on_off, needs_local_scope)
36 line_cell_magic, on_off, needs_local_scope)
37 from IPython.testing.skipdoctest import skip_doctest
37 from IPython.testing.skipdoctest import skip_doctest
38 from IPython.utils import py3compat
38 from IPython.utils import py3compat
39 from IPython.utils.py3compat import builtin_mod, iteritems, PY3
39 from IPython.utils.py3compat import builtin_mod, PY3
40 from IPython.utils.contexts import preserve_keys
40 from IPython.utils.contexts import preserve_keys
41 from IPython.utils.capture import capture_output
41 from IPython.utils.capture import capture_output
42 from IPython.utils.ipstruct import Struct
42 from IPython.utils.ipstruct import Struct
@@ -1271,8 +1271,7 b' python-profiler package from non-free.""")'
1271 """
1271 """
1272 opts,args = self.parse_options(parameter_s,'rq',mode='list')
1272 opts,args = self.parse_options(parameter_s,'rq',mode='list')
1273 if not args: # List existing macros
1273 if not args: # List existing macros
1274 return sorted(k for k,v in iteritems(self.shell.user_ns) if\
1274 return sorted(k for k,v in self.shell.user_ns.items() if isinstance(v, Macro))
1275 isinstance(v, Macro))
1276 if len(args) == 1:
1275 if len(args) == 1:
1277 raise UsageError(
1276 raise UsageError(
1278 "%macro insufficient args; usage '%macro name n1-n2 n3-4...")
1277 "%macro insufficient args; usage '%macro name n1-n2 n3-4...")
@@ -771,7 +771,6 b' except AttributeError: # Python 3'
771 _type_pprinters[slice] = _repr_pprint
771 _type_pprinters[slice] = _repr_pprint
772
772
773 try:
773 try:
774 _type_pprinters[xrange] = _repr_pprint
775 _type_pprinters[long] = _repr_pprint
774 _type_pprinters[long] = _repr_pprint
776 _type_pprinters[unicode] = _repr_pprint
775 _type_pprinters[unicode] = _repr_pprint
777 except NameError:
776 except NameError:
@@ -9,7 +9,6 b''
9 # the file COPYING, distributed as part of this software.
9 # the file COPYING, distributed as part of this software.
10 #-----------------------------------------------------------------------------
10 #-----------------------------------------------------------------------------
11
11
12 from .py3compat import xrange
13
12
14 def uniq_stable(elems):
13 def uniq_stable(elems):
15 """uniq_stable(elems) -> list
14 """uniq_stable(elems) -> list
@@ -32,6 +31,6 b' def flatten(seq):'
32
31
33 def chop(seq, size):
32 def chop(seq, size):
34 """Chop a sequence into chunks of the given size."""
33 """Chop a sequence into chunks of the given size."""
35 return [seq[i:i+size] for i in xrange(0,len(seq),size)]
34 return [seq[i:i+size] for i in range(0,len(seq),size)]
36
35
37
36
@@ -619,10 +619,10 b' def _col_chunks(l, max_rows, row_first=False):'
619 """Yield successive max_rows-sized column chunks from l."""
619 """Yield successive max_rows-sized column chunks from l."""
620 if row_first:
620 if row_first:
621 ncols = (len(l) // max_rows) + (len(l) % max_rows > 0)
621 ncols = (len(l) // max_rows) + (len(l) % max_rows > 0)
622 for i in py3compat.xrange(ncols):
622 for i in range(ncols):
623 yield [l[j] for j in py3compat.xrange(i, len(l), ncols)]
623 yield [l[j] for j in range(i, len(l), ncols)]
624 else:
624 else:
625 for i in py3compat.xrange(0, len(l), max_rows):
625 for i in range(0, len(l), max_rows):
626 yield l[i:(i + max_rows)]
626 yield l[i:(i + max_rows)]
627
627
628
628
@@ -16,8 +16,6 b' Utilities for timing code execution.'
16
16
17 import time
17 import time
18
18
19 from .py3compat import xrange
20
21 #-----------------------------------------------------------------------------
19 #-----------------------------------------------------------------------------
22 # Code
20 # Code
23 #-----------------------------------------------------------------------------
21 #-----------------------------------------------------------------------------
@@ -89,7 +87,7 b' def timings_out(reps,func,*args,**kw):'
89 out = func(*args,**kw)
87 out = func(*args,**kw)
90 tot_time = clock()-start
88 tot_time = clock()-start
91 else:
89 else:
92 rng = xrange(reps-1) # the last time is executed separately to store output
90 rng = range(reps-1) # the last time is executed separately to store output
93 start = clock()
91 start = clock()
94 for dummy in rng: func(*args,**kw)
92 for dummy in rng: func(*args,**kw)
95 out = func(*args,**kw) # one last time
93 out = func(*args,**kw) # one last time
@@ -18,7 +18,6 b' import re'
18 import types
18 import types
19
19
20 from IPython.utils.dir2 import dir2
20 from IPython.utils.dir2 import dir2
21 from .py3compat import iteritems
22
21
23 def create_typestr2type_dicts(dont_include_in_type2typestr=["lambda"]):
22 def create_typestr2type_dicts(dont_include_in_type2typestr=["lambda"]):
24 """Return dictionaries mapping lower case typename (e.g. 'tuple') to type
23 """Return dictionaries mapping lower case typename (e.g. 'tuple') to type
@@ -83,7 +82,7 b' def filter_ns(ns, name_pattern="*", type_pattern="all", ignore_case=True,'
83 reg = re.compile(pattern+"$")
82 reg = re.compile(pattern+"$")
84
83
85 # Check each one matches regex; shouldn't be hidden; of correct type.
84 # Check each one matches regex; shouldn't be hidden; of correct type.
86 return dict((key,obj) for key, obj in iteritems(ns) if reg.match(key) \
85 return dict((key,obj) for key, obj in ns.items() if reg.match(key) \
87 and show_hidden(key, show_all) \
86 and show_hidden(key, show_all) \
88 and is_type(obj, type_pattern) )
87 and is_type(obj, type_pattern) )
89
88
@@ -103,10 +102,10 b' def list_namespace(namespace, type_pattern, filter, ignore_case=False, show_all='
103 type_pattern="all",
102 type_pattern="all",
104 ignore_case=ignore_case, show_all=show_all)
103 ignore_case=ignore_case, show_all=show_all)
105 results = {}
104 results = {}
106 for name, obj in iteritems(filtered):
105 for name, obj in filtered.items():
107 ns = list_namespace(dict_dir(obj), type_pattern,
106 ns = list_namespace(dict_dir(obj), type_pattern,
108 ".".join(pattern_list[1:]),
107 ".".join(pattern_list[1:]),
109 ignore_case=ignore_case, show_all=show_all)
108 ignore_case=ignore_case, show_all=show_all)
110 for inner_name, inner_obj in iteritems(ns):
109 for inner_name, inner_obj in ns.items():
111 results["%s.%s"%(name,inner_name)] = inner_obj
110 results["%s.%s"%(name,inner_name)] = inner_obj
112 return results
111 return results
General Comments 0
You need to be logged in to leave comments. Login now