Author: Amaury Forgeot d'Arc <[email protected]>
Branch: py3k
Changeset: r48893:239bf4fc877d
Date: 2011-11-08 01:04 +0100
http://bitbucket.org/pypy/pypy/changeset/239bf4fc877d/
Log: Implement IOBase._checkClosed(), will maybe fix test_fptlib and
test_poplib.
diff --git a/lib_pypy/pyrepl/input.py b/lib_pypy/pyrepl/input.py
--- a/lib_pypy/pyrepl/input.py
+++ b/lib_pypy/pyrepl/input.py
@@ -56,24 +56,24 @@
keyseq = tuple(parse_keys(keyspec))
d[keyseq] = command
if self.verbose:
- print d
+ print(d)
self.k = self.ck = compile_keymap(d, ())
self.results = []
self.stack = []
def push(self, evt):
if self.verbose:
- print "pushed", evt.data,
+ print("pushed", evt.data, end='')
key = evt.data
d = self.k.get(key)
if isinstance(d, dict):
if self.verbose:
- print "transition"
+ print("transition")
self.stack.append(key)
self.k = d
else:
if d is None:
if self.verbose:
- print "invalid"
+ print("invalid")
if self.stack or len(key) > 1 or unicodedata_.category(key) ==
'C':
self.results.append(
(self.invalid_cls, self.stack + [key]))
@@ -84,7 +84,7 @@
(self.character_cls, [key]))
else:
if self.verbose:
- print "matched", d
+ print("matched", d)
self.results.append((d, self.stack + [key]))
self.stack = []
self.k = self.ck
diff --git a/lib_pypy/pyrepl/keymap.py b/lib_pypy/pyrepl/keymap.py
--- a/lib_pypy/pyrepl/keymap.py
+++ b/lib_pypy/pyrepl/keymap.py
@@ -106,22 +106,22 @@
s += 2
elif c == "c":
if key[s + 2] != '-':
- raise KeySpecError, \
+ raise KeySpecError(
"\\C must be followed by `-' (char %d of %s)"%(
- s + 2, repr(key))
+ s + 2, repr(key)))
if ctrl:
- raise KeySpecError, "doubled \\C- (char %d of %s)"%(
- s + 1, repr(key))
+ raise KeySpecError("doubled \\C- (char %d of %s)"%(
+ s + 1, repr(key)))
ctrl = 1
s += 3
elif c == "m":
if key[s + 2] != '-':
- raise KeySpecError, \
+ raise KeySpecError(
"\\M must be followed by `-' (char %d of %s)"%(
- s + 2, repr(key))
+ s + 2, repr(key)))
if meta:
- raise KeySpecError, "doubled \\M- (char %d of %s)"%(
- s + 1, repr(key))
+ raise KeySpecError("doubled \\M- (char %d of %s)"%(
+ s + 1, repr(key)))
meta = 1
s += 3
elif c.isdigit():
@@ -135,26 +135,26 @@
elif c == '<':
t = key.find('>', s)
if t == -1:
- raise KeySpecError, \
+ raise KeySpecError(
"unterminated \\< starting at char %d of %s"%(
- s + 1, repr(key))
+ s + 1, repr(key)))
ret = key[s+2:t].lower()
if ret not in _keynames:
- raise KeySpecError, \
+ raise KeySpecError(
"unrecognised keyname `%s' at char %d of %s"%(
- ret, s + 2, repr(key))
+ ret, s + 2, repr(key)))
ret = _keynames[ret]
s = t + 1
else:
- raise KeySpecError, \
+ raise KeySpecError(
"unknown backslash escape %s at char %d of %s"%(
- `c`, s + 2, repr(key))
+ repr(c), s + 2, repr(key)))
else:
ret = key[s]
s += 1
if ctrl:
if len(ret) > 1:
- raise KeySpecError, "\\C- must be followed by a character"
+ raise KeySpecError("\\C- must be followed by a character")
ret = chr(ord(ret) & 0x1f) # curses.ascii.ctrl()
if meta:
ret = ['\033', ret]
@@ -177,8 +177,8 @@
for key, value in r.items():
if empty in value:
if len(value) <> 1:
- raise KeySpecError, \
- "key definitions for %s clash"%(value.values(),)
+ raise KeySpecError(
+ "key definitions for %s clash"%(value.values(),))
else:
r[key] = value[empty]
else:
diff --git a/lib_pypy/pyrepl/reader.py b/lib_pypy/pyrepl/reader.py
--- a/lib_pypy/pyrepl/reader.py
+++ b/lib_pypy/pyrepl/reader.py
@@ -26,17 +26,17 @@
def _make_unctrl_map():
uc_map = {}
- for c in map(unichr, range(256)):
+ for c in map(chr, range(256)):
if unicodedata_.category(c)[0] <> 'C':
uc_map[c] = c
for i in range(32):
- c = unichr(i)
- uc_map[c] = u'^' + unichr(ord('A') + i - 1)
+ c = chr(i)
+ uc_map[c] = u'^' + chr(ord('A') + i - 1)
uc_map['\t'] = ' ' # display TABs as 4 characters
uc_map['\177'] = u'^?'
for i in range(256):
- c = unichr(i)
- if not uc_map.has_key(c):
+ c = chr(i)
+ if c not in uc_map:
uc_map[c] = u'\\%03o'%i
return uc_map
@@ -56,7 +56,7 @@
return u[c]
else:
if unicodedata_.category(c).startswith('C'):
- return '\u%04x'%(ord(c),)
+ return '\\u%04x'%(ord(c),)
else:
return c
diff --git a/lib_pypy/pyrepl/unix_console.py b/lib_pypy/pyrepl/unix_console.py
--- a/lib_pypy/pyrepl/unix_console.py
+++ b/lib_pypy/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
diff --git a/lib_pypy/pyrepl/unix_eventqueue.py
b/lib_pypy/pyrepl/unix_eventqueue.py
--- a/lib_pypy/pyrepl/unix_eventqueue.py
+++ b/lib_pypy/pyrepl/unix_eventqueue.py
@@ -52,7 +52,7 @@
for key, tiname in _keynames.items():
keycode = curses.tigetstr(tiname)
if keycode:
- our_keycodes[keycode] = unicode(key)
+ our_keycodes[keycode] = str(key)
if os.isatty(fd):
our_keycodes[tcgetattr(fd)[6][VERASE]] = u'backspace'
self.k = self.ck = keymap.compile_keymap(our_keycodes)
diff --git a/pypy/module/_io/interp_iobase.py b/pypy/module/_io/interp_iobase.py
--- a/pypy/module/_io/interp_iobase.py
+++ b/pypy/module/_io/interp_iobase.py
@@ -88,6 +88,9 @@
raise OperationError(
space.w_ValueError, space.wrap(message))
+ def check_closed_w(self, space):
+ self._check_closed(space)
+
def closed_get_w(self, space):
return space.newbool(self.__IOBase_closed)
@@ -253,6 +256,7 @@
_checkWritable = interp2app(check_writable_w),
_checkSeekable = interp2app(check_seekable_w),
closed = GetSetProperty(W_IOBase.closed_get_w),
+ _checkClosed = interp2app(W_IOBase.check_closed_w),
__dict__ = GetSetProperty(descr_get_dict, descr_set_dict, cls=W_IOBase),
__weakref__ = make_weakref_descr(W_IOBase),
diff --git a/pypy/module/_io/test/test_io.py b/pypy/module/_io/test/test_io.py
--- a/pypy/module/_io/test/test_io.py
+++ b/pypy/module/_io/test/test_io.py
@@ -24,7 +24,9 @@
import io
with io.BufferedIOBase() as f:
assert not f.closed
+ f._checkClosed()
assert f.closed
+ raises(ValueError, f._checkClosed)
def test_iter(self):
import io
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit