diff --git a/IPython/core/prefilter.py b/IPython/core/prefilter.py index e427091..9b5d12a 100755 --- a/IPython/core/prefilter.py +++ b/IPython/core/prefilter.py @@ -237,7 +237,7 @@ class PrefilterManager(Configurable): This must be called after the priority of a transformer is changed. The :meth:`register_transformer` method calls this automatically. """ - self._transformers.sort(cmp=lambda x,y: x.priority-y.priority) + self._transformers.sort(key=lambda x: x.priority) @property def transformers(self): @@ -273,7 +273,7 @@ class PrefilterManager(Configurable): This must be called after the priority of a checker is changed. The :meth:`register_checker` method calls this automatically. """ - self._checkers.sort(cmp=lambda x,y: x.priority-y.priority) + self._checkers.sort(key=lambda x: x.priority) @property def checkers(self): diff --git a/IPython/external/Itpl.py b/IPython/external/Itpl.py index 3423fe4..ea98172 100644 --- a/IPython/external/Itpl.py +++ b/IPython/external/Itpl.py @@ -78,7 +78,6 @@ __license__ = 'MIT' import string import sys from tokenize import tokenprog -from types import StringType class ItplError(ValueError): def __init__(self, text, pos): @@ -144,7 +143,7 @@ class Itpl: pos = 0 while 1: - dollar = string.find(format, "$", pos) + dollar = format.find("$", pos) if dollar < 0: break nextchar = format[dollar+1] diff --git a/IPython/external/path.py b/IPython/external/path.py index 6b0f952..4abe32d 100644 --- a/IPython/external/path.py +++ b/IPython/external/path.py @@ -7,7 +7,7 @@ d = path('/home/guido/bin') for f in d.files('*.py'): f.chmod(0755) -This module requires Python 2.2 or later. +This module requires Python 2.5 or later. URL: http://www.jorendorff.com/articles/python/path @@ -30,9 +30,7 @@ Date: 9 Mar 2007 from __future__ import generators import sys, warnings, os, fnmatch, glob, shutil, codecs -# deprecated in python 2.6 -warnings.filterwarnings('ignore', r'.*md5.*') -import md5 +from hashlib import md5 __version__ = '2.2' __all__ = ['path'] @@ -49,38 +47,11 @@ else: except ImportError: pwd = None -# Pre-2.3 support. Are unicode filenames supported? -_base = str -_getcwd = os.getcwd -try: - if os.path.supports_unicode_filenames: - _base = unicode - _getcwd = os.getcwdu -except AttributeError: - pass - -# Pre-2.3 workaround for booleans -try: - True, False -except NameError: - True, False = 1, 0 - -# Pre-2.3 workaround for basestring. -try: - basestring -except NameError: - basestring = (str, unicode) - -# Universal newline support -_textmode = 'r' -if hasattr(file, 'newlines'): - _textmode = 'U' - class TreeWalkWarning(Warning): pass -class path(_base): +class path(unicode): """ Represents a filesystem path. For documentation on individual methods, consult their @@ -90,12 +61,12 @@ class path(_base): # --- Special Python methods. def __repr__(self): - return 'path(%s)' % _base.__repr__(self) + return 'path(%s)' % unicode.__repr__(self) # Adding a path and a string yields a path. def __add__(self, more): try: - resultStr = _base.__add__(self, more) + resultStr = unicode.__add__(self, more) except TypeError: #Python bug resultStr = NotImplemented if resultStr is NotImplemented: @@ -122,7 +93,7 @@ class path(_base): def getcwd(cls): """ Return the current working directory as a path object. """ - return cls(_getcwd()) + return cls(os.getcwdu()) getcwd = classmethod(getcwd) @@ -152,7 +123,7 @@ class path(_base): return base def _get_ext(self): - f, ext = os.path.splitext(_base(self)) + f, ext = os.path.splitext(unicode(self)) return ext def _get_drive(self): @@ -513,14 +484,14 @@ class path(_base): of all the files users have in their bin directories. """ cls = self.__class__ - return [cls(s) for s in glob.glob(_base(self / pattern))] + return [cls(s) for s in glob.glob(unicode(self / pattern))] # --- Reading or writing an entire file at once. def open(self, mode='r'): """ Open this file. Return a file object. """ - return file(self, mode) + return open(self, mode) def bytes(self): """ Open this file, read all bytes, return them as a string. """ @@ -563,7 +534,7 @@ class path(_base): """ if encoding is None: # 8-bit - f = self.open(_textmode) + f = self.open('U') try: return f.read() finally: @@ -690,7 +661,7 @@ class path(_base): This uses 'U' mode in Python 2.3 and later. """ if encoding is None and retain: - f = self.open(_textmode) + f = self.open('U') try: return f.readlines() finally: @@ -770,7 +741,7 @@ class path(_base): """ f = self.open('rb') try: - m = md5.new() + m = md5() while True: d = f.read(8192) if not d: diff --git a/IPython/utils/importstring.py b/IPython/utils/importstring.py index 63f08e8..cbb6101 100644 --- a/IPython/utils/importstring.py +++ b/IPython/utils/importstring.py @@ -22,10 +22,15 @@ def import_item(name): """Import and return bar given the string foo.bar.""" package = '.'.join(name.split('.')[0:-1]) obj = name.split('.')[-1] - execString = 'from %s import %s' % (package, obj) - try: - exec execString - except SyntaxError: - raise ImportError("Invalid class specification: %s" % name) - exec 'temp = %s' % obj - return temp +# execString = 'from %s import %s' % (package, obj) +# try: +# exec execString +# except SyntaxError: +# raise ImportError("Invalid class specification: %s" % name) +# exec 'temp = %s' % obj +# return temp + if package: + module = __import__(package,fromlist=[obj]) + return module.__dict__[obj] + else: + return __import__(obj) diff --git a/IPython/utils/traitlets.py b/IPython/utils/traitlets.py index 4c7b3f8..39c8570 100644 --- a/IPython/utils/traitlets.py +++ b/IPython/utils/traitlets.py @@ -56,19 +56,7 @@ from types import ( InstanceType, ClassType, FunctionType, ListType, TupleType ) - -def import_item(name): - """Import and return bar given the string foo.bar.""" - package = '.'.join(name.split('.')[0:-1]) - obj = name.split('.')[-1] - execString = 'from %s import %s' % (package, obj) - try: - exec execString - except SyntaxError: - raise ImportError("Invalid class specification: %s" % name) - exec 'temp = %s' % obj - return temp - +from .importstring import import_item ClassTypes = (ClassType, type)