Example #1
0
 def setattr(self, space, attr, w_value):
     # XXX kill me?  This is mostly to make tests happy, raising
     # a TypeError instead of an AttributeError and using "readonly"
     # instead of "read-only" in the error message :-/
     if attr in ["__doc__", "fget", "fset", "fdel"]:
         raise operationerrfmt(space.w_TypeError,
             "Trying to set readonly attribute %s on property", attr)
     return space.call_function(object_setattr(space),
                                space.wrap(self), space.wrap(attr), w_value)
Example #2
0
 def setattr(self, space, attr, w_value):
     # XXX kill me?  This is mostly to make tests happy, raising
     # a TypeError instead of an AttributeError and using "readonly"
     # instead of "read-only" in the error message :-/
     if attr in ["__doc__", "fget", "fset", "fdel"]:
         raise operationerrfmt(
             space.w_TypeError,
             "Trying to set readonly attribute %s on property", attr)
     return space.call_function(object_setattr(space), space.wrap(self),
                                space.wrap(attr), w_value)
Example #3
0
    def setattr(self, space, name, w_value):
        if name == "namespace_prefixes":
            XML_SetReturnNSTriplet(self.itself, space.int_w(w_value))
            return

        for handler_name, (index, setter, handler) in ENUMERATE_SETTERS:
            if name == handler_name:
                return self.sethandler(space, handler_name, w_value, index,
                                       setter, handler)

        # fallback to object.__setattr__()
        return space.call_function(object_setattr(space), space.wrap(self),
                                   space.wrap(name), w_value)
Example #4
0
    def setattr(self, space, name, w_value):
        if name == "namespace_prefixes":
            XML_SetReturnNSTriplet(self.itself, space.int_w(w_value))
            return

        for handler_name, (index, setter, handler) in ENUMERATE_SETTERS:
            if name == handler_name:
                return self.sethandler(space, handler_name, w_value,
                                       index, setter, handler)

        # fallback to object.__setattr__()
        return space.call_function(
            object_setattr(space),
            space.wrap(self), space.wrap(name), w_value)
Example #5
0
def PyObject_GenericSetAttr(space, w_obj, w_name, w_value):
    """Generic attribute setter function that is meant to be put into a type
    object's tp_setattro slot.  It looks for a data descriptor in the
    dictionary of classes in the object's MRO, and if found it takes preference
    over setting the attribute in the instance dictionary. Otherwise, the
    attribute is set in the object's __dict__ (if present).  Otherwise,
    an AttributeError is raised and -1 is returned."""
    from pypy.objspace.descroperation import object_setattr, object_delattr
    if w_value is not None:
        w_descr = object_setattr(space)
        space.get_and_call_function(w_descr, w_obj, w_name, w_value)
    else:
        w_descr = object_delattr(space)
        space.get_and_call_function(w_descr, w_obj, w_name)
    return 0
Example #6
0
def PyObject_GenericSetAttr(space, w_obj, w_name, w_value):
    """Generic attribute setter function that is meant to be put into a type
    object's tp_setattro slot.  It looks for a data descriptor in the
    dictionary of classes in the object's MRO, and if found it takes preference
    over setting the attribute in the instance dictionary. Otherwise, the
    attribute is set in the object's __dict__ (if present).  Otherwise,
    an AttributeError is raised and -1 is returned."""
    from pypy.objspace.descroperation import object_setattr, object_delattr
    if w_value is not None:
        w_descr = object_setattr(space)
        space.get_and_call_function(w_descr, w_obj, w_name, w_value)
    else:
        w_descr = object_delattr(space)
        space.get_and_call_function(w_descr, w_obj, w_name)
    return 0