Show More
@@ -47,7 +47,7 b' from .testing import test' | |||
|
47 | 47 | |
|
48 | 48 | # Release data |
|
49 | 49 | __author__ = '' |
|
50 | for author, email in release.authors.values(): | |
|
50 | for author, email in release.authors.itervalues(): | |
|
51 | 51 | __author__ += author + ' <' + email + '>\n' |
|
52 | 52 | __license__ = release.license |
|
53 | 53 | __version__ = release.version |
@@ -112,7 +112,7 b' class Configurable(HasTraits):' | |||
|
112 | 112 | # dynamically create the section with name self.__class__.__name__. |
|
113 | 113 | if new._has_section(sname): |
|
114 | 114 | my_config = new[sname] |
|
115 | for k, v in traits.items(): | |
|
115 | for k, v in traits.iteritems(): | |
|
116 | 116 | # Don't allow traitlets with config=True to start with |
|
117 | 117 | # uppercase. Otherwise, they are confused with Config |
|
118 | 118 | # subsections. But, developers shouldn't have uppercase |
@@ -1,3 +1,4 b'' | |||
|
1 | # -*- coding: utf-8 -*- | |
|
1 | 2 | # coding: utf-8 |
|
2 | 3 | """A simple configuration system. |
|
3 | 4 | |
@@ -73,7 +74,7 b' class Config(dict):' | |||
|
73 | 74 | |
|
74 | 75 | def _merge(self, other): |
|
75 | 76 | to_update = {} |
|
76 | for k, v in other.items(): | |
|
77 | for k, v in other.iteritems(): | |
|
77 | 78 | if not self.has_key(k): |
|
78 | 79 | to_update[k] = v |
|
79 | 80 | else: # I have this key |
@@ -92,15 +93,17 b' class Config(dict):' | |||
|
92 | 93 | else: |
|
93 | 94 | return False |
|
94 | 95 | |
|
95 |
def |
|
|
96 | def __contains__(self, key): | |
|
96 | 97 | if self._is_section_key(key): |
|
97 | 98 | return True |
|
98 | 99 | else: |
|
99 | return dict.has_key(self, key) | |
|
100 | return super(Config, self).__contains__(key) | |
|
101 | # .has_key is deprecated for dictionaries. | |
|
102 | has_key = __contains__ | |
|
100 | 103 | |
|
101 | 104 | def _has_section(self, key): |
|
102 | 105 | if self._is_section_key(key): |
|
103 | if dict.has_key(self, key): | |
|
106 | if super(Config, self).__contains__(key): | |
|
104 | 107 | return True |
|
105 | 108 | return False |
|
106 | 109 | |
@@ -363,7 +366,7 b' class ArgParseConfigLoader(CommandLineConfigLoader):' | |||
|
363 | 366 | |
|
364 | 367 | def _convert_to_config(self): |
|
365 | 368 | """self.parsed_data->self.config""" |
|
366 | for k, v in vars(self.parsed_data).items(): | |
|
369 | for k, v in vars(self.parsed_data).iteritems(): | |
|
367 | 370 | exec_str = 'self.config.' + k + '= v' |
|
368 | 371 | exec exec_str in locals(), globals() |
|
369 | 372 |
@@ -336,7 +336,7 b' def cd_completer(self, event):' | |||
|
336 | 336 | return [compress_user(relpath, tilde_expand, tilde_val)] |
|
337 | 337 | |
|
338 | 338 | # if no completions so far, try bookmarks |
|
339 | bks = self.db.get('bookmarks',{}).keys() | |
|
339 | bks = self.db.get('bookmarks',{}).iterkeys() | |
|
340 | 340 | bkmatches = [s for s in bks if s.startswith(event.symbol)] |
|
341 | 341 | if bkmatches: |
|
342 | 342 | return bkmatches |
@@ -260,7 +260,7 b' class ShadowHist(object):' | |||
|
260 | 260 | |
|
261 | 261 | def all(self): |
|
262 | 262 | d = self.db.hdict('shadowhist') |
|
263 | items = [(i,s) for (s,i) in d.items()] | |
|
263 | items = [(i,s) for (s,i) in d.iteritems()] | |
|
264 | 264 | items.sort() |
|
265 | 265 | return items |
|
266 | 266 |
@@ -22,13 +22,12 b' import __future__' | |||
|
22 | 22 | import abc |
|
23 | 23 | import atexit |
|
24 | 24 | import codeop |
|
25 | import exceptions | |
|
26 | import new | |
|
27 | 25 | import os |
|
28 | 26 | import re |
|
29 | 27 | import string |
|
30 | 28 | import sys |
|
31 | 29 | import tempfile |
|
30 | import types | |
|
32 | 31 | from contextlib import nested |
|
33 | 32 | |
|
34 | 33 | from IPython.config.configurable import Configurable |
@@ -102,7 +101,7 b' def softspace(file, newvalue):' | |||
|
102 | 101 | |
|
103 | 102 | def no_op(*a, **kw): pass |
|
104 | 103 | |
|
105 |
class SpaceInInput( |
|
|
104 | class SpaceInInput(Exception): pass | |
|
106 | 105 | |
|
107 | 106 | class Bunch: pass |
|
108 | 107 | |
@@ -512,7 +511,7 b' class InteractiveShell(Configurable, Magic):' | |||
|
512 | 511 | def restore_sys_module_state(self): |
|
513 | 512 | """Restore the state of the sys module.""" |
|
514 | 513 | try: |
|
515 | for k, v in self._orig_sys_module_state.items(): | |
|
514 | for k, v in self._orig_sys_module_state.iteritems(): | |
|
516 | 515 | setattr(sys, k, v) |
|
517 | 516 | except AttributeError: |
|
518 | 517 | pass |
@@ -550,7 +549,7 b' class InteractiveShell(Configurable, Magic):' | |||
|
550 | 549 | # accepts it. Probably at least check that the hook takes the number |
|
551 | 550 | # of args it's supposed to. |
|
552 | 551 | |
|
553 |
f = |
|
|
552 | f = types.MethodType(hook, self) | |
|
554 | 553 | |
|
555 | 554 | # check if the hook is for strdispatcher first |
|
556 | 555 | if str_key is not None: |
@@ -1249,7 +1248,7 b' class InteractiveShell(Configurable, Magic):' | |||
|
1249 | 1248 | def init_shadow_hist(self): |
|
1250 | 1249 | try: |
|
1251 | 1250 | self.db = pickleshare.PickleShareDB(self.ipython_dir + "/db") |
|
1252 |
except |
|
|
1251 | except UnicodeDecodeError: | |
|
1253 | 1252 | print "Your ipython_dir can't be decoded to unicode!" |
|
1254 | 1253 | print "Please set HOME environment variable to something that" |
|
1255 | 1254 | print r"only has ASCII characters, e.g. c:\home" |
@@ -1414,7 +1413,7 b' class InteractiveShell(Configurable, Magic):' | |||
|
1414 | 1413 | |
|
1415 | 1414 | if handler is None: handler = dummy_handler |
|
1416 | 1415 | |
|
1417 |
self.CustomTB = |
|
|
1416 | self.CustomTB = types.MethodType(handler, self) | |
|
1418 | 1417 | self.custom_exceptions = exc_tuple |
|
1419 | 1418 | |
|
1420 | 1419 | def excepthook(self, etype, value, tb): |
@@ -1756,8 +1755,7 b' class InteractiveShell(Configurable, Magic):' | |||
|
1756 | 1755 | The position argument (defaults to 0) is the index in the completers |
|
1757 | 1756 | list where you want the completer to be inserted.""" |
|
1758 | 1757 | |
|
1759 |
newcomp = |
|
|
1760 | self.Completer.__class__) | |
|
1758 | newcomp = types.MethodType(completer, self.Completer) | |
|
1761 | 1759 | self.Completer.matchers.insert(pos,newcomp) |
|
1762 | 1760 | |
|
1763 | 1761 | def set_readline_completer(self): |
@@ -1828,12 +1826,11 b' class InteractiveShell(Configurable, Magic):' | |||
|
1828 | 1826 | print 'Magic function. Passed parameter is between < >:' |
|
1829 | 1827 | print '<%s>' % parameter_s |
|
1830 | 1828 | print 'The self object is:',self |
|
1831 | ||
|
1829 | newcomp = types.MethodType(completer, self.Completer) | |
|
1832 | 1830 | self.define_magic('foo',foo_impl) |
|
1833 | 1831 | """ |
|
1834 | 1832 | |
|
1835 | import new | |
|
1836 | im = new.instancemethod(func,self, self.__class__) | |
|
1833 | im = types.MethodType(func, self) | |
|
1837 | 1834 | old = getattr(self, "magic_" + magicname, None) |
|
1838 | 1835 | setattr(self, "magic_" + magicname, im) |
|
1839 | 1836 | return old |
@@ -237,7 +237,7 b' class PrefilterManager(Configurable):' | |||
|
237 | 237 | This must be called after the priority of a transformer is changed. |
|
238 | 238 | The :meth:`register_transformer` method calls this automatically. |
|
239 | 239 | """ |
|
240 |
self._transformers.sort( |
|
|
240 | self._transformers.sort(key=lambda x: x.priority) | |
|
241 | 241 | |
|
242 | 242 | @property |
|
243 | 243 | def transformers(self): |
@@ -273,7 +273,7 b' class PrefilterManager(Configurable):' | |||
|
273 | 273 | This must be called after the priority of a checker is changed. |
|
274 | 274 | The :meth:`register_checker` method calls this automatically. |
|
275 | 275 | """ |
|
276 |
self._checkers.sort( |
|
|
276 | self._checkers.sort(key=lambda x: x.priority) | |
|
277 | 277 | |
|
278 | 278 | @property |
|
279 | 279 | def checkers(self): |
@@ -28,7 +28,7 b' from IPython.core import inputsplitter as isp' | |||
|
28 | 28 | # Note: at the bottom, there's a slightly more complete version of this that |
|
29 | 29 | # can be useful during development of code here. |
|
30 | 30 | |
|
31 |
def mini_interactive_loop( |
|
|
31 | def mini_interactive_loop(input_func): | |
|
32 | 32 | """Minimal example of the logic of an interactive interpreter loop. |
|
33 | 33 | |
|
34 | 34 | This serves as an example, and it is used by the test system with a fake |
@@ -43,7 +43,7 b' def mini_interactive_loop(raw_input):' | |||
|
43 | 43 | while isp.push_accepts_more(): |
|
44 | 44 | indent = ' '*isp.indent_spaces |
|
45 | 45 | prompt = '>>> ' + indent |
|
46 |
line = indent + |
|
|
46 | line = indent + input_func(prompt) | |
|
47 | 47 | isp.push(line) |
|
48 | 48 | |
|
49 | 49 | # Here we just return input so we can use it in a test suite, but a real |
@@ -356,7 +356,7 b' class InteractiveLoopTestCase(unittest.TestCase):' | |||
|
356 | 356 | # We can't check that the provided ns is identical to the test_ns, |
|
357 | 357 | # because Python fills test_ns with extra keys (copyright, etc). But |
|
358 | 358 | # we can check that the given dict is *contained* in test_ns |
|
359 | for k,v in ns.items(): | |
|
359 | for k,v in ns.iteritems(): | |
|
360 | 360 | self.assertEqual(test_ns[k], v) |
|
361 | 361 | |
|
362 | 362 | def test_simple(self): |
@@ -33,7 +33,7 b' def test_rehashx():' | |||
|
33 | 33 | # Practically ALL ipython development systems will have more than 10 aliases |
|
34 | 34 | |
|
35 | 35 | yield (nt.assert_true, len(_ip.alias_manager.alias_table) > 10) |
|
36 | for key, val in _ip.alias_manager.alias_table.items(): | |
|
36 | for key, val in _ip.alias_manager.alias_table.iteritems(): | |
|
37 | 37 | # we must strip dots from alias names |
|
38 | 38 | nt.assert_true('.' not in key) |
|
39 | 39 |
@@ -712,14 +712,14 b' class VerboseTB(TBTools):' | |||
|
712 | 712 | |
|
713 | 713 | head = '%s%s%s\n%s%s%s\n%s' % (Colors.topline, '-'*75, ColorsNormal, |
|
714 | 714 | exc, ' '*(75-len(str(etype))-len(pyver)), |
|
715 |
pyver, |
|
|
715 | pyver, date.rjust(75) ) | |
|
716 | 716 | head += "\nA problem occured executing Python code. Here is the sequence of function"\ |
|
717 | 717 | "\ncalls leading up to the error, with the most recent (innermost) call last." |
|
718 | 718 | else: |
|
719 | 719 | # Simplified header |
|
720 | 720 | head = '%s%s%s\n%s%s' % (Colors.topline, '-'*75, ColorsNormal,exc, |
|
721 |
|
|
|
722 | 75 - len(str(etype)) ) ) | |
|
721 | 'Traceback (most recent call last)'.\ | |
|
722 | rjust(75 - len(str(etype)) ) ) | |
|
723 | 723 | frames = [] |
|
724 | 724 | # Flush cache before calling inspect. This helps alleviate some of the |
|
725 | 725 | # problems with python 2.3's inspect.py. |
@@ -78,7 +78,6 b" __license__ = 'MIT'" | |||
|
78 | 78 | import string |
|
79 | 79 | import sys |
|
80 | 80 | from tokenize import tokenprog |
|
81 | from types import StringType | |
|
82 | 81 | |
|
83 | 82 | class ItplError(ValueError): |
|
84 | 83 | def __init__(self, text, pos): |
@@ -144,7 +143,7 b' class Itpl:' | |||
|
144 | 143 | pos = 0 |
|
145 | 144 | |
|
146 | 145 | while 1: |
|
147 |
dollar = |
|
|
146 | dollar = format.find("$", pos) | |
|
148 | 147 | if dollar < 0: break |
|
149 | 148 | nextchar = format[dollar+1] |
|
150 | 149 |
@@ -1,3 +1,4 b'' | |||
|
1 | # -*- coding: utf-8 -*- | |
|
1 | 2 | # configobj.py |
|
2 | 3 | # A config file reader/writer that supports nested sections in config files. |
|
3 | 4 | # Copyright (C) 2005-2008 Michael Foord, Nicola Larosa |
@@ -32,22 +33,7 b' except ImportError:' | |||
|
32 | 33 | pass |
|
33 | 34 | from types import StringTypes |
|
34 | 35 | from warnings import warn |
|
35 | try: | |
|
36 | from codecs import BOM_UTF8, BOM_UTF16, BOM_UTF16_BE, BOM_UTF16_LE | |
|
37 | except ImportError: | |
|
38 | # Python 2.2 does not have these | |
|
39 | # UTF-8 | |
|
40 | BOM_UTF8 = '\xef\xbb\xbf' | |
|
41 | # UTF-16, little endian | |
|
42 | BOM_UTF16_LE = '\xff\xfe' | |
|
43 | # UTF-16, big endian | |
|
44 | BOM_UTF16_BE = '\xfe\xff' | |
|
45 | if sys.byteorder == 'little': | |
|
46 | # UTF-16, native endianness | |
|
47 | BOM_UTF16 = BOM_UTF16_LE | |
|
48 | else: | |
|
49 | # UTF-16, native endianness | |
|
50 | BOM_UTF16 = BOM_UTF16_BE | |
|
36 | from codecs import BOM_UTF8, BOM_UTF16, BOM_UTF16_BE, BOM_UTF16_LE | |
|
51 | 37 | |
|
52 | 38 | # A dictionary mapping BOM to |
|
53 | 39 | # the encoding to decode with, and what to set the |
@@ -101,21 +87,6 b' wspace_plus = \' \\r\\t\\n\\v\\t\\\'"\'' | |||
|
101 | 87 | tsquot = '"""%s"""' |
|
102 | 88 | tdquot = "'''%s'''" |
|
103 | 89 | |
|
104 | try: | |
|
105 | enumerate | |
|
106 | except NameError: | |
|
107 | def enumerate(obj): | |
|
108 | """enumerate for Python 2.2.""" | |
|
109 | i = -1 | |
|
110 | for item in obj: | |
|
111 | i += 1 | |
|
112 | yield i, item | |
|
113 | ||
|
114 | try: | |
|
115 | True, False | |
|
116 | except NameError: | |
|
117 | True, False = 1, 0 | |
|
118 | ||
|
119 | 90 | |
|
120 | 91 | __version__ = '4.5.2' |
|
121 | 92 | |
@@ -814,7 +785,7 b' class Section(dict):' | |||
|
814 | 785 | >>> c2 |
|
815 | 786 | {'section1': {'option1': 'False', 'subsection': {'more_options': 'False'}}} |
|
816 | 787 | """ |
|
817 | for key, val in indict.items(): | |
|
788 | for key, val in indict.iteritems(): | |
|
818 | 789 | if (key in self and isinstance(self[key], dict) and |
|
819 | 790 | isinstance(val, dict)): |
|
820 | 791 | self[key].merge(val) |
@@ -1438,7 +1409,7 b' class ConfigObj(Section):' | |||
|
1438 | 1409 | enc = BOM_LIST[self.encoding.lower()] |
|
1439 | 1410 | if enc == 'utf_16': |
|
1440 | 1411 | # For UTF16 we try big endian and little endian |
|
1441 | for BOM, (encoding, final_encoding) in BOMS.items(): | |
|
1412 | for BOM, (encoding, final_encoding) in BOMS.iteritems(): | |
|
1442 | 1413 | if not final_encoding: |
|
1443 | 1414 | # skip UTF8 |
|
1444 | 1415 | continue |
@@ -1468,7 +1439,7 b' class ConfigObj(Section):' | |||
|
1468 | 1439 | return self._decode(infile, self.encoding) |
|
1469 | 1440 | |
|
1470 | 1441 | # No encoding specified - so we need to check for UTF8/UTF16 |
|
1471 | for BOM, (encoding, final_encoding) in BOMS.items(): | |
|
1442 | for BOM, (encoding, final_encoding) in BOMS.iteritems(): | |
|
1472 | 1443 | if not line.startswith(BOM): |
|
1473 | 1444 | continue |
|
1474 | 1445 | else: |
@@ -2481,7 +2452,7 b' def flatten_errors(cfg, res, levels=None, results=None):' | |||
|
2481 | 2452 | if levels: |
|
2482 | 2453 | levels.pop() |
|
2483 | 2454 | return results |
|
2484 | for (key, val) in res.items(): | |
|
2455 | for (key, val) in res.iteritems(): | |
|
2485 | 2456 | if val == True: |
|
2486 | 2457 | continue |
|
2487 | 2458 | if isinstance(cfg.get(key), dict): |
@@ -7,7 +7,7 b" d = path('/home/guido/bin')" | |||
|
7 | 7 | for f in d.files('*.py'): |
|
8 | 8 | f.chmod(0755) |
|
9 | 9 | |
|
10 |
This module requires Python 2. |
|
|
10 | This module requires Python 2.5 or later. | |
|
11 | 11 | |
|
12 | 12 | |
|
13 | 13 | URL: http://www.jorendorff.com/articles/python/path |
@@ -30,9 +30,7 b' Date: 9 Mar 2007' | |||
|
30 | 30 | from __future__ import generators |
|
31 | 31 | |
|
32 | 32 | import sys, warnings, os, fnmatch, glob, shutil, codecs |
|
33 | # deprecated in python 2.6 | |
|
34 | warnings.filterwarnings('ignore', r'.*md5.*') | |
|
35 | import md5 | |
|
33 | from hashlib import md5 | |
|
36 | 34 | |
|
37 | 35 | __version__ = '2.2' |
|
38 | 36 | __all__ = ['path'] |
@@ -49,38 +47,11 b' else:' | |||
|
49 | 47 | except ImportError: |
|
50 | 48 | pwd = None |
|
51 | 49 | |
|
52 | # Pre-2.3 support. Are unicode filenames supported? | |
|
53 | _base = str | |
|
54 | _getcwd = os.getcwd | |
|
55 | try: | |
|
56 | if os.path.supports_unicode_filenames: | |
|
57 | _base = unicode | |
|
58 | _getcwd = os.getcwdu | |
|
59 | except AttributeError: | |
|
60 | pass | |
|
61 | ||
|
62 | # Pre-2.3 workaround for booleans | |
|
63 | try: | |
|
64 | True, False | |
|
65 | except NameError: | |
|
66 | True, False = 1, 0 | |
|
67 | ||
|
68 | # Pre-2.3 workaround for basestring. | |
|
69 | try: | |
|
70 | basestring | |
|
71 | except NameError: | |
|
72 | basestring = (str, unicode) | |
|
73 | ||
|
74 | # Universal newline support | |
|
75 | _textmode = 'r' | |
|
76 | if hasattr(file, 'newlines'): | |
|
77 | _textmode = 'U' | |
|
78 | ||
|
79 | 50 | |
|
80 | 51 | class TreeWalkWarning(Warning): |
|
81 | 52 | pass |
|
82 | 53 | |
|
83 |
class path( |
|
|
54 | class path(unicode): | |
|
84 | 55 | """ Represents a filesystem path. |
|
85 | 56 | |
|
86 | 57 | For documentation on individual methods, consult their |
@@ -90,12 +61,12 b' class path(_base):' | |||
|
90 | 61 | # --- Special Python methods. |
|
91 | 62 | |
|
92 | 63 | def __repr__(self): |
|
93 |
return 'path(%s)' % |
|
|
64 | return 'path(%s)' % unicode.__repr__(self) | |
|
94 | 65 | |
|
95 | 66 | # Adding a path and a string yields a path. |
|
96 | 67 | def __add__(self, more): |
|
97 | 68 | try: |
|
98 |
resultStr = |
|
|
69 | resultStr = unicode.__add__(self, more) | |
|
99 | 70 | except TypeError: #Python bug |
|
100 | 71 | resultStr = NotImplemented |
|
101 | 72 | if resultStr is NotImplemented: |
@@ -122,7 +93,7 b' class path(_base):' | |||
|
122 | 93 | |
|
123 | 94 | def getcwd(cls): |
|
124 | 95 | """ Return the current working directory as a path object. """ |
|
125 |
return cls( |
|
|
96 | return cls(os.getcwdu()) | |
|
126 | 97 | getcwd = classmethod(getcwd) |
|
127 | 98 | |
|
128 | 99 | |
@@ -152,7 +123,7 b' class path(_base):' | |||
|
152 | 123 | return base |
|
153 | 124 | |
|
154 | 125 | def _get_ext(self): |
|
155 |
f, ext = os.path.splitext( |
|
|
126 | f, ext = os.path.splitext(unicode(self)) | |
|
156 | 127 | return ext |
|
157 | 128 | |
|
158 | 129 | def _get_drive(self): |
@@ -513,14 +484,14 b' class path(_base):' | |||
|
513 | 484 | of all the files users have in their bin directories. |
|
514 | 485 | """ |
|
515 | 486 | cls = self.__class__ |
|
516 |
return [cls(s) for s in glob.glob( |
|
|
487 | return [cls(s) for s in glob.glob(unicode(self / pattern))] | |
|
517 | 488 | |
|
518 | 489 | |
|
519 | 490 | # --- Reading or writing an entire file at once. |
|
520 | 491 | |
|
521 | 492 | def open(self, mode='r'): |
|
522 | 493 | """ Open this file. Return a file object. """ |
|
523 |
return |
|
|
494 | return open(self, mode) | |
|
524 | 495 | |
|
525 | 496 | def bytes(self): |
|
526 | 497 | """ Open this file, read all bytes, return them as a string. """ |
@@ -563,7 +534,7 b' class path(_base):' | |||
|
563 | 534 | """ |
|
564 | 535 | if encoding is None: |
|
565 | 536 | # 8-bit |
|
566 |
f = self.open( |
|
|
537 | f = self.open('U') | |
|
567 | 538 | try: |
|
568 | 539 | return f.read() |
|
569 | 540 | finally: |
@@ -690,7 +661,7 b' class path(_base):' | |||
|
690 | 661 | This uses 'U' mode in Python 2.3 and later. |
|
691 | 662 | """ |
|
692 | 663 | if encoding is None and retain: |
|
693 |
f = self.open( |
|
|
664 | f = self.open('U') | |
|
694 | 665 | try: |
|
695 | 666 | return f.readlines() |
|
696 | 667 | finally: |
@@ -770,7 +741,7 b' class path(_base):' | |||
|
770 | 741 | """ |
|
771 | 742 | f = self.open('rb') |
|
772 | 743 | try: |
|
773 |
m = md5 |
|
|
744 | m = md5() | |
|
774 | 745 | while True: |
|
775 | 746 | d = f.read(8192) |
|
776 | 747 | if not d: |
@@ -101,7 +101,8 b'' | |||
|
101 | 101 | Portions (c) 2009 by Robert Kern. |
|
102 | 102 | :license: BSD License. |
|
103 | 103 | """ |
|
104 | import __future__ | |
|
104 | from __future__ import with_statement | |
|
105 | from contextlib import contextmanager | |
|
105 | 106 | import sys |
|
106 | 107 | import types |
|
107 | 108 | import re |
@@ -138,12 +139,6 b" def pprint(obj, verbose=False, max_width=79, newline='\\n'):" | |||
|
138 | 139 | sys.stdout.write(newline) |
|
139 | 140 | sys.stdout.flush() |
|
140 | 141 | |
|
141 | ||
|
142 | # add python2.5 context managers if we have the with statement feature | |
|
143 | if hasattr(__future__, 'with_statement'): exec ''' | |
|
144 | from __future__ import with_statement | |
|
145 | from contextlib import contextmanager | |
|
146 | ||
|
147 | 142 | class _PrettyPrinterBase(object): |
|
148 | 143 | |
|
149 | 144 | @contextmanager |
@@ -164,16 +159,6 b' class _PrettyPrinterBase(object):' | |||
|
164 | 159 | yield |
|
165 | 160 | finally: |
|
166 | 161 | self.end_group(indent, close) |
|
167 | ''' | |
|
168 | else: | |
|
169 | class _PrettyPrinterBase(object): | |
|
170 | ||
|
171 | def _unsupported(self, *a, **kw): | |
|
172 | """unsupported operation""" | |
|
173 | raise RuntimeError('not available in this python version') | |
|
174 | group = indent = _unsupported | |
|
175 | del _unsupported | |
|
176 | ||
|
177 | 162 | |
|
178 | 163 | class PrettyPrinter(_PrettyPrinterBase): |
|
179 | 164 | """ |
@@ -1,3 +1,4 b'' | |||
|
1 | # -*- coding: utf-8 -*- | |
|
1 | 2 | # module pyparsing.py |
|
2 | 3 | # |
|
3 | 4 | # Copyright (c) 2003-2009 Paul T. McGuire |
@@ -400,7 +401,7 b' class ParseResults(object):' | |||
|
400 | 401 | |
|
401 | 402 | def values( self ): |
|
402 | 403 | """Returns all named result values.""" |
|
403 | return [ v[-1][0] for v in self.__tokdict.values() ] | |
|
404 | return [ v[-1][0] for v in self.__tokdict.itervalues() ] | |
|
404 | 405 | |
|
405 | 406 | def __getattr__( self, name ): |
|
406 | 407 | if name not in self.__slots__: |
@@ -422,7 +423,7 b' class ParseResults(object):' | |||
|
422 | 423 | if other.__tokdict: |
|
423 | 424 | offset = len(self.__toklist) |
|
424 | 425 | addoffset = ( lambda a: (a<0 and offset) or (a+offset) ) |
|
425 | otheritems = other.__tokdict.items() | |
|
426 | otheritems = other.__tokdict.iteritems() | |
|
426 | 427 | otherdictitems = [(k, _ParseResultsWithOffset(v[0],addoffset(v[1])) ) |
|
427 | 428 | for (k,vlist) in otheritems for v in vlist] |
|
428 | 429 | for k,v in otherdictitems: |
@@ -488,7 +489,7 b' class ParseResults(object):' | |||
|
488 | 489 | """Returns the parse results as XML. Tags are created for tokens and lists that have defined results names.""" |
|
489 | 490 | nl = "\n" |
|
490 | 491 | out = [] |
|
491 |
namedItems = dict( |
|
|
492 | namedItems = dict([(v[1],k) for (k,vlist) in self.__tokdict.iteritems() | |
|
492 | 493 | for v in vlist ] ) |
|
493 | 494 | nextLevelIndent = indent + " " |
|
494 | 495 | |
@@ -545,7 +546,7 b' class ParseResults(object):' | |||
|
545 | 546 | return "".join(out) |
|
546 | 547 | |
|
547 | 548 | def __lookup(self,sub): |
|
548 | for k,vlist in self.__tokdict.items(): | |
|
549 | for k,vlist in self.__tokdict.iteritems(): | |
|
549 | 550 | for v,loc in vlist: |
|
550 | 551 | if sub is v: |
|
551 | 552 | return k |
@@ -2563,7 +2564,7 b' class Each(ParseExpression):' | |||
|
2563 | 2564 | tmp += ParseResults(r[k]) |
|
2564 | 2565 | dups[k] = tmp |
|
2565 | 2566 | finalResults += ParseResults(r) |
|
2566 | for k,v in dups.items(): | |
|
2567 | for k,v in dups.iteritems(): | |
|
2567 | 2568 | finalResults[k] = v |
|
2568 | 2569 | return loc, finalResults |
|
2569 | 2570 | |
@@ -3442,7 +3443,7 b' def withAttribute(*args,**attrDict):' | |||
|
3442 | 3443 | if args: |
|
3443 | 3444 | attrs = args[:] |
|
3444 | 3445 | else: |
|
3445 | attrs = attrDict.items() | |
|
3446 | attrs = attrDict.iteritems() | |
|
3446 | 3447 | attrs = [(k,v) for k,v in attrs] |
|
3447 | 3448 | def pa(s,l,tokens): |
|
3448 | 3449 | for attrName,attrValue in attrs: |
@@ -617,7 +617,7 b' class WindowsHPCLauncher(BaseLauncher):' | |||
|
617 | 617 | # Twisted will raise DeprecationWarnings if we try to pass unicode to this |
|
618 | 618 | output = yield getProcessOutput(str(self.job_cmd), |
|
619 | 619 | [str(a) for a in args], |
|
620 | env=dict((str(k),str(v)) for k,v in os.environ.items()), | |
|
620 | env=dict((str(k),str(v)) for k,v in os.environ.iteritems()), | |
|
621 | 621 | path=self.work_dir |
|
622 | 622 | ) |
|
623 | 623 | except: |
@@ -59,7 +59,7 b' class PendingDeferredManagerTest(DeferredTestCase):' | |||
|
59 | 59 | did = self.pdm.save_pending_deferred(d) |
|
60 | 60 | dDict[did] = d |
|
61 | 61 | # Make sure they are begin saved |
|
62 | for k in dDict.keys(): | |
|
62 | for k in dDict.iterkeys(): | |
|
63 | 63 | self.assert_(self.pdm.quick_has_id(k)) |
|
64 | 64 | # Get the pending deferred (block=True), then callback with 'foo' and compare |
|
65 | 65 | for did in dDict.keys()[0:5]: |
@@ -212,7 +212,7 b' class WinHPCTask(Configurable):' | |||
|
212 | 212 | |
|
213 | 213 | def get_env_vars(self): |
|
214 | 214 | env_vars = ET.Element('EnvironmentVariables') |
|
215 | for k, v in self.environment_variables.items(): | |
|
215 | for k, v in self.environment_variables.iteritems(): | |
|
216 | 216 | variable = ET.SubElement(env_vars, "Variable") |
|
217 | 217 | name = ET.SubElement(variable, "Name") |
|
218 | 218 | name.text = k |
@@ -22,10 +22,15 b' def import_item(name):' | |||
|
22 | 22 | """Import and return bar given the string foo.bar.""" |
|
23 | 23 | package = '.'.join(name.split('.')[0:-1]) |
|
24 | 24 | obj = name.split('.')[-1] |
|
25 | execString = 'from %s import %s' % (package, obj) | |
|
26 | try: | |
|
27 | exec execString | |
|
28 | except SyntaxError: | |
|
29 | raise ImportError("Invalid class specification: %s" % name) | |
|
30 | exec 'temp = %s' % obj | |
|
31 | return temp | |
|
25 | # execString = 'from %s import %s' % (package, obj) | |
|
26 | # try: | |
|
27 | # exec execString | |
|
28 | # except SyntaxError: | |
|
29 | # raise ImportError("Invalid class specification: %s" % name) | |
|
30 | # exec 'temp = %s' % obj | |
|
31 | # return temp | |
|
32 | if package: | |
|
33 | module = __import__(package,fromlist=[obj]) | |
|
34 | return module.__dict__[obj] | |
|
35 | else: | |
|
36 | return __import__(obj) |
@@ -56,19 +56,7 b' from types import (' | |||
|
56 | 56 | InstanceType, ClassType, FunctionType, |
|
57 | 57 | ListType, TupleType |
|
58 | 58 | ) |
|
59 | ||
|
60 | def import_item(name): | |
|
61 | """Import and return bar given the string foo.bar.""" | |
|
62 | package = '.'.join(name.split('.')[0:-1]) | |
|
63 | obj = name.split('.')[-1] | |
|
64 | execString = 'from %s import %s' % (package, obj) | |
|
65 | try: | |
|
66 | exec execString | |
|
67 | except SyntaxError: | |
|
68 | raise ImportError("Invalid class specification: %s" % name) | |
|
69 | exec 'temp = %s' % obj | |
|
70 | return temp | |
|
71 | ||
|
59 | from .importstring import import_item | |
|
72 | 60 | |
|
73 | 61 | ClassTypes = (ClassType, type) |
|
74 | 62 |
@@ -11,7 +11,7 b' try:' | |||
|
11 | 11 | except ImportError: |
|
12 | 12 | from path import path |
|
13 | 13 | |
|
14 |
import |
|
|
14 | import hashlib, pickle | |
|
15 | 15 | |
|
16 | 16 | def showdiff(old,new): |
|
17 | 17 | import difflib |
@@ -59,23 +59,23 b' def upgrade_dir(srcdir, tgtdir):' | |||
|
59 | 59 | pr("Creating %s" % str(tgt)) |
|
60 | 60 | |
|
61 | 61 | tgt.write_text(src.text()) |
|
62 |
rpt[str(tgt)] = md5 |
|
|
62 | rpt[str(tgt)] = hashlib.md5(tgt.text()).hexdigest() | |
|
63 | 63 | else: |
|
64 | 64 | cont = tgt.text() |
|
65 | 65 | sum = rpt.get(str(tgt), None) |
|
66 | 66 | #print sum |
|
67 |
if sum and md5 |
|
|
67 | if sum and hashlib.md5(cont).hexdigest() == sum: | |
|
68 | 68 | pr("%s: Unedited, installing new version" % tgt) |
|
69 | 69 | tgt.write_text(src.text()) |
|
70 |
rpt[str(tgt)] = md5 |
|
|
70 | rpt[str(tgt)] = hashlib.md5(tgt.text()).hexdigest() | |
|
71 | 71 | else: |
|
72 | 72 | pr(' == Modified, skipping %s, diffs below == ' % tgt) |
|
73 |
#rpt[str(tgt)] = md5 |
|
|
73 | #rpt[str(tgt)] = hashlib.md5(tgt.bytes()).hexdigest() | |
|
74 | 74 | real = showdiff(tgt,src) |
|
75 | 75 | pr('') # empty line |
|
76 | 76 | if not real: |
|
77 | 77 | pr("(Ok, it was identical, only upgrading checksum)") |
|
78 |
rpt[str(tgt)] = md5 |
|
|
78 | rpt[str(tgt)] = hashlib.md5(tgt.text()).hexdigest() | |
|
79 | 79 | else: |
|
80 | 80 | modded.append(tgt) |
|
81 | 81 |
General Comments 0
You need to be logged in to leave comments.
Login now