Show More
@@ -40,7 +40,7 from IPython.utils.traitlets import ( | |||
|
40 | 40 | from IPython.utils.importstring import import_item |
|
41 | 41 | from IPython.utils.text import indent, wrap_paragraphs, dedent |
|
42 | 42 | from IPython.utils import py3compat |
|
43 | from IPython.utils.py3compat import string_types | |
|
43 | from IPython.utils.py3compat import string_types, iteritems | |
|
44 | 44 | |
|
45 | 45 | #----------------------------------------------------------------------------- |
|
46 | 46 | # function for re-wrapping a helpstring |
@@ -216,7 +216,7 class Application(SingletonConfigurable): | |||
|
216 | 216 | flags = Dict() |
|
217 | 217 | def _flags_changed(self, name, old, new): |
|
218 | 218 | """ensure flags dict is valid""" |
|
219 |
for key,value in |
|
|
219 | for key,value in iteritems(new): | |
|
220 | 220 | assert len(value) == 2, "Bad flag: %r:%s"%(key,value) |
|
221 | 221 | assert isinstance(value[0], (dict, Config)), "Bad flag: %r:%s"%(key,value) |
|
222 | 222 | assert isinstance(value[1], string_types), "Bad flag: %r:%s"%(key,value) |
@@ -276,7 +276,7 class Application(SingletonConfigurable): | |||
|
276 | 276 | for c in cls.mro()[:-3]: |
|
277 | 277 | classdict[c.__name__] = c |
|
278 | 278 | |
|
279 |
for alias, longname in self.aliases |
|
|
279 | for alias, longname in iteritems(self.aliases): | |
|
280 | 280 | classname, traitname = longname.split('.',1) |
|
281 | 281 | cls = classdict[classname] |
|
282 | 282 | |
@@ -296,7 +296,7 class Application(SingletonConfigurable): | |||
|
296 | 296 | return |
|
297 | 297 | |
|
298 | 298 | lines = [] |
|
299 |
for m, (cfg,help) in self.flags |
|
|
299 | for m, (cfg,help) in iteritems(self.flags): | |
|
300 | 300 | prefix = '--' if len(m) > 1 else '-' |
|
301 | 301 | lines.append(prefix+m) |
|
302 | 302 | lines.append(indent(dedent(help.strip()))) |
@@ -328,7 +328,7 class Application(SingletonConfigurable): | |||
|
328 | 328 | for p in wrap_paragraphs(self.subcommand_description): |
|
329 | 329 | lines.append(p) |
|
330 | 330 | lines.append('') |
|
331 |
for subc, (cls, help) in self.subcommands |
|
|
331 | for subc, (cls, help) in iteritems(self.subcommands): | |
|
332 | 332 | lines.append(subc) |
|
333 | 333 | if help: |
|
334 | 334 | lines.append(indent(dedent(help.strip()))) |
@@ -434,7 +434,7 class Application(SingletonConfigurable): | |||
|
434 | 434 | # flatten aliases, which have the form: |
|
435 | 435 | # { 'alias' : 'Class.trait' } |
|
436 | 436 | aliases = {} |
|
437 |
for alias, cls_trait in self.aliases |
|
|
437 | for alias, cls_trait in iteritems(self.aliases): | |
|
438 | 438 | cls,trait = cls_trait.split('.',1) |
|
439 | 439 | children = mro_tree[cls] |
|
440 | 440 | if len(children) == 1: |
@@ -445,9 +445,9 class Application(SingletonConfigurable): | |||
|
445 | 445 | # flatten flags, which are of the form: |
|
446 | 446 | # { 'key' : ({'Cls' : {'trait' : value}}, 'help')} |
|
447 | 447 | flags = {} |
|
448 |
for key, (flagdict, help) in self.flags |
|
|
448 | for key, (flagdict, help) in iteritems(self.flags): | |
|
449 | 449 | newflag = {} |
|
450 |
for cls, subdict in |
|
|
450 | for cls, subdict in iteritems(flagdict): | |
|
451 | 451 | children = mro_tree[cls] |
|
452 | 452 | # exactly one descendent, promote flag section |
|
453 | 453 | if len(children) == 1: |
@@ -32,6 +32,7 from copy import deepcopy | |||
|
32 | 32 | from .loader import Config, LazyConfigValue |
|
33 | 33 | from IPython.utils.traitlets import HasTraits, Instance |
|
34 | 34 | from IPython.utils.text import indent, wrap_paragraphs |
|
35 | from IPython.utils.py3compat import iteritems | |
|
35 | 36 | |
|
36 | 37 | |
|
37 | 38 | #----------------------------------------------------------------------------- |
@@ -148,7 +149,7 class Configurable(HasTraits): | |||
|
148 | 149 | section_names = self.section_names() |
|
149 | 150 | |
|
150 | 151 | my_config = self._find_my_config(cfg) |
|
151 |
for name, config_value in |
|
|
152 | for name, config_value in iteritems(my_config): | |
|
152 | 153 | if name in traits: |
|
153 | 154 | if isinstance(config_value, LazyConfigValue): |
|
154 | 155 | # ConfigValue is a wrapper for using append / update on containers |
@@ -197,7 +198,7 class Configurable(HasTraits): | |||
|
197 | 198 | final_help = [] |
|
198 | 199 | final_help.append(u'%s options' % cls.__name__) |
|
199 | 200 | final_help.append(len(final_help[0])*u'-') |
|
200 |
for k, v in sorted(cls.class_traits(config=True). |
|
|
201 | for k, v in sorted(cls.class_traits(config=True).items()): | |
|
201 | 202 | help = cls.class_get_trait_help(v, inst) |
|
202 | 203 | final_help.append(help) |
|
203 | 204 | return '\n'.join(final_help) |
@@ -277,7 +278,7 class Configurable(HasTraits): | |||
|
277 | 278 | lines.append(c('%s will inherit config from: %s'%(cls.__name__, pstr))) |
|
278 | 279 | lines.append('') |
|
279 | 280 | |
|
280 |
for name, trait in cls.class_traits(config=True) |
|
|
281 | for name, trait in iteritems(cls.class_traits(config=True)): | |
|
281 | 282 | help = trait.get_metadata('help') or '' |
|
282 | 283 | lines.append(c(help)) |
|
283 | 284 | lines.append('# c.%s.%s = %r'%(cls.__name__, name, trait.get_default_value())) |
@@ -32,7 +32,7 import sys | |||
|
32 | 32 | from IPython.utils.path import filefind, get_ipython_dir |
|
33 | 33 | from IPython.utils import py3compat, warn |
|
34 | 34 | from IPython.utils.encoding import DEFAULT_ENCODING |
|
35 | from IPython.utils.py3compat import builtin_mod, unicode_type | |
|
35 | from IPython.utils.py3compat import builtin_mod, unicode_type, iteritems | |
|
36 | 36 | from IPython.utils.traitlets import HasTraits, List, Any, TraitError |
|
37 | 37 | |
|
38 | 38 | #----------------------------------------------------------------------------- |
@@ -193,7 +193,7 class Config(dict): | |||
|
193 | 193 | def merge(self, other): |
|
194 | 194 | """merge another config object into this one""" |
|
195 | 195 | to_update = {} |
|
196 |
for k, v in |
|
|
196 | for k, v in iteritems(other): | |
|
197 | 197 | if k not in self: |
|
198 | 198 | to_update[k] = v |
|
199 | 199 | else: # I have this key |
@@ -485,7 +485,7 class CommandLineConfigLoader(ConfigLoader): | |||
|
485 | 485 | if isinstance(cfg, (dict, Config)): |
|
486 | 486 | # don't clobber whole config sections, update |
|
487 | 487 | # each section from config: |
|
488 |
for sec,c in |
|
|
488 | for sec,c in iteritems(cfg): | |
|
489 | 489 | self.config[sec].update(c) |
|
490 | 490 | else: |
|
491 | 491 | raise TypeError("Invalid flag: %r" % cfg) |
@@ -733,7 +733,7 class ArgParseConfigLoader(CommandLineConfigLoader): | |||
|
733 | 733 | |
|
734 | 734 | def _convert_to_config(self): |
|
735 | 735 | """self.parsed_data->self.config""" |
|
736 |
for k, v in vars(self.parsed_data) |
|
|
736 | for k, v in iteritems(vars(self.parsed_data)): | |
|
737 | 737 | exec("self.config.%s = v"%k, locals(), globals()) |
|
738 | 738 | |
|
739 | 739 | class KVArgParseConfigLoader(ArgParseConfigLoader): |
@@ -750,7 +750,7 class KVArgParseConfigLoader(ArgParseConfigLoader): | |||
|
750 | 750 | if flags is None: |
|
751 | 751 | flags = self.flags |
|
752 | 752 | paa = self.parser.add_argument |
|
753 |
for key,value in |
|
|
753 | for key,value in iteritems(aliases): | |
|
754 | 754 | if key in flags: |
|
755 | 755 | # flags |
|
756 | 756 | nargs = '?' |
@@ -760,7 +760,7 class KVArgParseConfigLoader(ArgParseConfigLoader): | |||
|
760 | 760 | paa('-'+key, '--'+key, type=unicode_type, dest=value, nargs=nargs) |
|
761 | 761 | else: |
|
762 | 762 | paa('--'+key, type=unicode_type, dest=value, nargs=nargs) |
|
763 |
for key, (value, help) in |
|
|
763 | for key, (value, help) in iteritems(flags): | |
|
764 | 764 | if key in self.aliases: |
|
765 | 765 | # |
|
766 | 766 | self.alias_flags[self.aliases[key]] = value |
@@ -779,7 +779,7 class KVArgParseConfigLoader(ArgParseConfigLoader): | |||
|
779 | 779 | else: |
|
780 | 780 | subcs = [] |
|
781 | 781 | |
|
782 |
for k, v in vars(self.parsed_data) |
|
|
782 | for k, v in iteritems(vars(self.parsed_data)): | |
|
783 | 783 | if v is None: |
|
784 | 784 | # it was a flag that shares the name of an alias |
|
785 | 785 | subcs.append(self.alias_flags[k]) |
@@ -20,7 +20,7 Authors: | |||
|
20 | 20 | |
|
21 | 21 | from IPython.config.configurable import Configurable |
|
22 | 22 | |
|
23 | from IPython.utils.py3compat import builtin_mod | |
|
23 | from IPython.utils.py3compat import builtin_mod, iteritems | |
|
24 | 24 | from IPython.utils.traitlets import Instance |
|
25 | 25 | |
|
26 | 26 | #----------------------------------------------------------------------------- |
@@ -98,14 +98,14 class BuiltinTrap(Configurable): | |||
|
98 | 98 | """Store ipython references in the __builtin__ namespace.""" |
|
99 | 99 | |
|
100 | 100 | add_builtin = self.add_builtin |
|
101 |
for name, func in self.auto_builtins |
|
|
101 | for name, func in iteritems(self.auto_builtins): | |
|
102 | 102 | add_builtin(name, func) |
|
103 | 103 | |
|
104 | 104 | def deactivate(self): |
|
105 | 105 | """Remove any builtins which might have been added by add_builtins, or |
|
106 | 106 | restore overwritten ones to their previous values.""" |
|
107 | 107 | remove_builtin = self.remove_builtin |
|
108 |
for key, val in self._orig_builtins |
|
|
108 | for key, val in iteritems(self._orig_builtins): | |
|
109 | 109 | remove_builtin(key, val) |
|
110 | 110 | self._orig_builtins.clear() |
|
111 | 111 | self._builtins_added = False |
@@ -69,7 +69,7 from IPython.utils.path import get_home_dir, get_ipython_dir, get_py_filename, u | |||
|
69 | 69 | from IPython.utils.pickleshare import PickleShareDB |
|
70 | 70 | from IPython.utils.process import system, getoutput |
|
71 | 71 | from IPython.utils.py3compat import (builtin_mod, unicode_type, string_types, |
|
72 | with_metaclass) | |
|
72 | with_metaclass, iteritems) | |
|
73 | 73 | from IPython.utils.strdispatch import StrDispatch |
|
74 | 74 | from IPython.utils.syspathcontext import prepended_to_syspath |
|
75 | 75 | from IPython.utils.text import (format_screen, LSString, SList, |
@@ -752,7 +752,7 class InteractiveShell(SingletonConfigurable): | |||
|
752 | 752 | def restore_sys_module_state(self): |
|
753 | 753 | """Restore the state of the sys module.""" |
|
754 | 754 | try: |
|
755 |
for k, v in self._orig_sys_module_state |
|
|
755 | for k, v in iteritems(self._orig_sys_module_state): | |
|
756 | 756 | setattr(sys, k, v) |
|
757 | 757 | except AttributeError: |
|
758 | 758 | pass |
@@ -1243,7 +1243,7 class InteractiveShell(SingletonConfigurable): | |||
|
1243 | 1243 | # Also check in output history |
|
1244 | 1244 | ns_refs.append(self.history_manager.output_hist) |
|
1245 | 1245 | for ns in ns_refs: |
|
1246 |
to_delete = [n for n, o in |
|
|
1246 | to_delete = [n for n, o in iteritems(ns) if o is obj] | |
|
1247 | 1247 | for name in to_delete: |
|
1248 | 1248 | del ns[name] |
|
1249 | 1249 | |
@@ -1335,7 +1335,7 class InteractiveShell(SingletonConfigurable): | |||
|
1335 | 1335 | variables : dict |
|
1336 | 1336 | A dictionary mapping object names (as strings) to the objects. |
|
1337 | 1337 | """ |
|
1338 |
for name, obj in |
|
|
1338 | for name, obj in iteritems(variables): | |
|
1339 | 1339 | if name in self.user_ns and self.user_ns[name] is obj: |
|
1340 | 1340 | del self.user_ns[name] |
|
1341 | 1341 | self.user_ns_hidden.pop(name, None) |
@@ -2447,7 +2447,7 class InteractiveShell(SingletonConfigurable): | |||
|
2447 | 2447 | user_ns = self.user_ns |
|
2448 | 2448 | global_ns = self.user_global_ns |
|
2449 | 2449 | |
|
2450 |
for key, expr in |
|
|
2450 | for key, expr in iteritems(expressions): | |
|
2451 | 2451 | try: |
|
2452 | 2452 | value = self._format_user_obj(eval(expr, global_ns, user_ns)) |
|
2453 | 2453 | except: |
@@ -2687,7 +2687,7 class InteractiveShell(SingletonConfigurable): | |||
|
2687 | 2687 | |
|
2688 | 2688 | # Execute any registered post-execution functions. |
|
2689 | 2689 | # unless we are silent |
|
2690 |
post_exec = [] if silent else self._post_execute |
|
|
2690 | post_exec = [] if silent else iteritems(self._post_execute) | |
|
2691 | 2691 | |
|
2692 | 2692 | for func, status in post_exec: |
|
2693 | 2693 | if self.disable_failing_post_execute and not status: |
@@ -30,7 +30,7 from IPython.core.inputsplitter import ESC_MAGIC, ESC_MAGIC2 | |||
|
30 | 30 | from IPython.external.decorator import decorator |
|
31 | 31 | from IPython.utils.ipstruct import Struct |
|
32 | 32 | from IPython.utils.process import arg_split |
|
33 | from IPython.utils.py3compat import string_types | |
|
33 | from IPython.utils.py3compat import string_types, iteritems | |
|
34 | 34 | from IPython.utils.text import dedent |
|
35 | 35 | from IPython.utils.traitlets import Bool, Dict, Instance, MetaHasTraits |
|
36 | 36 | from IPython.utils.warn import error |
@@ -349,7 +349,7 class MagicsManager(Configurable): | |||
|
349 | 349 | docs = {} |
|
350 | 350 | for m_type in self.magics: |
|
351 | 351 | m_docs = {} |
|
352 |
for m_name, m_func in self.magics[m_type] |
|
|
352 | for m_name, m_func in iteritems(self.magics[m_type]): | |
|
353 | 353 | if m_func.__doc__: |
|
354 | 354 | if brief: |
|
355 | 355 | m_docs[m_name] = m_func.__doc__.split('\n', 1)[0] |
@@ -533,7 +533,7 class Magics(Configurable): | |||
|
533 | 533 | for mtype in magic_kinds: |
|
534 | 534 | tab = self.magics[mtype] = {} |
|
535 | 535 | cls_tab = class_magics[mtype] |
|
536 |
for magic_name, meth_name in |
|
|
536 | for magic_name, meth_name in iteritems(cls_tab): | |
|
537 | 537 | if isinstance(meth_name, string_types): |
|
538 | 538 | # it's a method name, grab it |
|
539 | 539 | tab[magic_name] = getattr(self, meth_name) |
@@ -43,7 +43,7 from IPython.core.magic import (Magics, magics_class, line_magic, cell_magic, | |||
|
43 | 43 | line_cell_magic, on_off, needs_local_scope) |
|
44 | 44 | from IPython.testing.skipdoctest import skip_doctest |
|
45 | 45 | from IPython.utils import py3compat |
|
46 | from IPython.utils.py3compat import builtin_mod | |
|
46 | from IPython.utils.py3compat import builtin_mod, iteritems | |
|
47 | 47 | from IPython.utils.contexts import preserve_keys |
|
48 | 48 | from IPython.utils.io import capture_output |
|
49 | 49 | from IPython.utils.ipstruct import Struct |
@@ -1185,7 +1185,7 python-profiler package from non-free.""") | |||
|
1185 | 1185 | """ |
|
1186 | 1186 | opts,args = self.parse_options(parameter_s,'rq',mode='list') |
|
1187 | 1187 | if not args: # List existing macros |
|
1188 |
return sorted(k for k,v in self.shell.user_ns |
|
|
1188 | return sorted(k for k,v in iteritems(self.shell.user_ns) if\ | |
|
1189 | 1189 | isinstance(v, Macro)) |
|
1190 | 1190 | if len(args) == 1: |
|
1191 | 1191 | raise UsageError( |
@@ -371,7 +371,7 class InteractiveLoopTestCase(unittest.TestCase): | |||
|
371 | 371 | # We can't check that the provided ns is identical to the test_ns, |
|
372 | 372 | # because Python fills test_ns with extra keys (copyright, etc). But |
|
373 | 373 | # we can check that the given dict is *contained* in test_ns |
|
374 |
for k,v in ns. |
|
|
374 | for k,v in ns.items(): | |
|
375 | 375 | self.assertEqual(test_ns[k], v) |
|
376 | 376 | |
|
377 | 377 | def test_simple(self): |
@@ -406,7 +406,7 class IPythonInputTestCase(InputSplitterTestCase): | |||
|
406 | 406 | def test_syntax(self): |
|
407 | 407 | """Call all single-line syntax tests from the main object""" |
|
408 | 408 | isp = self.isp |
|
409 |
for example in syntax. |
|
|
409 | for example in syntax.values(): | |
|
410 | 410 | for raw, out_t in example: |
|
411 | 411 | if raw.startswith(' '): |
|
412 | 412 | continue |
@@ -419,7 +419,7 class IPythonInputTestCase(InputSplitterTestCase): | |||
|
419 | 419 | |
|
420 | 420 | def test_syntax_multiline(self): |
|
421 | 421 | isp = self.isp |
|
422 |
for example in syntax_ml. |
|
|
422 | for example in syntax_ml.values(): | |
|
423 | 423 | for line_pairs in example: |
|
424 | 424 | out_t_parts = [] |
|
425 | 425 | raw_parts = [] |
@@ -439,7 +439,7 class IPythonInputTestCase(InputSplitterTestCase): | |||
|
439 | 439 | |
|
440 | 440 | def test_syntax_multiline_cell(self): |
|
441 | 441 | isp = self.isp |
|
442 |
for example in syntax_ml. |
|
|
442 | for example in syntax_ml.values(): | |
|
443 | 443 | |
|
444 | 444 | out_t_parts = [] |
|
445 | 445 | for line_pairs in example: |
@@ -31,7 +31,7 from .channelsabc import ( | |||
|
31 | 31 | ShellChannelABC, IOPubChannelABC, |
|
32 | 32 | HBChannelABC, StdInChannelABC, |
|
33 | 33 | ) |
|
34 | from IPython.utils.py3compat import string_types | |
|
34 | from IPython.utils.py3compat import string_types, iteritems | |
|
35 | 35 | |
|
36 | 36 | #----------------------------------------------------------------------------- |
|
37 | 37 | # Constants and exceptions |
@@ -62,7 +62,7 def validate_string_dict(dct): | |||
|
62 | 62 | """Validate that the input is a dict with string keys and values. |
|
63 | 63 | |
|
64 | 64 | Raises ValueError if not.""" |
|
65 |
for k,v in |
|
|
65 | for k,v in iteritems(dct): | |
|
66 | 66 | if not isinstance(k, string_types): |
|
67 | 67 | raise ValueError('key %r in dict must be a string' % k) |
|
68 | 68 | if not isinstance(v, string_types): |
@@ -21,7 +21,7 from IPython.kernel import KernelManager | |||
|
21 | 21 | from IPython.utils.traitlets import ( |
|
22 | 22 | HasTraits, TraitError, Bool, Unicode, Dict, Integer, List, Enum, Any, |
|
23 | 23 | ) |
|
24 | from IPython.utils.py3compat import string_types | |
|
24 | from IPython.utils.py3compat import string_types, iteritems | |
|
25 | 25 | |
|
26 | 26 | from .utils import TIMEOUT, start_global_kernel, flush_channels, execute |
|
27 | 27 | |
@@ -185,7 +185,7 class DisplayData(Reference): | |||
|
185 | 185 | metadata = Dict() |
|
186 | 186 | data = Dict() |
|
187 | 187 | def _data_changed(self, name, old, new): |
|
188 |
for k,v in |
|
|
188 | for k,v in iteritems(new): | |
|
189 | 189 | assert mime_pat.match(k) |
|
190 | 190 | nt.assert_is_instance(v, string_types) |
|
191 | 191 | |
@@ -194,7 +194,7 class PyOut(Reference): | |||
|
194 | 194 | execution_count = Integer() |
|
195 | 195 | data = Dict() |
|
196 | 196 | def _data_changed(self, name, old, new): |
|
197 |
for k,v in |
|
|
197 | for k,v in iteritems(new): | |
|
198 | 198 | assert mime_pat.match(k) |
|
199 | 199 | nt.assert_is_instance(v, string_types) |
|
200 | 200 |
@@ -49,7 +49,8 from IPython.config.configurable import Configurable, LoggingConfigurable | |||
|
49 | 49 | from IPython.utils import io |
|
50 | 50 | from IPython.utils.importstring import import_item |
|
51 | 51 | from IPython.utils.jsonutil import extract_dates, squash_dates, date_default |
|
52 | from IPython.utils.py3compat import str_to_bytes, str_to_unicode, unicode_type | |
|
52 | from IPython.utils.py3compat import (str_to_bytes, str_to_unicode, unicode_type, | |
|
53 | iteritems) | |
|
53 | 54 | from IPython.utils.traitlets import (CBytes, Unicode, Bool, Any, Instance, Set, |
|
54 | 55 | DottedObjectName, CUnicode, Dict, Integer, |
|
55 | 56 | TraitError, |
@@ -166,14 +167,14 class Message(object): | |||
|
166 | 167 | |
|
167 | 168 | def __init__(self, msg_dict): |
|
168 | 169 | dct = self.__dict__ |
|
169 |
for k, v in dict(msg_dict) |
|
|
170 | for k, v in iteritems(dict(msg_dict)): | |
|
170 | 171 | if isinstance(v, dict): |
|
171 | 172 | v = Message(v) |
|
172 | 173 | dct[k] = v |
|
173 | 174 | |
|
174 | 175 | # Having this iterator lets dict(msg_obj) work out of the box. |
|
175 | 176 | def __iter__(self): |
|
176 |
return iter(self.__dict__ |
|
|
177 | return iter(iteritems(self.__dict__)) | |
|
177 | 178 | |
|
178 | 179 | def __repr__(self): |
|
179 | 180 | return repr(self.__dict__) |
@@ -20,6 +20,7 import nose.tools as nt | |||
|
20 | 20 | from IPython.kernel.zmq.serialize import serialize_object, unserialize_object |
|
21 | 21 | from IPython.testing import decorators as dec |
|
22 | 22 | from IPython.utils.pickleutil import CannedArray, CannedClass |
|
23 | from IPython.utils.py3compat import iteritems | |
|
23 | 24 | from IPython.parallel import interactive |
|
24 | 25 | |
|
25 | 26 | #------------------------------------------------------------------------------- |
@@ -37,7 +38,7 class C(object): | |||
|
37 | 38 | """dummy class for """ |
|
38 | 39 | |
|
39 | 40 | def __init__(self, **kwargs): |
|
40 |
for key,value in |
|
|
41 | for key,value in iteritems(kwargs): | |
|
41 | 42 | setattr(self, key, value) |
|
42 | 43 | |
|
43 | 44 | SHAPES = ((100,), (1024,10), (10,8,6,5), (), (0,)) |
@@ -71,7 +71,7 def ansi2html(text): | |||
|
71 | 71 | '`': '`', |
|
72 | 72 | } |
|
73 | 73 | |
|
74 |
for c, escape in html_escapes. |
|
|
74 | for c, escape in html_escapes.items(): | |
|
75 | 75 | text = text.replace(c, escape) |
|
76 | 76 | |
|
77 | 77 | ansi_re = re.compile('\x1b' + r'\[([\dA-Fa-f;]*?)m') |
@@ -97,7 +97,7 def prompt_dictionary(choices, default_style=1, menu_comments={}): | |||
|
97 | 97 | # Build the menu that will be displayed to the user with |
|
98 | 98 | # all of the options available. |
|
99 | 99 | prompt = "" |
|
100 |
for key, value in choices. |
|
|
100 | for key, value in choices.items(): | |
|
101 | 101 | prompt += "%d %s " % (key, value) |
|
102 | 102 | if key in menu_comments: |
|
103 | 103 | prompt += menu_comments[key] |
@@ -2,7 +2,7 | |||
|
2 | 2 | |
|
3 | 3 | from unittest import TestCase |
|
4 | 4 | |
|
5 | from IPython.utils.py3compat import string_types | |
|
5 | from IPython.utils.py3compat import string_types, iteritems | |
|
6 | 6 | |
|
7 | 7 | from . import formattest |
|
8 | 8 | |
@@ -24,7 +24,7 class TestPy(formattest.NBFormatTest, TestCase): | |||
|
24 | 24 | elements. |
|
25 | 25 | """ |
|
26 | 26 | if isinstance(da, dict): |
|
27 |
for k,v in |
|
|
27 | for k,v in iteritems(da): | |
|
28 | 28 | if k in self.ignored_keys: |
|
29 | 29 | continue |
|
30 | 30 | self.assertTrue(k in db) |
@@ -7,6 +7,7 import json | |||
|
7 | 7 | |
|
8 | 8 | from IPython.external.jsonschema import Draft3Validator, validate, ValidationError |
|
9 | 9 | import IPython.external.jsonpointer as jsonpointer |
|
10 | from IPython.utils.py3compat import iteritems | |
|
10 | 11 | |
|
11 | 12 | def nbvalidate(nbjson, schema='v3.withref.json', key=None,verbose=True): |
|
12 | 13 | v3schema = resolve_ref(json.load(open(schema,'r'))) |
@@ -35,7 +36,7 def resolve_ref(json, base=None): | |||
|
35 | 36 | temp.append(resolve_ref(item, base=base)) |
|
36 | 37 | elif type(json) is dict: |
|
37 | 38 | temp = {}; |
|
38 |
for key,value in |
|
|
39 | for key,value in iteritems(json): | |
|
39 | 40 | if key == '$ref': |
|
40 | 41 | return resolve_ref(jsonpointer.resolve_pointer(base,value), base=base) |
|
41 | 42 | else : |
@@ -64,6 +64,7 from IPython.utils.traitlets import ( | |||
|
64 | 64 | from IPython.utils.encoding import DEFAULT_ENCODING |
|
65 | 65 | from IPython.utils.path import get_home_dir |
|
66 | 66 | from IPython.utils.process import find_cmd, FindCmdError |
|
67 | from IPython.utils.py3compat import iteritems, itervalues | |
|
67 | 68 | |
|
68 | 69 | from .win32support import forward_read_events |
|
69 | 70 | |
@@ -404,14 +405,14 class LocalEngineSetLauncher(LocalEngineLauncher): | |||
|
404 | 405 | |
|
405 | 406 | def signal(self, sig): |
|
406 | 407 | dlist = [] |
|
407 |
for el in self.launchers |
|
|
408 | for el in itervalues(self.launchers): | |
|
408 | 409 | d = el.signal(sig) |
|
409 | 410 | dlist.append(d) |
|
410 | 411 | return dlist |
|
411 | 412 | |
|
412 | 413 | def interrupt_then_kill(self, delay=1.0): |
|
413 | 414 | dlist = [] |
|
414 |
for el in self.launchers |
|
|
415 | for el in itervalues(self.launchers): | |
|
415 | 416 | d = el.interrupt_then_kill(delay) |
|
416 | 417 | dlist.append(d) |
|
417 | 418 | return dlist |
@@ -421,7 +422,7 class LocalEngineSetLauncher(LocalEngineLauncher): | |||
|
421 | 422 | |
|
422 | 423 | def _notice_engine_stopped(self, data): |
|
423 | 424 | pid = data['pid'] |
|
424 |
for idx,el in self.launchers |
|
|
425 | for idx,el in iteritems(self.launchers): | |
|
425 | 426 | if el.process.pid == pid: |
|
426 | 427 | break |
|
427 | 428 | self.launchers.pop(idx) |
@@ -742,7 +743,7 class SSHEngineSetLauncher(LocalEngineSetLauncher): | |||
|
742 | 743 | def engine_count(self): |
|
743 | 744 | """determine engine count from `engines` dict""" |
|
744 | 745 | count = 0 |
|
745 |
for n in self.engines |
|
|
746 | for n in itervalues(self.engines): | |
|
746 | 747 | if isinstance(n, (tuple,list)): |
|
747 | 748 | n,args = n |
|
748 | 749 | count += n |
@@ -754,7 +755,7 class SSHEngineSetLauncher(LocalEngineSetLauncher): | |||
|
754 | 755 | """ |
|
755 | 756 | |
|
756 | 757 | dlist = [] |
|
757 |
for host, n in self.engines |
|
|
758 | for host, n in iteritems(self.engines): | |
|
758 | 759 | if isinstance(n, (tuple, list)): |
|
759 | 760 | n, args = n |
|
760 | 761 | else: |
@@ -28,6 +28,7 import uuid | |||
|
28 | 28 | from xml.etree import ElementTree as ET |
|
29 | 29 | |
|
30 | 30 | from IPython.config.configurable import Configurable |
|
31 | from IPython.utils.py3compat import iteritems | |
|
31 | 32 | from IPython.utils.traitlets import ( |
|
32 | 33 | Unicode, Integer, List, Instance, |
|
33 | 34 | Enum, Bool |
@@ -215,7 +216,7 class WinHPCTask(Configurable): | |||
|
215 | 216 | |
|
216 | 217 | def get_env_vars(self): |
|
217 | 218 | env_vars = ET.Element('EnvironmentVariables') |
|
218 |
for k, v in self.environment_variables |
|
|
219 | for k, v in iteritems(self.environment_variables): | |
|
219 | 220 | variable = ET.SubElement(env_vars, "Variable") |
|
220 | 221 | name = ET.SubElement(variable, "Name") |
|
221 | 222 | name.text = k |
@@ -40,7 +40,7 from IPython.utils.coloransi import TermColors | |||
|
40 | 40 | from IPython.utils.jsonutil import rekey |
|
41 | 41 | from IPython.utils.localinterfaces import localhost, is_local_ip |
|
42 | 42 | from IPython.utils.path import get_ipython_dir |
|
43 | from IPython.utils.py3compat import cast_bytes, string_types, xrange | |
|
43 | from IPython.utils.py3compat import cast_bytes, string_types, xrange, iteritems | |
|
44 | 44 | from IPython.utils.traitlets import (HasTraits, Integer, Instance, Unicode, |
|
45 | 45 | Dict, List, Bool, Set, Any) |
|
46 | 46 | from IPython.external.decorator import decorator |
@@ -534,7 +534,7 class Client(HasTraits): | |||
|
534 | 534 | |
|
535 | 535 | def _update_engines(self, engines): |
|
536 | 536 | """Update our engines dict and _ids from a dict of the form: {id:uuid}.""" |
|
537 |
for k,v in |
|
|
537 | for k,v in iteritems(engines): | |
|
538 | 538 | eid = int(k) |
|
539 | 539 | if eid not in self._engines: |
|
540 | 540 | self._ids.append(eid) |
@@ -32,7 +32,7 from IPython.external.decorator import decorator | |||
|
32 | 32 | |
|
33 | 33 | from IPython.parallel import util |
|
34 | 34 | from IPython.parallel.controller.dependency import Dependency, dependent |
|
35 | from IPython.utils.py3compat import string_types | |
|
35 | from IPython.utils.py3compat import string_types, iteritems | |
|
36 | 36 | |
|
37 | 37 | from . import map as Map |
|
38 | 38 | from .asyncresult import AsyncResult, AsyncMapResult |
@@ -164,7 +164,7 class View(HasTraits): | |||
|
164 | 164 | safely edit after arrays and buffers during non-copying |
|
165 | 165 | sends. |
|
166 | 166 | """ |
|
167 |
for name, value in |
|
|
167 | for name, value in iteritems(kwargs): | |
|
168 | 168 | if name not in self._flag_names: |
|
169 | 169 | raise KeyError("Invalid name: %r"%name) |
|
170 | 170 | else: |
@@ -51,6 +51,7 from datetime import datetime | |||
|
51 | 51 | |
|
52 | 52 | from IPython.config.configurable import LoggingConfigurable |
|
53 | 53 | |
|
54 | from IPython.utils.py3compat import iteritems, itervalues | |
|
54 | 55 | from IPython.utils.traitlets import Dict, Unicode, Integer, Float |
|
55 | 56 | |
|
56 | 57 | filters = { |
@@ -74,7 +75,7 class CompositeFilter(object): | |||
|
74 | 75 | def __init__(self, dikt): |
|
75 | 76 | self.tests = [] |
|
76 | 77 | self.values = [] |
|
77 |
for key, value in |
|
|
78 | for key, value in iteritems(dikt): | |
|
78 | 79 | self.tests.append(filters[key]) |
|
79 | 80 | self.values.append(value) |
|
80 | 81 | |
@@ -131,7 +132,7 class DictDB(BaseDB): | |||
|
131 | 132 | |
|
132 | 133 | def _match_one(self, rec, tests): |
|
133 | 134 | """Check if a specific record matches tests.""" |
|
134 |
for key,test in |
|
|
135 | for key,test in iteritems(tests): | |
|
135 | 136 | if not test(rec.get(key, None)): |
|
136 | 137 | return False |
|
137 | 138 | return True |
@@ -140,13 +141,13 class DictDB(BaseDB): | |||
|
140 | 141 | """Find all the matches for a check dict.""" |
|
141 | 142 | matches = [] |
|
142 | 143 | tests = {} |
|
143 |
for k,v in |
|
|
144 | for k,v in iteritems(check): | |
|
144 | 145 | if isinstance(v, dict): |
|
145 | 146 | tests[k] = CompositeFilter(v) |
|
146 | 147 | else: |
|
147 | 148 | tests[k] = lambda o: o==v |
|
148 | 149 | |
|
149 |
for rec in self._records |
|
|
150 | for rec in itervalues(self._records): | |
|
150 | 151 | if self._match_one(rec, tests): |
|
151 | 152 | matches.append(copy(rec)) |
|
152 | 153 | return matches |
@@ -31,7 +31,7 from zmq.eventloop.zmqstream import ZMQStream | |||
|
31 | 31 | # internal: |
|
32 | 32 | from IPython.utils.importstring import import_item |
|
33 | 33 | from IPython.utils.localinterfaces import localhost |
|
34 | from IPython.utils.py3compat import cast_bytes, unicode_type | |
|
34 | from IPython.utils.py3compat import cast_bytes, unicode_type, iteritems | |
|
35 | 35 | from IPython.utils.traitlets import ( |
|
36 | 36 | HasTraits, Instance, Integer, Unicode, Dict, Set, Tuple, CBytes, DottedObjectName |
|
37 | 37 | ) |
@@ -455,7 +455,7 class Hub(SessionFactory): | |||
|
455 | 455 | self._idcounter += 1 |
|
456 | 456 | return newid |
|
457 | 457 | # newid = 0 |
|
458 |
# incoming = [id[0] for id in self.incoming_registrations |
|
|
458 | # incoming = [id[0] for id in itervalues(self.incoming_registrations)] | |
|
459 | 459 | # # print newid, self.ids, self.incoming_registrations |
|
460 | 460 | # while newid in self.ids or newid in incoming: |
|
461 | 461 | # newid += 1 |
@@ -611,7 +611,7 class Hub(SessionFactory): | |||
|
611 | 611 | try: |
|
612 | 612 | # it's posible iopub arrived first: |
|
613 | 613 | existing = self.db.get_record(msg_id) |
|
614 |
for key,evalue in |
|
|
614 | for key,evalue in iteritems(existing): | |
|
615 | 615 | rvalue = record.get(key, None) |
|
616 | 616 | if evalue and rvalue and evalue != rvalue: |
|
617 | 617 | self.log.warn("conflicting initial state for record: %r:%r <%r> %r", msg_id, rvalue, key, evalue) |
@@ -717,7 +717,7 class Hub(SessionFactory): | |||
|
717 | 717 | # still check content,header which should not change |
|
718 | 718 | # but are not expensive to compare as buffers |
|
719 | 719 | |
|
720 |
for key,evalue in |
|
|
720 | for key,evalue in iteritems(existing): | |
|
721 | 721 | if key.endswith('buffers'): |
|
722 | 722 | # don't compare buffers |
|
723 | 723 | continue |
@@ -892,7 +892,7 class Hub(SessionFactory): | |||
|
892 | 892 | self.log.info("client::client %r connected", client_id) |
|
893 | 893 | content = dict(status='ok') |
|
894 | 894 | jsonable = {} |
|
895 |
for k,v in self.keytable |
|
|
895 | for k,v in iteritems(self.keytable): | |
|
896 | 896 | if v not in self.dead_engines: |
|
897 | 897 | jsonable[str(k)] = v |
|
898 | 898 | content['engines'] = jsonable |
@@ -920,7 +920,7 class Hub(SessionFactory): | |||
|
920 | 920 | content = error.wrap_exception() |
|
921 | 921 | self.log.error("uuid %r in use", uuid, exc_info=True) |
|
922 | 922 | else: |
|
923 |
for h, ec in self.incoming_registrations |
|
|
923 | for h, ec in iteritems(self.incoming_registrations): | |
|
924 | 924 | if uuid == h: |
|
925 | 925 | try: |
|
926 | 926 | raise KeyError("heart_id %r in use" % uuid) |
@@ -1073,7 +1073,7 class Hub(SessionFactory): | |||
|
1073 | 1073 | self.log.debug("save engine state to %s" % self.engine_state_file) |
|
1074 | 1074 | state = {} |
|
1075 | 1075 | engines = {} |
|
1076 |
for eid, ec in self.engines |
|
|
1076 | for eid, ec in iteritems(self.engines): | |
|
1077 | 1077 | if ec.uuid not in self.dead_engines: |
|
1078 | 1078 | engines[eid] = ec.uuid |
|
1079 | 1079 | |
@@ -1097,7 +1097,7 class Hub(SessionFactory): | |||
|
1097 | 1097 | |
|
1098 | 1098 | save_notifier = self.notifier |
|
1099 | 1099 | self.notifier = None |
|
1100 |
for eid, uuid in state['engines'] |
|
|
1100 | for eid, uuid in iteritems(state['engines']): | |
|
1101 | 1101 | heart = uuid.encode('ascii') |
|
1102 | 1102 | # start with this heart as current and beating: |
|
1103 | 1103 | self.heartmonitor.responses.add(heart) |
@@ -1290,7 +1290,7 class Hub(SessionFactory): | |||
|
1290 | 1290 | finish(dict(status='ok', resubmitted=resubmitted)) |
|
1291 | 1291 | |
|
1292 | 1292 | # store the new IDs in the Task DB |
|
1293 |
for msg_id, resubmit_id in |
|
|
1293 | for msg_id, resubmit_id in iteritems(resubmitted): | |
|
1294 | 1294 | try: |
|
1295 | 1295 | self.db.update_record(msg_id, {'resubmitted' : resubmit_id}) |
|
1296 | 1296 | except Exception: |
@@ -29,6 +29,7 from zmq.eventloop import ioloop | |||
|
29 | 29 | from IPython.utils.traitlets import Unicode, Instance, List, Dict |
|
30 | 30 | from .dictdb import BaseDB |
|
31 | 31 | from IPython.utils.jsonutil import date_default, extract_dates, squash_dates |
|
32 | from IPython.utils.py3compat import iteritems | |
|
32 | 33 | |
|
33 | 34 | #----------------------------------------------------------------------------- |
|
34 | 35 | # SQLite operators, adapters, and converters |
@@ -295,9 +296,9 class SQLiteDB(BaseDB): | |||
|
295 | 296 | if skeys: |
|
296 | 297 | raise KeyError("Illegal testing key(s): %s"%skeys) |
|
297 | 298 | |
|
298 |
for name,sub_check in |
|
|
299 | for name,sub_check in iteritems(check): | |
|
299 | 300 | if isinstance(sub_check, dict): |
|
300 |
for test,value in |
|
|
301 | for test,value in iteritems(sub_check): | |
|
301 | 302 | try: |
|
302 | 303 | op = operators[test] |
|
303 | 304 | except KeyError: |
@@ -26,6 +26,7 from IPython.parallel.error import TimeoutError | |||
|
26 | 26 | from IPython.parallel import error, Client |
|
27 | 27 | from IPython.parallel.tests import add_engines |
|
28 | 28 | from .clienttest import ClusterTestCase |
|
29 | from IPython.utils.py3compat import iteritems | |
|
29 | 30 | |
|
30 | 31 | def setup(): |
|
31 | 32 | add_engines(2, total=True) |
@@ -77,7 +78,7 class AsyncResultTest(ClusterTestCase): | |||
|
77 | 78 | self.assertEqual(ar.get(), [5]*n) |
|
78 | 79 | d = ar.get_dict() |
|
79 | 80 | self.assertEqual(sorted(d.keys()), sorted(self.client.ids)) |
|
80 |
for eid,r in |
|
|
81 | for eid,r in iteritems(d): | |
|
81 | 82 | self.assertEqual(r, 5) |
|
82 | 83 | |
|
83 | 84 | def test_get_dict_single(self): |
@@ -44,7 +44,7 from IPython.external.decorator import decorator | |||
|
44 | 44 | # IPython imports |
|
45 | 45 | from IPython.config.application import Application |
|
46 | 46 | from IPython.utils.localinterfaces import localhost, is_public_ip, public_ips |
|
47 | from IPython.utils.py3compat import string_types | |
|
47 | from IPython.utils.py3compat import string_types, iteritems, itervalues | |
|
48 | 48 | from IPython.kernel.zmq.log import EnginePUBHandler |
|
49 | 49 | from IPython.kernel.zmq.serialize import ( |
|
50 | 50 | unserialize_object, serialize_object, pack_apply_message, unpack_apply_message |
@@ -77,7 +77,7 class ReverseDict(dict): | |||
|
77 | 77 | def __init__(self, *args, **kwargs): |
|
78 | 78 | dict.__init__(self, *args, **kwargs) |
|
79 | 79 | self._reverse = dict() |
|
80 |
for key, value in |
|
|
80 | for key, value in iteritems(self): | |
|
81 | 81 | self._reverse[value] = key |
|
82 | 82 | |
|
83 | 83 | def __getitem__(self, key): |
@@ -168,7 +168,7 def validate_url_container(container): | |||
|
168 | 168 | url = container |
|
169 | 169 | return validate_url(url) |
|
170 | 170 | elif isinstance(container, dict): |
|
171 |
container = |
|
|
171 | container = itervalues(container) | |
|
172 | 172 | |
|
173 | 173 | for element in container: |
|
174 | 174 | validate_url_container(element) |
@@ -231,7 +231,7 def _push(**ns): | |||
|
231 | 231 | while tmp in user_ns: |
|
232 | 232 | tmp = tmp + '_' |
|
233 | 233 | try: |
|
234 |
for name, value in |
|
|
234 | for name, value in iteritems(ns): | |
|
235 | 235 | user_ns[tmp] = value |
|
236 | 236 | exec("%s = %s" % (name, tmp), user_ns) |
|
237 | 237 | finally: |
@@ -75,7 +75,7 class PygmentsBlockUserData(QtGui.QTextBlockUserData): | |||
|
75 | 75 | syntax_stack = ('root',) |
|
76 | 76 | |
|
77 | 77 | def __init__(self, **kwds): |
|
78 |
for key, value in kwds. |
|
|
78 | for key, value in kwds.items(): | |
|
79 | 79 | setattr(self, key, value) |
|
80 | 80 | QtGui.QTextBlockUserData.__init__(self) |
|
81 | 81 |
@@ -8,6 +8,7 import inspect | |||
|
8 | 8 | from IPython.external.qt import QtCore, QtGui |
|
9 | 9 | |
|
10 | 10 | # IPython imports. |
|
11 | from IPython.utils.py3compat import iteritems | |
|
11 | 12 | from IPython.utils.traitlets import HasTraits, TraitType |
|
12 | 13 | |
|
13 | 14 | #----------------------------------------------------------------------------- |
@@ -27,7 +28,7 class MetaQObjectHasTraits(MetaQObject, MetaHasTraits): | |||
|
27 | 28 | def __new__(mcls, name, bases, classdict): |
|
28 | 29 | # FIXME: this duplicates the code from MetaHasTraits. |
|
29 | 30 | # I don't think a super() call will help me here. |
|
30 |
for k,v in |
|
|
31 | for k,v in iteritems(classdict): | |
|
31 | 32 | if isinstance(v, TraitType): |
|
32 | 33 | v.name = k |
|
33 | 34 | elif inspect.isclass(v): |
@@ -24,7 +24,7 except ImportError: | |||
|
24 | 24 | from base64 import encodestring as encodebytes |
|
25 | 25 | |
|
26 | 26 | from IPython.utils import py3compat |
|
27 | from IPython.utils.py3compat import string_types, unicode_type | |
|
27 | from IPython.utils.py3compat import string_types, unicode_type, iteritems | |
|
28 | 28 | from IPython.utils.encoding import DEFAULT_ENCODING |
|
29 | 29 | next_attr_name = '__next__' if py3compat.PY3 else 'next' |
|
30 | 30 | |
@@ -67,7 +67,7 def extract_dates(obj): | |||
|
67 | 67 | """extract ISO8601 dates from unpacked JSON""" |
|
68 | 68 | if isinstance(obj, dict): |
|
69 | 69 | obj = dict(obj) # don't clobber |
|
70 |
for k,v in |
|
|
70 | for k,v in iteritems(obj): | |
|
71 | 71 | obj[k] = extract_dates(v) |
|
72 | 72 | elif isinstance(obj, (list, tuple)): |
|
73 | 73 | obj = [ extract_dates(o) for o in obj ] |
@@ -84,7 +84,7 def squash_dates(obj): | |||
|
84 | 84 | """squash datetime objects into ISO8601 strings""" |
|
85 | 85 | if isinstance(obj, dict): |
|
86 | 86 | obj = dict(obj) # don't clobber |
|
87 |
for k,v in |
|
|
87 | for k,v in iteritems(obj): | |
|
88 | 88 | obj[k] = squash_dates(v) |
|
89 | 89 | elif isinstance(obj, (list, tuple)): |
|
90 | 90 | obj = [ squash_dates(o) for o in obj ] |
@@ -219,7 +219,7 def json_clean(obj): | |||
|
219 | 219 | 'key collision would lead to dropped values') |
|
220 | 220 | # If all OK, proceed by making the new dict that will be json-safe |
|
221 | 221 | out = {} |
|
222 |
for k,v in |
|
|
222 | for k,v in iteritems(obj): | |
|
223 | 223 | out[str(k)] = json_clean(v) |
|
224 | 224 | return out |
|
225 | 225 |
@@ -28,7 +28,7 except ImportError: | |||
|
28 | 28 | from . import codeutil # This registers a hook when it's imported |
|
29 | 29 | from . import py3compat |
|
30 | 30 | from .importstring import import_item |
|
31 | from .py3compat import string_types | |
|
31 | from .py3compat import string_types, iteritems | |
|
32 | 32 | |
|
33 | 33 | from IPython.config import Application |
|
34 | 34 | |
@@ -246,7 +246,7 def can(obj): | |||
|
246 | 246 | |
|
247 | 247 | import_needed = False |
|
248 | 248 | |
|
249 |
for cls,canner in |
|
|
249 | for cls,canner in iteritems(can_map): | |
|
250 | 250 | if isinstance(cls, string_types): |
|
251 | 251 | import_needed = True |
|
252 | 252 | break |
@@ -271,7 +271,7 def can_dict(obj): | |||
|
271 | 271 | """can the *values* of a dict""" |
|
272 | 272 | if istype(obj, dict): |
|
273 | 273 | newobj = {} |
|
274 |
for k, v in |
|
|
274 | for k, v in iteritems(obj): | |
|
275 | 275 | newobj[k] = can(v) |
|
276 | 276 | return newobj |
|
277 | 277 | else: |
@@ -291,7 +291,7 def uncan(obj, g=None): | |||
|
291 | 291 | """invert canning""" |
|
292 | 292 | |
|
293 | 293 | import_needed = False |
|
294 |
for cls,uncanner in |
|
|
294 | for cls,uncanner in iteritems(uncan_map): | |
|
295 | 295 | if isinstance(cls, string_types): |
|
296 | 296 | import_needed = True |
|
297 | 297 | break |
@@ -309,7 +309,7 def uncan(obj, g=None): | |||
|
309 | 309 | def uncan_dict(obj, g=None): |
|
310 | 310 | if istype(obj, dict): |
|
311 | 311 | newobj = {} |
|
312 |
for k, v in |
|
|
312 | for k, v in iteritems(obj): | |
|
313 | 313 | newobj[k] = uncan(v,g) |
|
314 | 314 | return newobj |
|
315 | 315 | else: |
@@ -93,6 +93,8 if sys.version_info[0] >= 3: | |||
|
93 | 93 | |
|
94 | 94 | open = orig_open |
|
95 | 95 | xrange = range |
|
96 | iteritems = dict.items | |
|
97 | itervalues = dict.values | |
|
96 | 98 | |
|
97 | 99 | MethodType = types.MethodType |
|
98 | 100 | |
@@ -168,6 +170,8 else: | |||
|
168 | 170 | self.f.close() |
|
169 | 171 | |
|
170 | 172 | xrange = xrange |
|
173 | iteritems = dict.iteritems | |
|
174 | itervalues = dict.itervalues | |
|
171 | 175 | |
|
172 | 176 | def MethodType(func, instance): |
|
173 | 177 | return types.MethodType(func, instance, type(instance)) |
@@ -21,7 +21,7 import nose.tools as nt | |||
|
21 | 21 | # our own |
|
22 | 22 | from IPython.utils import jsonutil, tz |
|
23 | 23 | from ..jsonutil import json_clean, encode_images |
|
24 | from ..py3compat import unicode_to_str, str_to_bytes | |
|
24 | from ..py3compat import unicode_to_str, str_to_bytes, iteritems | |
|
25 | 25 | |
|
26 | 26 | #----------------------------------------------------------------------------- |
|
27 | 27 | # Test functions |
@@ -71,7 +71,7 def test_encode_images(): | |||
|
71 | 71 | 'image/jpeg' : jpegdata, |
|
72 | 72 | } |
|
73 | 73 | encoded = encode_images(fmt) |
|
74 |
for key, value in |
|
|
74 | for key, value in iteritems(fmt): | |
|
75 | 75 | # encoded has unicode, want bytes |
|
76 | 76 | decoded = decodestring(encoded[key].encode('ascii')) |
|
77 | 77 | nt.assert_equal(decoded, value) |
@@ -79,11 +79,11 def test_encode_images(): | |||
|
79 | 79 | nt.assert_equal(encoded, encoded2) |
|
80 | 80 | |
|
81 | 81 | b64_str = {} |
|
82 |
for key, encoded in |
|
|
82 | for key, encoded in iteritems(encoded): | |
|
83 | 83 | b64_str[key] = unicode_to_str(encoded) |
|
84 | 84 | encoded3 = encode_images(b64_str) |
|
85 | 85 | nt.assert_equal(encoded3, b64_str) |
|
86 |
for key, value in |
|
|
86 | for key, value in iteritems(fmt): | |
|
87 | 87 | # encoded3 has str, want bytes |
|
88 | 88 | decoded = decodestring(str_to_bytes(encoded3[key])) |
|
89 | 89 | nt.assert_equal(decoded, value) |
@@ -66,6 +66,7 except: | |||
|
66 | 66 | |
|
67 | 67 | from .importstring import import_item |
|
68 | 68 | from IPython.utils import py3compat |
|
69 | from IPython.utils.py3compat import iteritems | |
|
69 | 70 | |
|
70 | 71 | SequenceTypes = (list, tuple, set, frozenset) |
|
71 | 72 | |
@@ -373,7 +374,7 class MetaHasTraits(type): | |||
|
373 | 374 | # print "MetaHasTraitlets (mcls, name): ", mcls, name |
|
374 | 375 | # print "MetaHasTraitlets (bases): ", bases |
|
375 | 376 | # print "MetaHasTraitlets (classdict): ", classdict |
|
376 |
for k,v in |
|
|
377 | for k,v in iteritems(classdict): | |
|
377 | 378 | if isinstance(v, TraitType): |
|
378 | 379 | v.name = k |
|
379 | 380 | elif inspect.isclass(v): |
@@ -389,7 +390,7 class MetaHasTraits(type): | |||
|
389 | 390 | This sets the :attr:`this_class` attribute of each TraitType in the |
|
390 | 391 | class dict to the newly created class ``cls``. |
|
391 | 392 | """ |
|
392 |
for k, v in |
|
|
393 | for k, v in iteritems(classdict): | |
|
393 | 394 | if isinstance(v, TraitType): |
|
394 | 395 | v.this_class = cls |
|
395 | 396 | super(MetaHasTraits, cls).__init__(name, bases, classdict) |
@@ -427,7 +428,7 class HasTraits(py3compat.with_metaclass(MetaHasTraits, object)): | |||
|
427 | 428 | # Allow trait values to be set using keyword arguments. |
|
428 | 429 | # We need to use setattr for this to trigger validation and |
|
429 | 430 | # notifications. |
|
430 |
for key, value in |
|
|
431 | for key, value in iteritems(kw): | |
|
431 | 432 | setattr(self, key, value) |
|
432 | 433 | |
|
433 | 434 | def _notify_trait(self, name, old_value, new_value): |
@@ -18,6 +18,7 import re | |||
|
18 | 18 | import types |
|
19 | 19 | |
|
20 | 20 | from IPython.utils.dir2 import dir2 |
|
21 | from .py3compat import iteritems | |
|
21 | 22 | |
|
22 | 23 | def create_typestr2type_dicts(dont_include_in_type2typestr=["lambda"]): |
|
23 | 24 | """Return dictionaries mapping lower case typename (e.g. 'tuple') to type |
@@ -82,7 +83,7 def filter_ns(ns, name_pattern="*", type_pattern="all", ignore_case=True, | |||
|
82 | 83 | reg = re.compile(pattern+"$") |
|
83 | 84 | |
|
84 | 85 | # Check each one matches regex; shouldn't be hidden; of correct type. |
|
85 |
return dict((key,obj) for key, obj in |
|
|
86 | return dict((key,obj) for key, obj in iteritems(ns) if reg.match(key) \ | |
|
86 | 87 | and show_hidden(key, show_all) \ |
|
87 | 88 | and is_type(obj, type_pattern) ) |
|
88 | 89 | |
@@ -102,10 +103,10 def list_namespace(namespace, type_pattern, filter, ignore_case=False, show_all= | |||
|
102 | 103 | type_pattern="all", |
|
103 | 104 | ignore_case=ignore_case, show_all=show_all) |
|
104 | 105 | results = {} |
|
105 |
for name, obj in |
|
|
106 | for name, obj in iteritems(filtered): | |
|
106 | 107 | ns = list_namespace(dict_dir(obj), type_pattern, |
|
107 | 108 | ".".join(pattern_list[1:]), |
|
108 | 109 | ignore_case=ignore_case, show_all=show_all) |
|
109 |
for inner_name, inner_obj in |
|
|
110 | for inner_name, inner_obj in iteritems(ns): | |
|
110 | 111 | results["%s.%s"%(name,inner_name)] = inner_obj |
|
111 | 112 | return results |
General Comments 0
You need to be logged in to leave comments.
Login now