Author: Ronny Pfannschmidt <[email protected]>
Branch: py3ksupport
Changeset: r148:9fd2a470fd2a
Date: 2011-10-19 22:37 +0200
http://bitbucket.org/pypy/pyrepl/changeset/9fd2a470fd2a/
Log: tonns of python3 fixes in various files, normal usage is still fine
diff --git a/pyrepl/cmdrepl.py b/pyrepl/cmdrepl.py
--- a/pyrepl/cmdrepl.py
+++ b/pyrepl/cmdrepl.py
@@ -33,7 +33,7 @@
which is in fact done by the `pythoni' script that comes with
pyrepl."""
-from __future__ import nested_scopes
+from __future__ import print_function
from pyrepl import completing_reader as cr, reader, completer
from pyrepl.completing_reader import CompletingReader as CR
@@ -96,7 +96,7 @@
if intro is not None:
self.intro = intro
if self.intro:
- print self.intro
+ print(self.intro)
stop = None
while not stop:
if self.cmdqueue:
diff --git a/pyrepl/completer.py b/pyrepl/completer.py
--- a/pyrepl/completer.py
+++ b/pyrepl/completer.py
@@ -17,7 +17,10 @@
# CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-import __builtin__
+try:
+ import __builtin__ as builtins
+except ImportError:
+ import builtins
class Completer:
def __init__(self, ns):
@@ -38,12 +41,11 @@
"""
import keyword
matches = []
- n = len(text)
for list in [keyword.kwlist,
- __builtin__.__dict__.keys(),
+ builtins.__dict__.keys(),
self.ns.keys()]:
for word in list:
- if word[:n] == text and word != "__builtins__":
+ if word.startswith(text) and word != "__builtins__":
matches.append(word)
return matches
diff --git a/pyrepl/completing_reader.py b/pyrepl/completing_reader.py
--- a/pyrepl/completing_reader.py
+++ b/pyrepl/completing_reader.py
@@ -168,7 +168,7 @@
r.insert(completions[0][len(stem):])
else:
p = prefix(completions, len(stem))
- if p <> '':
+ if p:
r.insert(p)
if r.last_command_is(self.__class__):
if not r.cmpltn_menu_vis:
@@ -259,7 +259,7 @@
p = self.pos - 1
while p >= 0 and st.get(b[p], SW) == SW:
p -= 1
- return u''.join(b[p+1:self.pos])
+ return ''.join(b[p+1:self.pos])
def get_completions(self, stem):
return []
diff --git a/pyrepl/copy_code.py b/pyrepl/copy_code.py
--- a/pyrepl/copy_code.py
+++ b/pyrepl/copy_code.py
@@ -17,7 +17,7 @@
# CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-import new
+from types import CodeType
def copy_code_with_changes(codeobject,
argcount=None,
@@ -44,7 +44,7 @@
if name is None: name = codeobject.co_name
if firstlineno is None: firstlineno = codeobject.co_firstlineno
if lnotab is None: lnotab = codeobject.co_lnotab
- return new.code(argcount,
+ return CodeType(argcount,
nlocals,
stacksize,
flags,
diff --git a/pyrepl/historical_reader.py b/pyrepl/historical_reader.py
--- a/pyrepl/historical_reader.py
+++ b/pyrepl/historical_reader.py
@@ -33,7 +33,8 @@
(r'\C-g', 'isearch-cancel'),
(r'\<backspace>', 'isearch-backspace')])
-del c
+if 'c' in globals():
+ del c
ISEARCH_DIRECTION_NONE = ''
ISEARCH_DIRECTION_BACKWARDS = 'r'
@@ -230,7 +231,7 @@
self.dirty = 1
def get_item(self, i):
- if i <> len(self.history):
+ if i != len(self.history):
return self.transient_history.get(i, self.history[i])
else:
return self.transient_history.get(i, self.get_unicode())
@@ -253,7 +254,7 @@
raise
def get_prompt(self, lineno, cursor_on_line):
- if cursor_on_line and self.isearch_direction <> ISEARCH_DIRECTION_NONE:
+ if cursor_on_line and self.isearch_direction != ISEARCH_DIRECTION_NONE:
d = 'rf'[self.isearch_direction == ISEARCH_DIRECTION_FORWARDS]
return "(%s-search `%s') "%(d, self.isearch_term)
else:
diff --git a/pyrepl/module_lister.py b/pyrepl/module_lister.py
--- a/pyrepl/module_lister.py
+++ b/pyrepl/module_lister.py
@@ -66,5 +66,5 @@
try:
mods = _packages[pack]
except KeyError:
- raise ImportError, "can't find \"%s\" package"%pack
+ raise ImportError("can't find \"%s\" package" % pack)
return [mod for mod in mods if mod.startswith(stem)]
diff --git a/pyrepl/python_reader.py b/pyrepl/python_reader.py
--- a/pyrepl/python_reader.py
+++ b/pyrepl/python_reader.py
@@ -20,12 +20,13 @@
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
# one impressive collections of imports:
+from __future__ import print_function
from pyrepl.completing_reader import CompletingReader
from pyrepl.historical_reader import HistoricalReader
from pyrepl import completing_reader, reader
from pyrepl import copy_code, commands, completer
from pyrepl import module_lister
-import new, sys, os, re, code, traceback
+import imp, sys, os, re, code, traceback
import atexit, warnings
try:
import cPickle as pickle
@@ -47,6 +48,21 @@
"""this function eats warnings, if you were wondering"""
pass
+if sys.version_info >= (3,0):
+ def _reraise(cls, val, tb):
+ __tracebackhide__ = True
+ assert hasattr(val, '__traceback__')
+ raise val
+else:
+ exec ("""
+def _reraise(cls, val, tb):
+ __tracebackhide__ = True
+ raise cls, val, tb
+""")
+
+
+
+
class maybe_accept(commands.Command):
def do(self):
r = self.reader
@@ -192,7 +208,7 @@
finally:
warnings.showwarning = sv
except KeyboardInterrupt:
- print "KeyboardInterrupt"
+ print("KeyboardInterrupt")
else:
if l:
self.execute(l)
@@ -217,7 +233,7 @@
r = self.reader.handle1(block)
except KeyboardInterrupt:
self.restore()
- print "KeyboardInterrupt"
+ print("KeyboardInterrupt")
self.prepare()
else:
if self.reader.finished:
@@ -253,7 +269,7 @@
if self.exc_info:
type, value, tb = self.exc_info
self.exc_info = None
- raise type, value, tb
+ _reraise(type, value, tb)
def tkinteract(self):
"""Run a Tk-aware Python interactive session.
@@ -370,13 +386,13 @@
encoding = None # so you get ASCII...
con = UnixConsole(0, 1, None, encoding)
if print_banner:
- print "Python", sys.version, "on", sys.platform
- print 'Type "help", "copyright", "credits" or "license" '\
- 'for more information.'
+ print("Python", sys.version, "on", sys.platform)
+ print('Type "help", "copyright", "credits" or "license" '\
+ 'for more information.')
sys.path.insert(0, os.getcwd())
if clear_main and __name__ != '__main__':
- mainmod = new.module('__main__')
+ mainmod = imp.new_module('__main__')
sys.modules['__main__'] = mainmod
else:
mainmod = sys.modules['__main__']
diff --git a/pyrepl/reader.py b/pyrepl/reader.py
--- a/pyrepl/reader.py
+++ b/pyrepl/reader.py
@@ -529,6 +529,8 @@
commands.invalid_command)(self, *cmd)
elif isinstance(cmd[0], type):
cmd = cmd[0](self, cmd)
+ else:
+ return # nothing to do
cmd.do()
diff --git a/pyrepl/unix_console.py b/pyrepl/unix_console.py
--- a/pyrepl/unix_console.py
+++ b/pyrepl/unix_console.py
@@ -41,8 +41,8 @@
def _my_getstr(cap, optional=0):
r = curses.tigetstr(cap)
if not optional and r is None:
- raise InvalidTerminal, \
- "terminal doesn't have the required '%s' capability"%cap
+ raise InvalidTerminal(
+ "terminal doesn't have the required '%s' capability"%cap)
return r
# at this point, can we say: AAAAAAAAAAAAAAAAAAAAAARGH!
@@ -131,14 +131,14 @@
elif self._cub1 and self._cuf1:
self.__move_x = self.__move_x_cub1_cuf1
else:
- raise RuntimeError, "insufficient terminal (horizontal)"
+ raise RuntimeError("insufficient terminal (horizontal)")
if self._cuu and self._cud:
self.__move_y = self.__move_y_cuu_cud
elif self._cuu1 and self._cud1:
self.__move_y = self.__move_y_cuu1_cud1
else:
- raise RuntimeError, "insufficient terminal (vertical)"
+ raise RuntimeError("insufficient terminal (vertical)")
if self._dch1:
self.dch1 = self._dch1
@@ -163,9 +163,9 @@
def change_encoding(self, encoding):
self.encoding = encoding
- def refresh(self, screen, (cx, cy)):
+ def refresh(self, screen, c_xy):
# this function is still too long (over 90 lines)
-
+ cx, cy = c_xy
if not self.__gone_tall:
while len(self.screen) < min(len(screen), self.height):
self.__hide_cursor()
@@ -406,7 +406,7 @@
self.partial_char += char
try:
c = unicode(self.partial_char, self.encoding)
- except UnicodeError, e:
+ except UnicodeError as e:
if len(e.args) > 4 and \
e.args[4] == 'unexpected end of data':
pass
@@ -421,7 +421,7 @@
while 1: # All hail Unix!
try:
self.push_char(os.read(self.input_fd, 1))
- except (IOError, OSError), err:
+ except (IOError, OSError) as err:
if err.errno == errno.EINTR:
if not self.event_queue.empty():
return self.event_queue.get()
diff --git a/tox.ini b/tox.ini
--- a/tox.ini
+++ b/tox.ini
@@ -2,6 +2,8 @@
envlist= py27, py32
[testenv]
-deps=pytest
+deps=
+ pytest
+ pexpect
commands=
py.test --junitxml={envdir}/junit.xml []
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit