Esempio n. 1
0
PyObject *call_setattr(const char *type, PyObject *self, PyObject *name_object, PyObject *value)
{
	const char *name = NULL;
	if (!(name = PyString_AsString(name_object))) return NULL;

	setattr_table::const_iterator position = all_setattr.find(type);
	if (position == all_setattr.end())
	return (PyObject_GenericSetAttr(self, name_object, value) == 0)? Py_BuildValue("") : NULL;

	setattr_map::const_iterator function = position->second.find(name);
	if (function == position->second.end())
	return (PyObject_GenericSetAttr(self, name_object, value) == 0)? Py_BuildValue("") : NULL;

	return (*function->second)(self, name_object, value);
}
Esempio n. 2
0
/** 
 * @brief Implements attribute set operation.
 */
int py_axl_doc_set_attr (PyObject *o, PyObject *attr_name, PyObject *v)
{
	const char      * attr    = NULL;
	PyAxlDoc        * self    = (PyAxlDoc *) o; 
	PyObject        * py_node = NULL;

	/* now implement other attributes */
	if (! PyArg_Parse (attr_name, "s", &attr))
		return -1;

	if (axl_cmp (attr, "root")) {
		if (! PyArg_Parse (v, "O", &py_node))
			return -1;

		/* configure the node */
		axl_doc_set_root (self->doc, py_axl_node_get (py_node));

		/* set the node to not dealloc internal node */
		py_axl_node_set_dealloc (py_node, axl_false);

		return 0;
	}

	/* now implement generic setter */
	return PyObject_GenericSetAttr (o, attr_name, v);
}
static int conflict_setattr(conflict *self, PyObject *attr_name, PyObject *value) {
    // Check and make sure we have a string as attribute name...
    if (PyUnicode_Check(attr_name)) {
        PY_SCIP_SET_PRIORITY(SCIPconflicthdlrSetPriority, self->conflict);
    }
    return PyObject_GenericSetAttr((PyObject *) self, attr_name, value);
}
int PyDSOP_SCOPE_INIT_INFO::setattro(PyObject *self, PyObject *obname, PyObject *val)
{
	PyDSOP_SCOPE_INIT_INFO *p = (PyDSOP_SCOPE_INIT_INFO *)self;
	DSOP_SCOPE_INIT_INFO *pssi = p->owner->pScopes + p->index;
	char *name=PyString_AsString(obname);
	PyErr_Clear();
	if (strcmp(name, "type")==0) {
		pssi->flType = PyInt_AsLong(val);
		if (PyErr_Occurred()) return -1;
	}
	else if (strcmp(name, "scope")==0) {
		pssi->flScope = PyInt_AsLong(val);
		if (PyErr_Occurred()) return -1;
	}
	else if (strcmp(name, "scope")==0) {
		pssi->hr = PyInt_AsLong(val);
		if (PyErr_Occurred()) return -1;
	}
	else if (strcmp(name, "dcName")==0) {
		WCHAR *buf;
		if (!PyWinObject_AsWCHAR(val, &buf, TRUE))
			return -1;
		PyWinObject_FreeWCHAR((WCHAR *)pssi->pwzDcName);
		pssi->pwzDcName = buf;
	}
	else if (strcmp(name, "filterFlags")==0) {
		PyErr_SetString(PyExc_AttributeError, "filterFlags attribute can not be set (try setting attributes on the object itself)");
		return -1;
	}
	else {
		return PyObject_GenericSetAttr(self, obname, val);
	}
	return 0;
}
Esempio n. 5
0
static int
Per_p_set_or_delattro(cPersistentObject *self, PyObject *name, PyObject *v)
{
    int result = -1;    /* guilty until proved innocent */
    PyObject *converted;
    char *s;

    converted = convert_name(name);
    if (!converted)
        goto Done;
    s = PyBytes_AS_STRING(converted);

    if (strncmp(s, "_p_", 3))
    {
        if (unghostify(self) < 0)
            goto Done;
        accessed(self);

        result = 0;
    }
    else
    {
        if (PyObject_GenericSetAttr((PyObject *)self, name, v) < 0)
            goto Done;
        result = 1;
    }

Done:
  Py_XDECREF(converted);
  return result;
}
Esempio n. 6
0
static int
Per_setattro(cPersistentObject *self, PyObject *name, PyObject *v)
{
    int result = -1;    /* guilty until proved innocent */
    PyObject *converted;
    char *s;

    converted = convert_name(name);
    if (!converted)
        goto Done;
    s = PyBytes_AS_STRING(converted);

    if (strncmp(s, "_p_", 3) != 0)
    {
        if (unghostify(self) < 0)
            goto Done;
        accessed(self);
        if (strncmp(s, "_v_", 3) != 0
            && self->state != cPersistent_CHANGED_STATE)
            {
            if (changed(self) < 0)
                goto Done;
            }
    }
    result = PyObject_GenericSetAttr((PyObject *)self, name, v);

Done:
    Py_XDECREF(converted);
    return result;
}
Esempio n. 7
0
static int Enum_setattro(PyObject *self, PyObject *attr_name, PyObject *value)
{
    if (!PyString_Check(attr_name))
    {
        PyErr_SetString(PyExc_TypeError, "setattro expects a string argument");
        return -1;;
    }
    Enum *theEnum = (Enum*)self;
    PyObject *item = PyDict_GetItem(theEnum->lookup, attr_name);
    if (!item)
    {
        PyErr_Clear(); // wasn't in the dictionary, check to see if they want the values or lookup dict
        char *name = PyString_AsString(attr_name);
        if (strcmp(name, "values") == 0)
        {
            PyErr_SetString(PyExc_RuntimeError, "Cannot set the value attribute");
            return -1;
        }
        else if (strcmp(name, "lookup") == 0)
        {
            PyErr_SetString(PyExc_RuntimeError, "Cannot set the lookup attribute");
            return -1;
        }
        else if (strcmp(name, "reverseLookup") == 0)
        {
            PyErr_SetString(PyExc_RuntimeError, "Cannot set the reverseLookup attribute");
            return -1;
        }
        // they aren't trying to set an enum value or any of our special values, so let them
        return PyObject_GenericSetAttr(self, attr_name, value); // let the default method handle it
    }
    PyErr_SetString(PyExc_RuntimeError, "Cannot set any enum value");
    return -1;
}
Esempio n. 8
0
static int mech_setattro(NPyMechObj* self, PyObject* name, PyObject* value) {
	int err = 0;
	Py_INCREF(name);
	char* n = PyString_AsString(name);
//printf("mech_setattro %s\n", n);
	NrnProperty np(self->prop_);	
	char buf[200];
	sprintf(buf, "%s_%s", n, memb_func[self->prop_->type].sym->name);
	Symbol* sym = np.find(buf);
	if (sym) {
		double x;
		if (PyArg_Parse(value, "d", &x) == 1) {
			double* pd = np.prop_pval(sym, 0);
			if (pd) {
				*pd = x;
			}else{
				rv_noexist(self->pyseg_->pysec_->sec_, sym->name, self->pyseg_->x_, 2);
				err = 1;
			}
		}else{
			PyErr_SetString(PyExc_ValueError,
				"must be a double");
			err = -1;
		}
	}else{
		err = PyObject_GenericSetAttr((PyObject*)self, name, value);
	}
	Py_DECREF(name);
	return err;
}
Esempio n. 9
0
File: ofx.cpp Progetto: gatgui/ofxpp
int PyOFXActionArguments_SetAttr(PyObject *self, PyObject *aname, PyObject *aval)
{
  PyOFXActionArguments *pargs = (PyOFXActionArguments*)self;
  
  char *name = PyString_AsString(aname);
  
  std::map<std::string, PyObject*>::iterator it = pargs->args.find(name);
  
  if (it == pargs->args.end())
  {
    // don't have such attribute, maybe base class have
    if (PyObject_GenericSetAttr(self, aname, aval) == 0)
    {
      return 0;
    }
    else
    {
      // no, add it then
      PyErr_Clear();
      pargs->args[name] = aval;
    }
  }
  else
  {
    Py_XDECREF(it->second);
    it->second = aval;
  }
  
  Py_INCREF(aval);
  
  return 0;
}
Esempio n. 10
0
static int segment_setattro(NPySegObj* self, PyObject* name, PyObject* value) {
	PyObject* rv;
	Symbol* sym;
	int err = 0;
	Py_INCREF(name);
	char* n = PyString_AsString(name);
//printf("segment_setattro %s\n", n);
	if (strcmp(n, "x") == 0) {
		int nseg;
		double x;
		if (PyArg_Parse(value, "d", &x) == 1 &&  x > 0. && x <= 1.) {
			if (x < 1e-9) {
				self->x_ = 0.;
			}else if (x > 1. - 1e-9) {
				self->x_ = 1.;
			}else{
				self->x_ = x;
			}
		}else{
			PyErr_SetString(PyExc_ValueError,
				"x must be in range 0. to 1.");
			err = -1;
		}
	}else if ((rv = PyDict_GetItemString(rangevars_, n)) != NULL) {
		sym = ((NPyRangeVar*)rv)->sym_;
		if (ISARRAY(sym)) {
			char s[200];
			sprintf(s, "%s needs an index for assignment", sym->name);
			PyErr_SetString(PyExc_IndexError, s);
			err = -1;
		}else{
			int errp;
			double* d = nrnpy_rangepointer(self->pysec_->sec_, sym, self->x_, &errp);
			if (!d) {
				rv_noexist(self->pysec_->sec_, n, self->x_, errp);
				Py_DECREF(name);
				return -1;
			}
			if (!PyArg_Parse(value, "d", d)) {
				PyErr_SetString(PyExc_ValueError, "bad value");
				Py_DECREF(name);
				return -1;
			}else if (sym->u.rng.type == MORPHOLOGY) {
				diam_changed = 1;
				self->pysec_->sec_->recalc_area_ = 1;
				nrn_diam_change(self->pysec_->sec_);
			}else if (sym->u.rng.type == EXTRACELL && sym->u.rng.index == 0) {
				// cannot execute because xraxial is an array
				diam_changed = 1;
			}
		}
	}else{
		err = PyObject_GenericSetAttr((PyObject*)self, name, value);
	}
	Py_DECREF(name);
	return err;
}
Esempio n. 11
0
static int Proxy_setattro(
        ProxyObject *self, PyObject *name, PyObject *value)
{
    if (PyObject_HasAttr((PyObject *)Py_TYPE(self), name))
        return PyObject_GenericSetAttr((PyObject *)self, name, value);

    Proxy__ENSURE_WRAPPED_OR_RETURN_MINUS1(self);

    return PyObject_SetAttr(self->wrapped, name, value);
}
Esempio n. 12
0
static int __pyx_tp_setattro_13extinheritdel_Norwegian(PyObject *o, PyObject *n, PyObject *v) {
  if (v) {
    if (__pyx_ptype_13extinheritdel_Parrot->tp_setattro)
      return __pyx_ptype_13extinheritdel_Parrot->tp_setattro(o, n, v);
    return PyObject_GenericSetAttr(o, n, v);
  }
  else {
    return __pyx_f_13extinheritdel_9Norwegian___delattr__(o, n);
  }
}
Esempio n. 13
0
static int display_column_setattr(display_column *self, PyObject *attr_name, PyObject *value) {
    int i;
    
    // Check and make sure we have a string as attribute name...
    if (PyUnicode_Check(attr_name)) {
         PY_SCIP_SET_INT_MIN("position", self->display->position, -1);
         PY_SCIP_SET_INT_MIN("priority", self->display->priority, -1);
         PY_SCIP_SET_INT_MIN("width", self->display->width, -1);
    }
    return PyObject_GenericSetAttr((PyObject *) self, attr_name, value);
}
Esempio n. 14
0
static PyObject *
delattribute(PyObject *self, PyObject *args)
{
	PyObject *target, *name;
	if (!PyArg_UnpackTuple(args, "", 2, 2, &target, &name))
		return NULL;
	if (PyObject_GenericSetAttr(target, name, NULL) < 0)
		return NULL;
	Py_INCREF(Py_None);
	return Py_None;
}
Esempio n. 15
0
static int Row_setattro(PyObject* o, PyObject *name, PyObject* v)
{
    Row* self = (Row*)o;

    PyObject* index = PyDict_GetItem(self->map_name_to_index, name);

    if (index)
        return Row_ass_item(o, PyNumber_AsSsize_t(index, 0), v);

    return PyObject_GenericSetAttr(o, name, v);
}
static int
local_setattro(localobject *self, PyObject *name, PyObject *v)
{
	PyObject *ldict;
	
	ldict = _ldict(self);
	if (ldict == NULL) 
		return -1;

	return PyObject_GenericSetAttr((PyObject *)self, name, v);
}
void PythonArithmeticScript::set(const std::string & name, const float & val)
{
    PyObject * pn = PyString_FromString(name.c_str());
    PyObject * py_val = PyFloat_FromDouble(val);
    if (PyObject_GenericSetAttr(m_script, pn, py_val) == 0) {
        // PyObject_GenericSetAttr sets and error if nothing was found
        PyErr_Clear();
    }
    Py_DECREF(pn);
    Py_DECREF(py_val);
}
Esempio n. 18
0
//-------------------------------------------------------------------------------------
PyObject* PropertyDescription::onSetValue(PyObject* parentObj, PyObject* value)
{
	PyObject* pyName = PyUnicode_InternFromString(getName());
	int result = PyObject_GenericSetAttr(parentObj, pyName, value);
	Py_DECREF(pyName);
	
	if(result == -1)
		return NULL;

	return value;	
}
Esempio n. 19
0
static int
EC_setattro(PyTypeObject *type, PyObject *name, PyObject *value)
{
  /* We want to allow setting attributes of builti-in types, because
     EC did in the past and there's code that relies on it.

     We can't really set slots though, but I don't think we need to.
     There's no good way to spot slots.  We could use a lame rule like
     names that begin and end with __s and have just 4 _s smell too
     much like slots.


  */
  if (! (type->tp_flags & Py_TPFLAGS_HEAPTYPE)) 
    {
      char *cname;
      int l;

      cname = PyString_AsString(name);
      if (cname == NULL)
        return -1;
      l = PyString_GET_SIZE(name);
      if (l > 4 
          && cname[0] == '_' && cname[1] == '_'
          && cname[l-1] == '_' && cname[l-2] == '_'
          )
        {
          char *c;
          
          c = strchr(cname+2, '_');
          if (c != NULL && (c - cname) >= (l-2))
            {
              PyErr_Format
                (PyExc_TypeError,
                 "can't set attributes of built-in/extension type '%s' if the "
                 "attribute name begins and ends with __ and contains only "
                 "4 _ characters",
                 type->tp_name
                 );
              return -1;
            }
        }
      
      if (PyObject_GenericSetAttr(OBJECT(type), name, value) < 0)
        return -1;
    }
  else if (PyType_Type.tp_setattro(OBJECT(type), name, value) < 0)
    return -1;
#ifdef Py_TPFLAGS_HAVE_VERSION_TAG
  PyType_Modified(type);
#endif
  return 0;
}
Esempio n. 20
0
static int LuaObject_setattro(LuaObject *self, PyObject *name, PyObject *o)
{
    if (PyString_Check(name))
    {
        const char *str;
        str = PyString_AsString(name);
        if (strncmp(str, "__", 2) == 0)
            return PyObject_GenericSetAttr((PyObject *)self, name, o);
    }

    return LuaObject_ass_subscript(self, name, o);
}
Esempio n. 21
0
static int branching_rule_setattr(branching_rule *self, PyObject *attr_name, PyObject *value) {
    double d;
    int i;
    
    // Check and make sure we have a string as attribute name...
    if (PyUnicode_Check(attr_name)) {
        PY_SCIP_SET_DBL_MIN("maxbounddist", self->branch->maxbounddist, -1); 
        PY_SCIP_SET_INT_MIN("maxdepth", self->branch->maxdepth, -1); 
        PY_SCIP_SET_PRIORITY(SCIPbranchruleSetPriority, self->branch);
    }
    return PyObject_GenericSetAttr((PyObject *) self, attr_name, value);
}
Esempio n. 22
0
static int separator_setattr(separator *self, PyObject *attr_name, PyObject *value) {
    int i;
    double d;
    
    // Check and make sure we have a string as attribute name...
    if (PyUnicode_Check(attr_name)) {
        PY_SCIP_SET_INT_MIN("frequency", self->sepa->freq, -1); 
        PY_SCIP_SET_DBL_MIN("maxbounddist", self->sepa->maxbounddist, -1); 
        PY_SCIP_SET_PRIORITY(SCIPsepaSetPriority, self->sepa);
    }
    return PyObject_GenericSetAttr((PyObject *) self, attr_name, value);
}
Esempio n. 23
0
/** 
 * @brief Implements attribute set operation.
 */
int py_axl_list_set_attr (PyObject *o, PyObject *attr_name, PyObject *v)
{
	const char      * attr = NULL;
/*	PyAxlList        * self = (PyAxlList *) o; */
/*	axl_bool          boolean_value = axl_false; */

	/* now implement other attributes */
	if (! PyArg_Parse (attr_name, "s", &attr))
		return -1;

	/* now implement generic setter */
	return PyObject_GenericSetAttr (o, attr_name, v);
}
Esempio n. 24
0
File: _k20.c Progetto: kevinarpe/kx
static int
_K_setattro(_K *self, PyObject *nameo, PyObject *value)
{
	char *name = 0;
	if (PyString_Check(nameo)) {
		name = PyString_AS_STRING(nameo);
	}
	if (name && name[1] == 0 && strchr("ktc", name[0])) {
		PyErr_Format(PyExc_AttributeError,
			     "attribute %c is read only", name[0]);
		return -1;
	}
	return PyObject_GenericSetAttr((PyObject*)self, nameo, value);
}
Esempio n. 25
0
/**
 * Set attribute of channel object.
 * @param obj Channel object
 * @param name Attribute name
 * @param value Attribute value
 */
int pyplugin_channel_setattro(PyObject *obj, PyObject *name, PyObject *value) {
	if (PyObject_GenericSetAttr(obj, name, value) != 0) {
		// Non existing property is OK here...
		PyErr_Clear();

		// Set attribute in dictionary
		channel_PyObject *chan = (channel_PyObject *)obj;

		return PyDict_SetItem(chan->dict, name, value);
	}

	// 0 means success... (weird...)
	return 0;
} // pyplugin_channel_setattr
static int
module_setattr(PyObject *m, PyObject *name, PyObject *value)
{
	PyObject *globals = ((PyModuleObject *)m)->md_dict;
	PyObject *builtins = PyEval_GetBuiltins();
	if (globals != NULL && globals != builtins) {
		int shadows = shadows_builtin(globals, name);
		if (shadows == 1) {
			if (PyErr_Warn(PyExc_DeprecationWarning,
					"assignment shadows builtin") < 0)
				return -1;
		}
		else if (shadows == -1)
			return -1;
	}
	return PyObject_GenericSetAttr(m, name, value);
}
Esempio n. 27
0
static int
foo_setattro(fooobject *self, PyObject *name, PyObject *value)
{
    char *name_str;
    if (!PyString_Check(name)) {
        PyErr_SetObject(PyExc_AttributeError, name);
        return -1;
    }
    name_str = PyString_AsString(name);
    if (strcmp(name_str, "set_foo") == 0)
    {
        long v = PyInt_AsLong(value);
        if (v == -1 && PyErr_Occurred())
            return -1;
        self->foo = v;
    }
    return PyObject_GenericSetAttr((PyObject *)self, name, value);
}
Esempio n. 28
0
static int Task_setattro(PyTask *self, PyObject * oname, PyObject *v)
{
#ifndef NDEBUG
    if (self->m_task == NULL) {
        PyErr_SetString(PyExc_AssertionError, "NULL task Task.setattr");
        return -1;
    }
#endif // NDEBUG
    char * name = PyString_AsString(oname);
    if (strcmp(name, "progress") == 0) {
        if (PyFloat_Check(v)) {
            self->m_task->progress() = PyFloat_AsDouble(v);
        } else if (PyInt_Check(v)) {
            self->m_task->progress() = PyInt_AsLong(v);
        } else {
            PyErr_SetString(PyExc_TypeError, "progress must be a number");
            return -1;
        }
        return 0;
    }
    if (strcmp(name, "rate") == 0) {
        double rate;
        if (PyFloat_Check(v)) {
            rate = PyFloat_AsDouble(v);
        } else if (PyInt_Check(v)) {
            rate = PyInt_AsLong(v);
        } else {
            PyErr_SetString(PyExc_TypeError, "rate must be a number");
            return -1;
        }
        self->m_task->rate() = rate;
        return 0;
    }
    if (PyWeakref_CheckProxy(v)) {
        PyErr_SetString(PyExc_TypeError, "don't store proxy objects as attributes");
        return -1;
    }
    if (PyLocatedEntity_Check(v)) {
        PyErr_SetString(PyExc_TypeError, "don't store server objects as attributes");
        return -1;
    }
    // FIXME Something may be required here long term, for task attributes.
    return PyObject_GenericSetAttr((PyObject*)self, oname, v);
}
Esempio n. 29
0
static int
pb_setattro(PersistentBaseObject *self, PyObject *name, PyObject *value)
{
	char *sname;
    sname = NULL;
	if (AttributeName_Check(name)) {
	    sname = AttributeName_AsString(name);
	} else {
		PyErr_SetString(PyExc_TypeError, "attribute name must be a string");
        return -1;
	}
	if (load_triggering_name(sname)) {
		if (self->p_status != UNSAVED) {
			if (!call_method((PyObject *)self, "_p_note_change", NULL))
				return -1;
		}
	}
	return PyObject_GenericSetAttr((PyObject *)self, name, value);
}
Esempio n. 30
0
static int
attr_dir_setattro(PyObject *_self, PyObject *name, PyObject *value)
{
	int ret;

	ret = PyObject_GenericSetAttr(_self, name, value);
	if (!ret || !PyErr_ExceptionMatches(PyExc_AttributeError))
		return ret;

	PyErr_Clear();
	ret = attr_dir_ass_subscript(_self, name, value);
	if (!ret || !PyErr_ExceptionMatches(PyExc_KeyError))
		return ret;

	PyErr_Format(PyExc_AttributeError,
		     "'%.50s' object has no attribute '%.400s'",
		     Py_TYPE(_self)->tp_name, PyString_AS_STRING(name));
	return -1;
}