[pypy-svn] r38630 - in pypy/dist/pypy: interpreter module/__builtin__ module/marshal objspace/std
arigo at codespeak.net
arigo at codespeak.net
Mon Feb 12 20:22:09 CET 2007
Author: arigo
Date: Mon Feb 12 20:22:03 2007
New Revision: 38630
Modified:
pypy/dist/pypy/interpreter/argument.py
pypy/dist/pypy/interpreter/baseobjspace.py
pypy/dist/pypy/interpreter/error.py
pypy/dist/pypy/module/__builtin__/importing.py
pypy/dist/pypy/module/__builtin__/operation.py
pypy/dist/pypy/module/marshal/interp_marshal.py
pypy/dist/pypy/objspace/std/dictmultiobject.py
pypy/dist/pypy/objspace/std/dictobject.py
pypy/dist/pypy/objspace/std/dictstrobject.py
pypy/dist/pypy/objspace/std/marshal_impl.py
pypy/dist/pypy/objspace/std/objecttype.py
pypy/dist/pypy/objspace/std/typeobject.py
pypy/dist/pypy/objspace/std/unicodeobject.py
Log:
Removing most bare "except OperationError:" in PyPy.
Added a space.findattr() helper.
Modified: pypy/dist/pypy/interpreter/argument.py
==============================================================================
--- pypy/dist/pypy/interpreter/argument.py (original)
+++ pypy/dist/pypy/interpreter/argument.py Mon Feb 12 20:22:03 2007
@@ -390,7 +390,9 @@
for w_key in space.unpackiterable(w_starstararg):
try:
key = space.str_w(w_key)
- except OperationError:
+ except OperationError, e:
+ if not e.match(space, space.w_TypeError):
+ raise
raise OperationError(space.w_TypeError,
space.wrap("keywords must be strings"))
if key in d:
Modified: pypy/dist/pypy/interpreter/baseobjspace.py
==============================================================================
--- pypy/dist/pypy/interpreter/baseobjspace.py (original)
+++ pypy/dist/pypy/interpreter/baseobjspace.py Mon Feb 12 20:22:03 2007
@@ -448,6 +448,15 @@
return None
raise
+ def findattr(self, w_object, w_name):
+ try:
+ return self.getattr(w_object, w_name)
+ except OperationError, e:
+ # a PyPy extension: let SystemExit and KeyboardInterrupt go through
+ if e.async(self):
+ raise
+ return None
+
def newbool(self, b):
if b:
return self.w_True
@@ -649,12 +658,15 @@
def abstract_issubclass(self, w_obj, w_cls, failhard=False):
try:
return self.issubtype(w_obj, w_cls)
- except OperationError:
+ except OperationError, e:
+ if not e.match(self, self.w_TypeError):
+ raise
try:
self.getattr(w_cls, self.wrap('__bases__')) # type sanity check
return self.recursive_issubclass(w_obj, w_cls)
- except OperationError:
- if failhard:
+ except OperationError, e:
+ if failhard or not (e.match(self, self.w_TypeError) or
+ e.match(self, self.w_AttributeError)):
raise
else:
return self.w_False
@@ -671,22 +683,25 @@
def abstract_isinstance(self, w_obj, w_cls):
try:
return self.isinstance(w_obj, w_cls)
- except OperationError:
+ except OperationError, e:
+ if not e.match(self, self.w_TypeError):
+ raise
try:
w_objcls = self.getattr(w_obj, self.wrap('__class__'))
return self.abstract_issubclass(w_objcls, w_cls)
- except OperationError:
+ except OperationError, e:
+ if not (e.match(self, self.w_TypeError) or
+ e.match(self, self.w_AttributeError)):
+ raise
return self.w_False
def abstract_isclass(self, w_obj):
if self.is_true(self.isinstance(w_obj, self.w_type)):
return self.w_True
- try:
- self.getattr(w_obj, self.wrap('__bases__'))
- except OperationError:
- return self.w_False
- else:
+ if self.findattr(w_obj, self.wrap('__bases__')) is not None:
return self.w_True
+ else:
+ return self.w_False
def abstract_getclass(self, w_obj):
try:
Modified: pypy/dist/pypy/interpreter/error.py
==============================================================================
--- pypy/dist/pypy/interpreter/error.py (original)
+++ pypy/dist/pypy/interpreter/error.py Mon Feb 12 20:22:03 2007
@@ -37,6 +37,11 @@
"Check if this application-level exception matches 'w_check_class'."
return space.exception_match(self.w_type, w_check_class)
+ def async(self, space):
+ "Check if this is an exception that should better not be caught."
+ return (self.match(space, space.w_SystemExit) or
+ self.match(space, space.w_KeyboardInterrupt))
+
def __str__(self):
"NOT_RPYTHON: Convenience for tracebacks."
return '[%s: %s]' % (self.w_type, self.w_value)
@@ -186,16 +191,11 @@
# things like 'raise 1', but it is probably fine (i.e.
# not ambiguous) to allow them in the explicit form
# 'raise int, 1'
- try:
- space.getattr(w_value, space.wrap('__dict__'))
- except OperationError:
- try:
- space.getattr(w_value, space.wrap('__slots__'))
- except OperationError:
- raise OperationError(space.w_TypeError,
- space.wrap("raising built-in objects can "
- "be ambiguous, "
- "use 'raise type, value' instead"))
+ if (space.findattr(w_value, space.wrap('__dict__')) is None and
+ space.findattr(w_value, space.wrap('__slots__')) is None):
+ msg = ("raising built-in objects can be ambiguous, "
+ "use 'raise type, value' instead")
+ raise OperationError(space.w_TypeError, space.wrap(msg))
self.w_type = w_type
self.w_value = w_value
Modified: pypy/dist/pypy/module/__builtin__/importing.py
==============================================================================
--- pypy/dist/pypy/module/__builtin__/importing.py (original)
+++ pypy/dist/pypy/module/__builtin__/importing.py Mon Feb 12 20:22:03 2007
@@ -404,12 +404,7 @@
the header; if not, return NULL.
Doesn't set an exception.
"""
- try:
- w_marshal = space.getbuiltinmodule('marshal')
- except OperationError:
- #XXX debug
- #print "skipped checking of", cpathname
- return -1
+ w_marshal = space.getbuiltinmodule('marshal')
stream = streamio.open_file_as_stream(cpathname, "rb")
magic = _r_long(stream)
try:
@@ -470,22 +465,13 @@
Errors are ignored, if a write error occurs an attempt is made to
remove the file.
"""
- # see if marshal exists, already.
- # if not, skip the writing.
- try:
- w_marshal = space.getbuiltinmodule('marshal')
- except OperationError:
- # XXX debug
- #print "skipped writing of", cpathname
- return
- else:
- pass
- #XXX debug
- #print "indeed writing", cpathname
+ w_marshal = space.getbuiltinmodule('marshal')
try:
w_str = space.call_method(w_marshal, 'dumps', space.wrap(co))
strbuf = space.str_w(w_str)
- except OperationError:
+ except OperationError, e:
+ if e.async(self):
+ raise
#print "Problem while marshalling %s, skipping" % cpathname
return
#
Modified: pypy/dist/pypy/module/__builtin__/operation.py
==============================================================================
--- pypy/dist/pypy/module/__builtin__/operation.py (original)
+++ pypy/dist/pypy/module/__builtin__/operation.py Mon Feb 12 20:22:03 2007
@@ -60,15 +60,10 @@
"""Return whether the object has an attribute with the given name.
(This is done by calling getattr(object, name) and catching exceptions.)"""
w_name = checkattrname(space, w_name)
- try:
- space.getattr(w_object, w_name)
- except OperationError, e:
- # a PyPy extension: let SystemExit and KeyboardInterrupt go through
- if (e.match(space, space.w_SystemExit) or
- e.match(space, space.w_KeyboardInterrupt)):
- raise
+ if space.findattr(w_object, w_name) is not None:
+ return space.w_True
+ else:
return space.w_False
- return space.w_True
def hash(space, w_object):
"""Return a hash value for the object. Two objects which compare as
Modified: pypy/dist/pypy/module/marshal/interp_marshal.py
==============================================================================
--- pypy/dist/pypy/module/marshal/interp_marshal.py (original)
+++ pypy/dist/pypy/module/marshal/interp_marshal.py Mon Feb 12 20:22:03 2007
@@ -47,7 +47,9 @@
try:
self.func = space.getattr(w_f, space.wrap('write'))
# XXX how to check if it is callable?
- except OperationError:
+ except OperationError, e:
+ if not e.match(space, space.w_AttributeError):
+ raise
raise OperationError(space.w_TypeError, space.wrap(
'marshal.dump() 2nd arg must be file-like object'))
@@ -67,7 +69,9 @@
try:
self.func = space.getattr(w_f, space.wrap('read'))
# XXX how to check if it is callable?
- except OperationError:
+ except OperationError, e:
+ if not e.match(space, space.w_AttributeError):
+ raise
raise OperationError(space.w_TypeError, space.wrap(
'marshal.load() arg must be file-like object'))
@@ -454,7 +458,9 @@
Unmarshaller.__init__(self, space, None)
try:
self.bufstr = space.str_w(w_str)
- except OperationError:
+ except OperationError, e:
+ if not e.match(space, space.w_TypeError):
+ raise
raise OperationError(space.w_TypeError, space.wrap(
'marshal.loads() arg must be string'))
self.bufpos = 0
Modified: pypy/dist/pypy/objspace/std/dictmultiobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/dictmultiobject.py (original)
+++ pypy/dist/pypy/objspace/std/dictmultiobject.py Mon Feb 12 20:22:03 2007
@@ -1033,9 +1033,7 @@
[W_DictMultiObject(space)]) # default argument
# w_dict.implementation = space.emptydictimpl
# ^^^ disabled only for CPython compatibility
- try:
- space.getattr(w_src, space.wrap("keys"))
- except OperationError:
+ if space.findattr(w_src, space.wrap("keys")) is None:
list_of_w_pairs = space.unpackiterable(w_src)
for w_pair in list_of_w_pairs:
pair = space.unpackiterable(w_pair)
Modified: pypy/dist/pypy/objspace/std/dictobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/dictobject.py (original)
+++ pypy/dist/pypy/objspace/std/dictobject.py Mon Feb 12 20:22:03 2007
@@ -52,9 +52,7 @@
(['seq_or_map'], None, 'kwargs'), # signature
[W_DictObject(space)]) # default argument
# w_dict.content.clear() - disabled only for CPython compatibility
- try:
- space.getattr(w_src, space.wrap("keys"))
- except OperationError:
+ if space.findattr(w_src, space.wrap("keys")) is None:
list_of_w_pairs = space.unpackiterable(w_src)
for w_pair in list_of_w_pairs:
pair = space.unpackiterable(w_pair)
Modified: pypy/dist/pypy/objspace/std/dictstrobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/dictstrobject.py (original)
+++ pypy/dist/pypy/objspace/std/dictstrobject.py Mon Feb 12 20:22:03 2007
@@ -109,9 +109,7 @@
#else: -
# w_dict.content.clear() -
- try:
- space.getattr(w_src, space.wrap("keys"))
- except OperationError:
+ if space.findattr(w_src, space.wrap("keys")) is None:
list_of_w_pairs = space.unpackiterable(w_src)
for w_pair in list_of_w_pairs:
pair = space.unpackiterable(w_pair)
Modified: pypy/dist/pypy/objspace/std/marshal_impl.py
==============================================================================
--- pypy/dist/pypy/objspace/std/marshal_impl.py (original)
+++ pypy/dist/pypy/objspace/std/marshal_impl.py Mon Feb 12 20:22:03 2007
@@ -421,8 +421,11 @@
w_obj = u.get_w_obj(False)
try:
return u.space.str_w(w_obj)
- except OperationError:
- u.raise_exc('invalid marshal data for code object')
+ except OperationError, e:
+ if e.match(u.space, u.space.w_TypeError):
+ u.raise_exc('invalid marshal data for code object')
+ else:
+ raise
def unmarshal_strlist(u, tc):
lng = u.atom_lng(tc)
Modified: pypy/dist/pypy/objspace/std/objecttype.py
==============================================================================
--- pypy/dist/pypy/objspace/std/objecttype.py (original)
+++ pypy/dist/pypy/objspace/std/objecttype.py Mon Feb 12 20:22:03 2007
@@ -59,9 +59,8 @@
def descr__reduce_ex__(space, w_obj, proto=0):
w_st_reduce = space.wrap('__reduce__')
- try: w_reduce = space.getattr(w_obj, w_st_reduce)
- except OperationError: pass
- else:
+ w_reduce = space.findattr(w_obj, w_st_reduce)
+ if w_reduce is not None:
w_cls = space.getattr(w_obj, space.wrap('__class__'))
w_cls_reduce_meth = space.getattr(w_cls, w_st_reduce)
w_cls_reduce = space.getattr(w_cls_reduce_meth, space.wrap('im_func'))
Modified: pypy/dist/pypy/objspace/std/typeobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/typeobject.py (original)
+++ pypy/dist/pypy/objspace/std/typeobject.py Mon Feb 12 20:22:03 2007
@@ -81,11 +81,8 @@
else:
w_globals = caller.w_globals
w_str_name = space.wrap('__name__')
- try:
- w_name = space.getitem(w_globals, w_str_name)
- except OperationError:
- pass
- else:
+ w_name = space.finditem(w_globals, w_str_name)
+ if w_name is not None:
dict_w['__module__'] = w_name
# find the most specific typedef
instancetypedef = object_typedef
Modified: pypy/dist/pypy/objspace/std/unicodeobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/unicodeobject.py (original)
+++ pypy/dist/pypy/objspace/std/unicodeobject.py Mon Feb 12 20:22:03 2007
@@ -502,9 +502,12 @@
def _to_unichar_w(space, w_char):
try:
w_unichar = unicodetype.unicode_from_object(space, w_char)
- except OperationError:
- # XXX don't completely eat this exception
- raise OperationError(space.w_TypeError, space.wrap('The fill character cannot be converted to Unicode'))
+ except OperationError, e:
+ if e.match(space, space.w_TypeError):
+ msg = 'The fill character cannot be converted to Unicode'
+ raise OperationError(space.w_TypeError, space.wrap(msg))
+ else:
+ raise
if space.int_w(space.len(w_unichar)) != 1:
raise OperationError(space.w_TypeError, space.wrap('The fill character must be exactly one character long'))
More information about the Pypy-commit
mailing list