Beispiel #1
0
	static PyObject *getattro(PyObject *self, PyObject *obname) {
		char *name=PYWIN_ATTR_CONVERT(obname);
		if (name==NULL)
			return NULL;
		if (strcmp(name, "__members__")==0) {
			PyObject *ret = PyList_New(4);
			if (ret) {
				PyList_SET_ITEM(ret, 0, PyString_FromString("AttrName"));
				PyList_SET_ITEM(ret, 1, PyString_FromString("ControlCode"));
				PyList_SET_ITEM(ret, 2, PyString_FromString("ADsType"));
				PyList_SET_ITEM(ret, 3, PyString_FromString("Values"));
			}
			return ret;
		}
		if (strcmp(name, "Values")==0) {
			PyObject *ret = ((PyADS_ATTR_INFO *)self)->obValues ?
				 ((PyADS_ATTR_INFO *)self)->obValues :
			         Py_None;
			Py_INCREF(ret);
			return ret;
		}
		return PyObject_GenericGetAttr(self, obname);
	}
Beispiel #2
0
/** 
 * @brief This function implements the generic attribute getting that
 * allows to perform complex member resolution (not merely direct
 * member access).
 */
PyObject * py_axl_doc_get_attr (PyObject *o, PyObject *attr_name) {
	const char      * attr = NULL;
	PyObject        * result;
	PyAxlDoc        * self = (PyAxlDoc *) o; 

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

	__axl_log (LOG_DOMAIN, AXL_LEVEL_DEBUG, "received request to report doc attr name %s (self: %p)",
		   attr, o);
	if (axl_cmp (attr, "encoding")) {
		/* encoding */
		return Py_BuildValue ("s", axl_doc_get_encoding (self->doc));
	} else if (axl_cmp (attr, "standalone") || axl_cmp (attr, "stand_alone")) {
		/* standalone */
		return Py_BuildValue ("i", axl_doc_get_standalone (self->doc));
	} else if (axl_cmp (attr, "root")) {
		if (axl_doc_get_root (self->doc) == NULL) {
			Py_INCREF (Py_None);
			return Py_None;
		}

		/* return root axl node: signaling to not finish the
		 * internal copy once it is collected the reference */
		__axl_log (LOG_DOMAIN, AXL_LEVEL_DEBUG, "reporting root node (doc ref: %p, ref count: %d)",
			   self, self->ob_refcnt);
		return py_axl_node_create (axl_doc_get_root (self->doc), axl_false, o);
	}

	/* first implement generic attr already defined */
	result = PyObject_GenericGetAttr (o, attr_name);
	if (result)
		return result;
	
	return NULL;
}
Beispiel #3
0
static PyObject*
module_getattro(PyModuleObject *m, PyObject *name)
{
    PyObject *attr, *mod_name;
    attr = PyObject_GenericGetAttr((PyObject *)m, name);
    if (attr || !PyErr_ExceptionMatches(PyExc_AttributeError))
        return attr;
    PyErr_Clear();
    if (m->md_dict) {
        _Py_IDENTIFIER(__name__);
        mod_name = _PyDict_GetItemId(m->md_dict, &PyId___name__);
        if (mod_name) {
            PyErr_Format(PyExc_AttributeError,
                        "module '%U' has no attribute '%U'", mod_name, name);
            return NULL;
        }
        else if (PyErr_Occurred()) {
            PyErr_Clear();
        }
    }
    PyErr_Format(PyExc_AttributeError,
                "module has no attribute '%U'", name);
    return NULL;
}
Beispiel #4
0
bool fillQtProperties(PyObject* qObj, const QMetaObject* metaObj, PyObject* kwds, const char** blackList, unsigned int blackListSize)
{

    PyObject *key, *value;
    Py_ssize_t pos = 0;

    while (PyDict_Next(kwds, &pos, &key, &value)) {
        if (!blackListSize || !std::binary_search(blackList, blackList + blackListSize, std::string(Shiboken::String::toCString(key)))) {
            QByteArray propName(Shiboken::String::toCString(key));
            if (metaObj->indexOfProperty(propName) != -1) {
                propName[0] = std::toupper(propName[0]);
                propName.prepend("set");

                Shiboken::AutoDecRef propSetter(PyObject_GetAttrString(qObj, propName.constData()));
                if (!propSetter.isNull()) {
                    Shiboken::AutoDecRef args(PyTuple_Pack(1, value));
                    Shiboken::AutoDecRef retval(PyObject_CallObject(propSetter, args));
                } else {
                    PyObject* attr = PyObject_GenericGetAttr(qObj, key);
                    if (PySide::Property::checkType(attr))
                        PySide::Property::setValue(reinterpret_cast<PySideProperty*>(attr), qObj, value);
                }
            } else {
                propName.append("()");
                if (metaObj->indexOfSignal(propName) != -1) {
                    propName.prepend('2');
                    PySide::Signal::connect(qObj, propName, value);
                } else {
                    PyErr_Format(PyExc_AttributeError, "'%s' is not a Qt property or a signal", propName.constData());
                    return false;
                };
            }
        }
    }
    return true;
}
Beispiel #5
0
static PyObject *
oss_getattro(oss_audio_t *self, PyObject *nameobj)
{
    char *name = "";
    PyObject * rval = NULL;

    if (PyUnicode_Check(nameobj))
        name = _PyUnicode_AsString(nameobj);

    if (strcmp(name, "closed") == 0) {
        rval = (self->fd == -1) ? Py_True : Py_False;
        Py_INCREF(rval);
    }
    else if (strcmp(name, "name") == 0) {
        rval = PyUnicode_FromString(self->devicename);
    }
    else if (strcmp(name, "mode") == 0) {
        /* No need for a "default" in this switch: from newossobject(),
           self->mode can only be one of these three values. */
        switch(self->mode) {
            case O_RDONLY:
                rval = PyUnicode_FromString("r");
                break;
            case O_RDWR:
                rval = PyUnicode_FromString("rw");
                break;
            case O_WRONLY:
                rval = PyUnicode_FromString("w");
                break;
        }
    }
    else {
        rval = PyObject_GenericGetAttr((PyObject *)self, nameobj);
    }
    return rval;
}
Beispiel #6
0
static PyObject *
BaseRowProxy_getattro(BaseRowProxy *self, PyObject *name)
{
    PyObject *tmp;

    if (!(tmp = PyObject_GenericGetAttr((PyObject *)self, name))) {
        if (!PyErr_ExceptionMatches(PyExc_AttributeError))
            return NULL;
        PyErr_Clear();
    }
    else
        return tmp;

    tmp = BaseRowProxy_subscript(self, name);
    if (tmp == NULL && PyErr_ExceptionMatches(PyExc_KeyError)) {
        PyErr_Format(
                PyExc_AttributeError, 
                "Could not locate column in row for column '%.200s'",
                PyString_AsString(name)
            );
        return NULL;
    }
    return tmp;
}
static PyObject*
Per_getattro(cPersistentObject *self, PyObject *name)
{
    PyObject *result = NULL;    /* guilty until proved innocent */
    PyObject *converted;
    char *s;

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

    if (unghost_getattr(s))
    {
        if (unghostify(self) < 0)
            goto Done;
        accessed(self);
    }
    result = PyObject_GenericGetAttr((PyObject *)self, name);

Done:
    Py_XDECREF(converted);
    return result;
}
Beispiel #8
0
static PyObject * rpmfi_getattro(PyObject * o, PyObject * n)
	/*@*/
{
    return PyObject_GenericGetAttr(o, n);
}
Beispiel #9
0
static PyObject * Match_getattro(
    PyObject *self,
    PyObject *name)
{
  return PyObject_GenericGetAttr(self, name);
}
Beispiel #10
0
static PyObject *
fortran_getattr(PyFortranObject *fp, char *name) {
    int i,j,k,flag;
    if (fp->dict != NULL) {
        PyObject *v = PyDict_GetItemString(fp->dict, name);
        if (v != NULL) {
            Py_INCREF(v);
            return v;
        }
    }
    for (i=0,j=1;i<fp->len && (j=strcmp(name,fp->defs[i].name));i++);
    if (j==0)
        if (fp->defs[i].rank!=-1) {                   /* F90 allocatable array */
            if (fp->defs[i].func==NULL) return NULL;
            for(k=0;k<fp->defs[i].rank;++k)
                fp->defs[i].dims.d[k]=-1;
            save_def = &fp->defs[i];
            (*(fp->defs[i].func))(&fp->defs[i].rank,fp->defs[i].dims.d,set_data,&flag);
            if (flag==2)
                k = fp->defs[i].rank + 1;
            else
                k = fp->defs[i].rank;
            if (fp->defs[i].data !=NULL) {              /* array is allocated */
                PyObject *v = PyArray_New(&PyArray_Type, k, fp->defs[i].dims.d,
                                          fp->defs[i].type, NULL, fp->defs[i].data, 0, NPY_FARRAY,
                                          NULL);
                if (v==NULL) return NULL;
                /* Py_INCREF(v); */
                return v;
            } else {                                    /* array is not allocated */
                Py_INCREF(Py_None);
                return Py_None;
            }
        }
    if (strcmp(name,"__dict__")==0) {
        Py_INCREF(fp->dict);
        return fp->dict;
    }
    if (strcmp(name,"__doc__")==0) {
#if PY_VERSION_HEX >= 0x03000000
        PyObject *s = PyUnicode_FromString(""), *s2, *s3;
        for (i=0;i<fp->len;i++) {
            s2 = fortran_doc(fp->defs[i]);
            s3 = PyUnicode_Concat(s, s2);
            Py_DECREF(s2);
            Py_DECREF(s);
            s = s3;
        }
#else
        PyObject *s = PyString_FromString("");
        for (i=0;i<fp->len;i++)
            PyString_ConcatAndDel(&s,fortran_doc(fp->defs[i]));
#endif
        if (PyDict_SetItemString(fp->dict, name, s))
            return NULL;
        return s;
    }
    if ((strcmp(name,"_cpointer")==0) && (fp->len==1)) {
        PyObject *cobj = F2PyCapsule_FromVoidPtr((void *)(fp->defs[0].data),NULL);
        if (PyDict_SetItemString(fp->dict, name, cobj))
            return NULL;
        return cobj;
    }
#if PY_VERSION_HEX >= 0x03000000
    if (1) {
        PyObject *str, *ret;
        str = PyUnicode_FromString(name);
        ret = PyObject_GenericGetAttr((PyObject *)fp, str);
        Py_DECREF(str);
        return ret;
    }
#else
    return Py_FindMethod(fortran_methods, (PyObject *)fp, name);
#endif
}
PyObject *PySTGMEDIUM::getattro(PyObject *self, PyObject *obname)
{
	char *name=PYWIN_ATTR_CONVERT(obname);
	if (name==NULL)
		return NULL;

	PySTGMEDIUM *ps = (PySTGMEDIUM *)self;
	// @prop int|tymed|An integer indicating the type of data in the stgmedium
	if (strcmp(name, "tymed")==0)
		return PyInt_FromLong(ps->medium.tymed);
	// @prop object|data|The data in the stgmedium.  
	// The result depends on the value of the 'tymed' property of the <o PySTGMEDIUM> object.
	// @flagh tymed|Result Type
	if (strcmp(name, "data")==0) {
		switch (ps->medium.tymed) {
			// @flag TYMED_GDI|An integer GDI handle
			case TYMED_GDI:
				return PyLong_FromVoidPtr(ps->medium.hBitmap);
			// @flag TYMED_MFPICT|An integer METAFILE handle
			case TYMED_MFPICT:
				return PyLong_FromVoidPtr(ps->medium.hMetaFilePict);
			// @flag TYMED_ENHMF|An integer ENHMETAFILE handle
			case TYMED_ENHMF:
				return PyLong_FromVoidPtr(ps->medium.hEnhMetaFile);
			// @flag TYMED_HGLOBAL|A string with the bytes of the global memory object.
			case TYMED_HGLOBAL: {
				PyObject *ret;
				void *p = GlobalLock(ps->medium.hGlobal);
				if (p) {
					ret = PyString_FromStringAndSize( (char *)p, GlobalSize(ps->medium.hGlobal));
					GlobalUnlock(ps->medium.hGlobal);
				} else {
					ret = Py_None;
					Py_INCREF(Py_None);
				}
				return ret;
			}
			// @flag TYMED_FILE|A string/unicode filename
			case TYMED_FILE: 
				return PyWinObject_FromWCHAR(ps->medium.lpszFileName);
			// @flag TYMED_ISTREAM|A <o PyIStream> object
			case TYMED_ISTREAM:
			// @flag TYMED_ISTORAGE|A <o PyIStorage> object
				return PyCom_PyObjectFromIUnknown(ps->medium.pstm, IID_IStream, TRUE);
			case TYMED_ISTORAGE:
				return PyCom_PyObjectFromIUnknown(ps->medium.pstg, IID_IStorage, TRUE);
			case TYMED_NULL:
				PyErr_SetString(PyExc_ValueError, "This STGMEDIUM has no data");
				return NULL;
			default:
				PyErr_SetString(PyExc_RuntimeError, "Unknown tymed");
				return NULL;
		}
	}
	// @prop int|data_handle|The raw 'integer' representation of the data.  
	// For TYMED_HGLOBAL, this is the handle rather than the string data.
	// For the string and interface types, this is an integer holding the pointer.
	if (strcmp(name, "data_handle")==0) {
		switch (ps->medium.tymed) {
			case TYMED_GDI:
				return PyLong_FromVoidPtr(ps->medium.hBitmap);
			case TYMED_MFPICT:
				return PyLong_FromVoidPtr(ps->medium.hMetaFilePict);
			case TYMED_ENHMF:
				return PyLong_FromVoidPtr(ps->medium.hEnhMetaFile);
			case TYMED_HGLOBAL:
				return PyLong_FromVoidPtr(ps->medium.hGlobal);
			// and may as well hand out the pointers for these.  
			// We are all consenting adults :)
			case TYMED_FILE: 
				return PyLong_FromVoidPtr(ps->medium.lpszFileName);
			case TYMED_ISTREAM:
				return PyLong_FromVoidPtr(ps->medium.pstm);
			case TYMED_ISTORAGE:
				return PyLong_FromVoidPtr(ps->medium.pstg);
			case TYMED_NULL:
				PyErr_SetString(PyExc_ValueError, "This STGMEDIUM has no data");
				return NULL;
			default:
				PyErr_SetString(PyExc_RuntimeError, "Unknown tymed");
				return NULL;
		}
	}
	return PyObject_GenericGetAttr(self, obname);
}
Beispiel #12
0
static PyObject * rpmal_getattro(PyObject * o, PyObject * n)
{
    return PyObject_GenericGetAttr(o, n);
}
static PyObject *PySilcUser_GetAttr(PyObject *self, PyObject *name)
{
    // expose the following attributes as readonly
    // - char *nickname
    // - char *username
    // - char *hostname
    // - char *server
    // - char *realname
    // - unsigned char *fingerprint;
    //   SilcUInt32 finderprint_len;
    //
    // - 64/160 bit user id
    // - unsigned int mode
    // - (TODO) attrs;
    // - (TODO) public_key;
    // - int status
    // - (TODO) channels
    // - int resolve_cmd_ident;
    
    int result;
    PyObject *temp = NULL, *value = NULL;
    PySilcUser *pyuser = (PySilcUser *)self;
  
    if (!pyuser->silcobj)
        goto cleanup;
  
    // check for nickname
    temp = PyString_FromString("nickname");
    if (PyObject_Cmp(temp, name, &result) == -1)
        goto cleanup;
    if (result == 0) {
        if (pyuser->silcobj->nickname)
            value = PyString_FromString(pyuser->silcobj->nickname);
        else {
            value = Py_None;
            Py_INCREF(value);
        }
        goto cleanup;
    }
  
    // check for username
    Py_DECREF(temp);
    temp = PyString_FromString("username");
    if (PyObject_Cmp(temp, name, &result) == -1)
        goto cleanup;
    if (result == 0) {
        if (pyuser->silcobj->username)
            value = PyString_FromString(pyuser->silcobj->username);
        else {
            value = Py_None;
            Py_INCREF(value);
        }
        goto cleanup;
    }

    // check for hostname
    Py_DECREF(temp);
    temp = PyString_FromString("hostname");
    if (PyObject_Cmp(temp, name, &result) == -1)
        goto cleanup;
    if (result == 0) {
        if (pyuser->silcobj->hostname)
            value = PyString_FromString(pyuser->silcobj->hostname);
        else {
            value = Py_None;
            Py_INCREF(value);
        }
        goto cleanup;
    }
    
    // check for server
    Py_DECREF(temp);
    temp = PyString_FromString("server");
    if (PyObject_Cmp(temp, name, &result) == -1)
        goto cleanup;
    if (result == 0) {
        if (pyuser->silcobj->server)
            value = PyString_FromString(pyuser->silcobj->server);
        else {
            value = Py_None;
            Py_INCREF(value);
        }
        goto cleanup;
    }    
  
    // check for realname
    Py_DECREF(temp);
    temp = PyString_FromString("realname");
    if (PyObject_Cmp(temp, name, &result) == -1)
        goto cleanup;
    if (result == 0) {
        if (pyuser->silcobj->realname)
            value = PyString_FromString(pyuser->silcobj->realname);
        else {
            value = Py_None;
            Py_INCREF(value);
        }
        goto cleanup;
    }
    
    // check for fingerprint
    Py_DECREF(temp);
    temp = PyString_FromString("fingerprint");
    if (PyObject_Cmp(temp, name, &result) == -1)
        goto cleanup;
    if (result == 0) {
        if (pyuser->silcobj->fingerprint)
            value = PyString_FromStringAndSize(pyuser->silcobj->fingerprint, pyuser->silcobj->fingerprint_len);
        else {
            value = Py_None;
            Py_INCREF(value);
        }
        goto cleanup;
    }
  
    // check for user id
    Py_DECREF(temp);
    temp = PyString_FromString("user_id");
    if (PyObject_Cmp(temp, name, &result) == -1)
        goto cleanup;
    if (result == 0) {
        char buf[224];
        memcpy(&buf, (pyuser->silcobj->id), 224);
        value = PyString_FromStringAndSize(buf, 224);
        goto cleanup;
    }
    
    // check for mode
    Py_DECREF(temp);
    temp = PyString_FromString("mode");
    if (PyObject_Cmp(temp, name, &result) == -1)
        goto cleanup;
    if (result == 0) {
        value = PyInt_FromLong(pyuser->silcobj->mode);
        goto cleanup;
    }
    
    // check for status
    Py_DECREF(temp);
    temp = PyString_FromString("status");
    if (PyObject_Cmp(temp, name, &result) == -1)
        goto cleanup;
    if (result == 0) {
        value = PyInt_FromLong(pyuser->silcobj->status);
        goto cleanup;
    }
    
    // check for resolve_cmd_ident
    Py_DECREF(temp);
    temp = PyString_FromString("resolve_cmd_ident");
    if (PyObject_Cmp(temp, name, &result) == -1)
        goto cleanup;
    if (result == 0) {
        value = PyInt_FromLong(pyuser->silcobj->resolve_cmd_ident);
        goto cleanup;
    }
    
cleanup:
    Py_XDECREF(temp);
    if (value)
        return value;
    else
        return PyObject_GenericGetAttr(self, name);    
}
Beispiel #14
0
static PyObject *
potential_getattro(potential_t *self, PyObject *pyname)
{
  char *name;
  property_t *p;
  PyObject *r = NULL;
  PyArrayObject *arr;
  npy_intp dims[3];
  double *data;
  PyObject **odata;
  int i, j, k;

  name = PyString_AsString(pyname);
  if (!name)
    return NULL;

  p = self->f90members->first_property;

  while (p != NULL && strcmp(p->name, name)) {
    p = p->next;
  }

  if (p) {
    r = NULL;
    switch (p->kind) {
    case PK_INT:
      r = PyInt_FromLong(*((int*) p->ptr));
      break;
    case PK_DOUBLE:
      r = PyFloat_FromDouble(*((double*) p->ptr));
      break;
    case PK_BOOL:
      r = PyBool_FromLong(*((BOOL*) p->ptr));
      break;
    case PK_LIST:
      if (*p->tag5 == 1) {
	r = PyFloat_FromDouble(*((double*) p->ptr));
      } else {
	dims[0] = *p->tag5;
	arr = (PyArrayObject*) PyArray_SimpleNew(1, (npy_intp*) dims,
						 NPY_DOUBLE);
	data = (double *) PyArray_DATA(arr);
	for (i = 0; i < *p->tag5; i++) {
	  data[i] = ((double*) p->ptr)[i];
	}
	r = (PyObject*) arr;
      }
      break;
    case PK_FORTRAN_STRING_LIST:
      if (*p->tag5 == 1) {
	r = fstring_to_pystring((char*) p->ptr, p->tag);
      } else {
	dims[0] = *p->tag5;
	arr = (PyArrayObject*) PyArray_SimpleNew(1, (npy_intp*) dims,
						 NPY_OBJECT);
	odata = (PyObject **) PyArray_DATA(arr);
	for (i = 0; i < *p->tag5; i++) {
	  odata[i] = fstring_to_pystring(((char*) p->ptr + i*p->tag), p->tag);
	}
	r = (PyObject*) arr;
      }
      break;
    case PK_ARRAY2D:
      dims[0] = p->tag;
      dims[1] = p->tag2;
      arr = (PyArrayObject*) PyArray_SimpleNew(2, (npy_intp*) dims, NPY_DOUBLE);
      data = (double *) PyArray_DATA(arr);
      for (i = 0; i < p->tag; i++) {
	for (j = 0; j < p->tag2; j++) {
	  data[j + i*p->tag2] = ((double*) p->ptr)[i + j*p->tag];
	}
      }
      //        memcpy(data, p->ptr, p->tag*p->tag2*sizeof(double));
      r = (PyObject*) arr;
      break;
    case PK_ARRAY3D:
      dims[0] = p->tag;
      dims[1] = p->tag2;
      dims[2] = p->tag3;
      arr = (PyArrayObject*) PyArray_SimpleNew(3, (npy_intp*) dims, NPY_DOUBLE);
      data = (double *) PyArray_DATA(arr);
      for (i = 0; i < p->tag; i++) {
	for (j = 0; j < p->tag2; j++) {
	  for (k = 0; k < p->tag3; k++) {
	    data[k + (j + i*p->tag2)*p->tag3] = 
	      ((double*) p->ptr)[i + (j + k*p->tag2)*p->tag];
	  }
	}
      }
      //        memcpy(data, p->ptr, p->tag*p->tag2*p->tag3*sizeof(double));
      r = (PyObject*) arr;
      break;
    default:
      PyErr_SetString(PyExc_TypeError, "Internal error: Unknown type encountered in section.");
      break;
    }
  } else {
    r = PyObject_GenericGetAttr((PyObject *) self, pyname);
    // Py_FindMethod(self->ob_type->tp_methods, (PyObject *) self, name);
  }

  return r;
}
Beispiel #15
0
static PyObject *
keymap_getattr(PyKeyMapObject *self, PyObject *name)
{
	return PyObject_GenericGetAttr((PyObject *)self, name);
}
static void initialize_bin_for_strictypes(AerospikeClient *self, as_error *err, PyObject *py_value, as_binop *binop, char *bin, as_static_pool *static_pool) {
	
	as_bin *binop_bin = &binop->bin;
	if (PyInt_Check(py_value)) {
		int val = PyInt_AsLong(py_value);
		as_integer_init((as_integer *) &binop_bin->value, val);
		binop_bin->valuep = &binop_bin->value;
	} else if (PyLong_Check(py_value)) {
		long val = PyLong_AsLong(py_value);
		as_integer_init((as_integer *) &binop_bin->value, val);
		binop_bin->valuep = &binop_bin->value;
	} else if (PyString_Check(py_value)) {
		char * val = PyString_AsString(py_value);
		as_string_init((as_string *) &binop_bin->value, val, false);
		binop_bin->valuep = &binop_bin->value;	
	} else if (PyUnicode_Check(py_value)) {
		PyObject *py_ustr1 = PyUnicode_AsUTF8String(py_value);
		char * val = PyString_AsString(py_ustr1);
		as_string_init((as_string *) &binop_bin->value, val, false);
		binop_bin->valuep = &binop_bin->value;	
	} else if (PyFloat_Check(py_value)) {
		int64_t val = PyFloat_AsDouble(py_value);
		if (aerospike_has_double(self->as)) {
			as_double_init((as_double *) &binop_bin->value, val);
			binop_bin->valuep = &binop_bin->value;
		} else {
			as_bytes *bytes;
			GET_BYTES_POOL(bytes, static_pool, err);
			serialize_based_on_serializer_policy(self, SERIALIZER_PYTHON, &bytes, py_value, err);	
			((as_val *) &binop_bin->value)->type = AS_UNKNOWN;
			binop_bin->valuep = (as_bin_value *) bytes;
		}
	} else if (PyList_Check(py_value)) {
		as_list * list = NULL;
		pyobject_to_list(self, err, py_value, &list, static_pool, SERIALIZER_PYTHON);
		((as_val *) &binop_bin->value)->type = AS_UNKNOWN;
		binop_bin->valuep = (as_bin_value *) list;
	} else if (PyDict_Check(py_value)) {
		as_map * map = NULL;
		pyobject_to_map(self, err, py_value, &map, static_pool, SERIALIZER_PYTHON);
		((as_val *) &binop_bin->value)->type = AS_UNKNOWN;
		binop_bin->valuep = (as_bin_value *) map;
	} else if (!strcmp(py_value->ob_type->tp_name, "aerospike.Geospatial")) {
		PyObject* py_data = PyObject_GenericGetAttr(py_value, PyString_FromString("geo_data"));
		char *geo_value = PyString_AsString(AerospikeGeospatial_DoDumps(py_data, err));
		if (aerospike_has_geo(self->as)) {
			as_geojson_init((as_geojson *) &binop_bin->value, geo_value, false);
			binop_bin->valuep = &binop_bin->value;
		} else {
			as_bytes *bytes;
			GET_BYTES_POOL(bytes, static_pool, err);
			serialize_based_on_serializer_policy(self, SERIALIZER_PYTHON, &bytes, py_data, err);	
			((as_val *) &binop_bin->value)->type = AS_UNKNOWN;
			binop_bin->valuep = (as_bin_value *) bytes;
		}
	} else if (!strcmp(py_value->ob_type->tp_name, "aerospike.null")) {
		((as_val *) &binop_bin->value)->type = AS_UNKNOWN;
		binop_bin->valuep = (as_bin_value *) &as_nil;
	} else if (PyByteArray_Check(py_value)) {
		as_bytes *bytes;
		GET_BYTES_POOL(bytes, static_pool, err);
		serialize_based_on_serializer_policy(self, SERIALIZER_PYTHON, &bytes, py_value, err);
		as_bytes_init_wrap((as_bytes *) &binop_bin->value, bytes->value, bytes->size, false);	
		binop_bin->valuep = &binop_bin->value;
	} else {
		as_bytes *bytes;
		GET_BYTES_POOL(bytes, static_pool, err);
		serialize_based_on_serializer_policy(self, SERIALIZER_PYTHON, &bytes, py_value, err);	
		((as_val *) &binop_bin->value)->type = AS_UNKNOWN;
		binop_bin->valuep = (as_bin_value *) bytes;
	}
	strcpy(binop_bin->name, bin);
}
Beispiel #17
0
static PyObject* segment_getattro(NPySegObj* self, PyObject* name) {
	Symbol* sym;
	Py_INCREF(name);
	char* n = PyString_AsString(name);
//printf("segment_getattr %s\n", n);
	PyObject* result = 0;
	PyObject* otype;
	PyObject* rv;
	if (strcmp(n, "v") == 0) {
		Node* nd = node_exact(self->pysec_->sec_, self->x_);
		result = Py_BuildValue("d", NODEV(nd));
	}else if ((otype = PyDict_GetItemString(pmech_types, n)) != NULL) {
		int type = PyInt_AsLong(otype);
//printf("segment_getattr type=%d\n", type);
		Node* nd = node_exact(self->pysec_->sec_, self->x_);
		Prop* p = nrn_mechanism(type, nd);
		if (!p) {
			rv_noexist(self->pysec_->sec_, n, self->x_, 1);
			Py_DECREF(name);
			return NULL;
		}	
		NPyMechObj* m = PyObject_New(NPyMechObj, pmech_generic_type);
		if (m == NULL) {
			Py_DECREF(name);
			return NULL;
		}
		m->pyseg_ = self;
		m->prop_ = p;
		Py_INCREF(m->pyseg_);
		result = (PyObject*)m;
	}else if ((rv = PyDict_GetItemString(rangevars_, n)) != NULL) {
		sym = ((NPyRangeVar*)rv)->sym_;
		if (ISARRAY(sym)) {
			NPyRangeVar* r = PyObject_New(NPyRangeVar, range_type);
			r->pyseg_ = self;
			Py_INCREF(r->pyseg_);
			r->sym_ = sym;
			r->isptr_ = 0;
			result = (PyObject*)r;
		}else{
			int err;
			double* d = nrnpy_rangepointer(self->pysec_->sec_, sym, self->x_, &err);
			if (!d) {
				rv_noexist(self->pysec_->sec_, n, self->x_, err);
				result = NULL;
			}else{
				result = Py_BuildValue("d", *d);
			}
		}
	}else if (strncmp(n, "_ref_", 5) == 0) {
		if (strcmp(n+5, "v") == 0) {
			Node* nd = node_exact(self->pysec_->sec_, self->x_);
			result = nrn_hocobj_ptr(&(NODEV(nd)));
		}else if ((sym = hoc_table_lookup(n+5, hoc_built_in_symlist)) != 0 && sym->type == RANGEVAR) {
			if (ISARRAY(sym)) {
				NPyRangeVar* r = PyObject_New(NPyRangeVar, range_type);
				r->pyseg_ = self;
				Py_INCREF(r->pyseg_);
				r->sym_ = sym;
				r->isptr_ = 1;
				result = (PyObject*)r;
			}else{
				int err;
				double* d = nrnpy_rangepointer(self->pysec_->sec_, sym, self->x_, &err);
				if (!d) {
					rv_noexist(self->pysec_->sec_, n+5, self->x_, err);
					result = NULL;
				}else{
					result = nrn_hocobj_ptr(d);
				}
			}
		}else{
			rv_noexist(self->pysec_->sec_, n, self->x_, 2);
			result = NULL;
		}
	}else if (strcmp(n, "__dict__") == 0) {
		Node* nd = node_exact(self->pysec_->sec_, self->x_);
		result = PyDict_New();
		assert(PyDict_SetItemString(result, "v", Py_None) == 0);
		assert(PyDict_SetItemString(result, "diam", Py_None) == 0);
		assert(PyDict_SetItemString(result, "cm", Py_None) == 0);
		for (Prop* p = nd->prop; p ; p = p->next) {
			if (p->type > CAP && !memb_func[p->type].is_point){
				char* pn = memb_func[p->type].sym->name;
				assert(PyDict_SetItemString(result, pn, Py_None) == 0);
			}
		}
	}else{
		result = PyObject_GenericGetAttr((PyObject*)self, name);
	}
	Py_DECREF(name);
	return result;
}
Beispiel #18
0
CounterLEObject_getattr(PyObject *s, char *name)
#endif
{
    PCT_CounterObject *self = (PCT_CounterObject *)s;
#ifdef IS_PY3K
	if (!PyUnicode_Check(attr))
		goto generic;

	if (PyUnicode_CompareWithASCIIString(attr, "carry") == 0) {
#else
    if (strcmp(name, "carry") == 0) {
#endif
        return PyLong_FromLong((long)self->carry);
#ifdef IS_PY3K
    } else if (!self->shortcut_disabled && PyUnicode_CompareWithASCIIString(attr, "__PCT_CTR_SHORTCUT__") == 0) {
#else
    } else if (!self->shortcut_disabled && strcmp(name, "__PCT_CTR_SHORTCUT__") == 0) {
#endif
        /* Shortcut hack - See block_template.c */
        Py_INCREF(Py_True);
        return Py_True;
    }
#ifdef IS_PY3K
  generic:
	return PyObject_GenericGetAttr(s, attr);
#else
    return Py_FindMethod(CounterLEObject_methods, (PyObject *)self, name);
#endif
}

static PyObject *
#ifdef IS_PY3K
CounterBEObject_getattro(PyObject *s, PyObject *attr)
#else
CounterBEObject_getattr(PyObject *s, char *name)
#endif
{
    PCT_CounterObject *self = (PCT_CounterObject *)s;
#ifdef IS_PY3K
	if (!PyUnicode_Check(attr))
		goto generic;

	if (PyUnicode_CompareWithASCIIString(attr, "carry") == 0) {
#else
    if (strcmp(name, "carry") == 0) {
#endif
        return PyLong_FromLong((long)self->carry);
#ifdef IS_PY3K
    } else if (!self->shortcut_disabled && PyUnicode_CompareWithASCIIString(attr, "__PCT_CTR_SHORTCUT__") == 0) {
#else
    } else if (!self->shortcut_disabled && strcmp(name, "__PCT_CTR_SHORTCUT__") == 0) {
#endif
        /* Shortcut hack - See block_template.c */
        Py_INCREF(Py_True);
        return Py_True;
    }
#ifdef IS_PY3K
  generic:
	return PyObject_GenericGetAttr(s, attr);
#else
    return Py_FindMethod(CounterBEObject_methods, (PyObject *)self, name);
#endif
}

static PyTypeObject
my_CounterLEType = {
#ifdef IS_PY3K
	PyVarObject_HEAD_INIT(NULL, 0)  /* deferred type init for compilation on Windows, type will be filled in at runtime */
#else
    PyObject_HEAD_INIT(NULL)
    0,                              /* ob_size */
#endif
	"_counter.CounterLE",           /* tp_name */
	sizeof(PCT_CounterObject),       /* tp_basicsize */
    0,                              /* tp_itemsize */
	/* methods */
    (destructor)CounterObject_dealloc, /* tp_dealloc */
    0,                              /* tp_print */
#ifdef IS_PY3K
	0,								/* tp_getattr */
#else
    CounterLEObject_getattr,        /* tp_getattr */
#endif
    0,                              /* tp_setattr */
    0,                              /* tp_compare */
    0,                              /* tp_repr */
    0,                              /* tp_as_number */
    0,                              /* tp_as_sequence */
    0,                              /* tp_as_mapping */
    0,                              /* tp_hash */
    (ternaryfunc)CounterObject_call, /* tp_call */
    0,                              /* tp_str */
#ifdef IS_PY3K
	CounterLEObject_getattro,		 /* tp_getattro */
#else
    0,                              /* tp_getattro */
#endif
    0,                              /* tp_setattro */
    0,                              /* tp_as_buffer */
    Py_TPFLAGS_DEFAULT,             /* tp_flags */
    "Counter (little endian)",      /* tp_doc */
#ifdef IS_PY3K
	0,								/*tp_traverse*/
	0,								/*tp_clear*/
	0,								/*tp_richcompare*/
	0,								/*tp_weaklistoffset*/
	0,								/*tp_iter*/
	0,								/*tp_iternext*/
	CounterLEObject_methods,		/*tp_methods*/
#endif
};

static PyTypeObject
my_CounterBEType = {
#ifdef IS_PY3K
	PyVarObject_HEAD_INIT(NULL, 0)  /* deferred type init for compilation on Windows, type will be filled in at runtime */
#else
    PyObject_HEAD_INIT(NULL)
    0,                              /* ob_size */
#endif
	"_counter.CounterBE",           /* tp_name */
	sizeof(PCT_CounterObject),       /* tp_basicsize */
    0,                              /* tp_itemsize */
    (destructor)CounterObject_dealloc, /* tp_dealloc */
    0,                              /* tp_print */
#ifdef IS_PY3K
	0,								/* tp_getattr */
#else
    CounterBEObject_getattr,        /* tp_getattr */
#endif
    0,                              /* tp_setattr */
    0,                              /* tp_compare */
    0,                              /* tp_repr */
    0,                              /* tp_as_number */
    0,                              /* tp_as_sequence */
    0,                              /* tp_as_mapping */
    0,                              /* tp_hash */
    (ternaryfunc)CounterObject_call, /* tp_call */
    0,                              /* tp_str */
#ifdef IS_PY3K
    CounterBEObject_getattro,		 /* tp_getattro */
#else
    0,                              /* tp_getattro */
#endif
    0,                              /* tp_setattro */
    0,                              /* tp_as_buffer */
    Py_TPFLAGS_DEFAULT,             /* tp_flags */
    "Counter (big endian)",         /* tp_doc */
#ifdef IS_PY3K
	0,								/*tp_traverse*/
	0,								/*tp_clear*/
	0,								/*tp_richcompare*/
	0,								/*tp_weaklistoffset*/
	0,								/*tp_iter*/
	0,								/*tp_iternext*/
	CounterBEObject_methods,		/*tp_methods*/
#endif
};

/*
 * Python 2.1 doesn't seem to allow a C equivalent of the __init__ method, so
 * we use the module-level functions newLE and newBE here.
 */
static PyObject *
CounterLE_new(PyObject *self, PyObject *args, PyObject *kwargs)
{
    PCT_CounterObject *obj = NULL;

    /* Create the new object */
    obj = PyObject_New(PCT_CounterObject, &my_CounterLEType);
    if (obj == NULL) {
        return NULL;
    }

    /* Zero the custom portion of the structure */
    memset(&obj->prefix, 0, sizeof(PCT_CounterObject) - offsetof(PCT_CounterObject, prefix));

    /* Call the object's initializer.  Delete the object if this fails. */
    if (CounterObject_init(obj, args, kwargs) != 0) {
        return NULL;
    }

    /* Set the inc_func pointer */
    obj->inc_func = (void (*)(void *))CounterLEObject_increment;

    /* Return the object */
    return (PyObject *)obj;
}
Beispiel #19
0
PyObject *PyRecord::getattro(PyObject *self, PyObject *obname)
{
	PyObject *res;
	PyRecord *pyrec = (PyRecord *)self;
	char *name=PYWIN_ATTR_CONVERT(obname);
	if (name==NULL)
		return NULL;
	if (strcmp(name, "__members__")==0) {
		ULONG cnames = 0;
		HRESULT hr = pyrec->pri->GetFieldNames(&cnames, NULL);
		if (FAILED(hr))
			return PyCom_BuildPyException(hr, pyrec->pri, IID_IRecordInfo);
		BSTR *strs = (BSTR *)malloc(sizeof(BSTR) * cnames);
		if (strs==NULL)
			return PyErr_NoMemory();
		hr = pyrec->pri->GetFieldNames(&cnames, strs);
		if (FAILED(hr)) {
			free(strs);
			return PyCom_BuildPyException(hr, pyrec->pri, IID_IRecordInfo);
		}
		res = PyList_New(cnames);
		for (ULONG i=0;i<cnames && res != NULL;i++) {
			PyObject *item = PyWinCoreString_FromString(strs[i]);
			SysFreeString(strs[i]);
			if (item==NULL) {
				Py_DECREF(res);
				res = NULL;
			} else
				PyList_SET_ITEM(res, i, item); // ref count swallowed.
		}
		free(strs);
		return res;
	}

	res = PyObject_GenericGetAttr(self, obname);
	if (res != NULL)
		return res;

	PyErr_Clear();
	WCHAR *wname;
	if (!PyWinObject_AsWCHAR(obname, &wname))
		return NULL;

	VARIANT vret;
	VariantInit(&vret);
	void *sub_data = NULL;

	PY_INTERFACE_PRECALL;
	HRESULT hr = pyrec->pri->GetFieldNoCopy(pyrec->pdata, wname, &vret, &sub_data);
	PyWinObject_FreeWCHAR(wname);
	PY_INTERFACE_POSTCALL;

	if (FAILED(hr)) {
		if (hr == TYPE_E_FIELDNOTFOUND){
			// This is slightly suspect - throwing a unicode
			// object for an AttributeError in py2k - but this
			// is the value we asked COM for, so it makes sense...
			// (and PyErr_Format doesn't handle unicode in py2x)
			PyErr_SetObject(PyExc_AttributeError, obname);
			return NULL;
			}
		return PyCom_BuildPyException(hr, pyrec->pri, IID_IRecordInfo);
	}

	// Short-circuit sub-structs and arrays here, so we dont allocate a new chunk
	// of memory and copy it - we need sub-structs to persist.
	if (V_VT(&vret)==(VT_BYREF | VT_RECORD))
		return new PyRecord(V_RECORDINFO(&vret), V_RECORD(&vret), pyrec->owner);
	else if (V_VT(&vret)==(VT_BYREF | VT_ARRAY | VT_RECORD)) {
		SAFEARRAY *psa = *V_ARRAYREF(&vret);
		int d = SafeArrayGetDim(psa);
		if (sub_data==NULL)
			return PyErr_Format(PyExc_RuntimeError, "Did not get a buffer for the array!");
		if (SafeArrayGetDim(psa) != 1)
			return PyErr_Format(PyExc_TypeError, "Only support single dimensional arrays of records");
		IRecordInfo *sub = NULL;
		long ubound, lbound, nelems;
		int i;
		BYTE *this_data;
		PyObject *ret_tuple = NULL;
		ULONG element_size = 0;
		hr = SafeArrayGetUBound(psa, 1, &ubound);
		if (FAILED(hr)) goto array_end;
		hr = SafeArrayGetLBound(psa, 1, &lbound);
		if (FAILED(hr)) goto array_end;
		hr = SafeArrayGetRecordInfo(psa, &sub);
		if (FAILED(hr)) goto array_end;
		hr = sub->GetSize(&element_size);
		if (FAILED(hr)) goto array_end;
		nelems = ubound-lbound;
		ret_tuple = PyTuple_New(nelems);
		if (ret_tuple==NULL) goto array_end;
		this_data = (BYTE *)sub_data;
		for (i=0;i<nelems;i++) {
			PyTuple_SET_ITEM(ret_tuple, i, new PyRecord(sub, this_data, pyrec->owner));
			this_data += element_size;
		}
array_end:
		if (sub)
			sub->Release();
		if (FAILED(hr)) 
			return PyCom_BuildPyException(hr, pyrec->pri, IID_IRecordInfo);
		return ret_tuple;
	}

	// This default conversion we use is a little slow (but it will do!)
	// For arrays, the pparray->pvData member is *not* set, since the actual data
	// pointer from the record is returned in sub_data, so set it here.
	if (V_ISARRAY(&vret) && V_ISBYREF(&vret))
		(*V_ARRAYREF(&vret))->pvData = sub_data;
	PyObject *ret = PyCom_PyObjectFromVariant(&vret);

//	VariantClear(&vret);
	return ret;
}
Beispiel #20
0
Box* superGetattribute(Box* _s, Box* _attr) {
    RELEASE_ASSERT(_s->cls == super_cls, "");
    BoxedSuper* s = static_cast<BoxedSuper*>(_s);

    RELEASE_ASSERT(_attr->cls == str_cls, "");
    BoxedString* attr = static_cast<BoxedString*>(_attr);

    bool skip = s->obj_type == NULL;

    if (!skip) {
        // Looks like __class__ is supposed to be "super", not the class of the the proxied object.
        skip = (attr->s() == class_str);
    }

    if (!skip) {
        PyObject* mro, *res, *tmp, *dict;
        PyTypeObject* starttype;
        descrgetfunc f;
        Py_ssize_t i, n;

        starttype = s->obj_type;
        mro = starttype->tp_mro;

        if (mro == NULL)
            n = 0;
        else {
            assert(PyTuple_Check(mro));
            n = PyTuple_GET_SIZE(mro);
        }
        for (i = 0; i < n; i++) {
            if ((PyObject*)(s->type) == PyTuple_GET_ITEM(mro, i))
                break;
        }
        i++;
        res = NULL;
        for (; i < n; i++) {
            tmp = PyTuple_GET_ITEM(mro, i);

// Pyston change:
#if 0
            if (PyType_Check(tmp))
                dict = ((PyTypeObject *)tmp)->tp_dict;
            else if (PyClass_Check(tmp))
                dict = ((PyClassObject *)tmp)->cl_dict;
            else
                continue;
            res = PyDict_GetItem(dict, name);
#endif
            res = tmp->getattr(attr);

            if (res != NULL) {
// Pyston change:
#if 0
                Py_INCREF(res);
                f = Py_TYPE(res)->tp_descr_get;
                if (f != NULL) {
                    tmp = f(res,
                        /* Only pass 'obj' param if
                           this is instance-mode sper
                           (See SF ID #743627)
                        */
                        (s->obj == (PyObject *)
                                    s->obj_type
                            ? (PyObject *)NULL
                            : s->obj),
                        (PyObject *)starttype);
                    Py_DECREF(res);
                    res = tmp;
                }
#endif
                return processDescriptor(res, (s->obj == s->obj_type ? None : s->obj), s->obj_type);
            }
        }
    }

    Box* rtn = PyObject_GenericGetAttr(s, attr);
    if (!rtn)
        throwCAPIException();
    return rtn;
}
Beispiel #21
0
static PyObject *
pygvfinfo_getattr(PyGnomeVFSFileInfo *self, const gchar *attr)
{
    GnomeVFSFileInfo *finfo;

    finfo = self->finfo;
    if (!strcmp(attr, "__members__")) {
	return Py_BuildValue("[ssssssssssssssssss]", "atime", "block_count",
			     "ctime", "device", "flags", "gid", "inode",
			     "io_block_size", "link_count", "mime_type",
			     "mtime", "name", "permissions", "access", "size",
			     "symlink_name", "type", "uid", "valid_fields");
    } else if (!strcmp(attr, "name")) {
	if (finfo->name)
	    return PyString_FromString(finfo->name);
	Py_INCREF(Py_None);
	return Py_None;
    } else if (!strcmp(attr, "valid_fields")) {
	return PyInt_FromLong(finfo->valid_fields);
    } else if (!strcmp(attr, "type")) {
	if (!(finfo->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_TYPE)) {
	    PyErr_SetString(PyExc_ValueError, "type field has no valid value");
	    return NULL;
	}
	return PyInt_FromLong(finfo->type);
    } else if (!strcmp(attr, "permissions")) {
	if (!(finfo->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_PERMISSIONS)) {
	    PyErr_SetString(PyExc_ValueError,
			    "permissions field has no valid value");
	    return NULL;
	}
	return PyInt_FromLong(finfo->permissions & (~PYGNOME_VFS_ACCESS_BITS));
    } else if (!strcmp(attr, "access")) {
	if (!(finfo->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_ACCESS)) {
	    PyErr_SetString(PyExc_ValueError,
			    "access field has no valid value");
	    return NULL;
	}
	return PyInt_FromLong(finfo->permissions & PYGNOME_VFS_ACCESS_BITS);
    } else if (!strcmp(attr, "flags")) {
	if (!(finfo->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_FLAGS)) {
	    PyErr_SetString(PyExc_ValueError,"flags field has no valid value");
	    return NULL;
	}
	return PyInt_FromLong(finfo->flags);
    } else if (!strcmp(attr, "device")) {
	if (!(finfo->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_DEVICE)) {
	    PyErr_SetString(PyExc_ValueError,
			    "device field has no valid value");
	    return NULL;
	}
	if (finfo->device <= G_MAXLONG)
	    return PyInt_FromLong(finfo->device);
	else
	    return PyLong_FromUnsignedLongLong(finfo->device);
    } else if (!strcmp(attr, "inode")) {
	if (!(finfo->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_INODE)) {
	    PyErr_SetString(PyExc_ValueError,"inode field has no valid value");
	    return NULL;
	}
	if (finfo->inode <= G_MAXLONG)
	    return PyInt_FromLong(finfo->inode);
	else
	    return PyLong_FromUnsignedLongLong(finfo->inode);
    } else if (!strcmp(attr, "link_count")) {
	if (!(finfo->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_LINK_COUNT)) {
	    PyErr_SetString(PyExc_ValueError,
			    "link_count field has no valid value");
	    return NULL;
	}
	if (finfo->link_count < G_MAXLONG)
	    return PyInt_FromLong(finfo->link_count);
	else
	    return PyLong_FromUnsignedLong(finfo->link_count);
    } else if (!strcmp(attr, "uid")) {
	if (!(finfo->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_IDS)) {
	    PyErr_SetString(PyExc_ValueError, "uid field has no valid value");
	    return NULL;
	}
	if (finfo->uid < G_MAXLONG)
	    return PyInt_FromLong(finfo->uid);
	else
	    return PyLong_FromUnsignedLong(finfo->uid);
    } else if (!strcmp(attr, "gid")) {
	if (!(finfo->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_IDS)) {
	    PyErr_SetString(PyExc_ValueError, "gid field has no valid value");
	    return NULL;
	}
	if (finfo->gid < G_MAXLONG)
	    return PyInt_FromLong(finfo->gid);
	else
	    return PyLong_FromUnsignedLong(finfo->gid);
    } else if (!strcmp(attr, "size")) {
	if (!(finfo->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_SIZE)) {
	    PyErr_SetString(PyExc_ValueError, "size field has no valid value");
	    return NULL;
	}
	if (finfo->size <= G_MAXLONG)
	    return PyInt_FromLong(finfo->size);
	else
	    return PyLong_FromUnsignedLongLong(finfo->size);
    } else if (!strcmp(attr, "block_count")) {
	if (!(finfo->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_BLOCK_COUNT)) {
	    PyErr_SetString(PyExc_ValueError,
			    "block_count field has no valid value");
	    return NULL;
	}
	if (finfo->block_count <= G_MAXLONG)
	    return PyInt_FromLong(finfo->block_count);
	else
	    return PyLong_FromUnsignedLongLong(finfo->block_count);
    } else if (!strcmp(attr, "io_block_size")) {
	if (!(finfo->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_IO_BLOCK_SIZE)){
	    PyErr_SetString(PyExc_ValueError,
			    "io_block_size field has no valid value");
	    return NULL;
	}
	if (finfo->io_block_size < G_MAXLONG)
	    return PyInt_FromLong(finfo->io_block_size);
	else
	    return PyLong_FromUnsignedLong(finfo->io_block_size);
    } else if (!strcmp(attr, "atime")) {
	if (!(finfo->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_ATIME)) {
	    PyErr_SetString(PyExc_ValueError,"atime field has no valid value");
	    return NULL;
	}
	return PyLong_FromLongLong(finfo->atime);
    } else if (!strcmp(attr, "mtime")) {
	if (!(finfo->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_MTIME)) {
	    PyErr_SetString(PyExc_ValueError,"mtime field has no valid value");
	    return NULL;
	}
	return PyLong_FromLongLong(finfo->mtime);
    } else if (!strcmp(attr, "ctime")) {
	if (!(finfo->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_CTIME)) {
	    PyErr_SetString(PyExc_ValueError,"ctime field has no valid value");
	    return NULL;
	}
	return PyLong_FromLongLong(finfo->ctime);
    } else if (!strcmp(attr, "symlink_name")) {
	if (!(finfo->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_SYMLINK_NAME)) {
	    PyErr_SetString(PyExc_ValueError,
			    "link_name field has no valid value");
	    return NULL;
	}
	if (finfo->symlink_name)
	    return PyString_FromString(finfo->symlink_name);
	Py_INCREF(Py_None);
	return Py_None;
    } else if (!strcmp(attr, "mime_type")) {
	if (!(finfo->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_MIME_TYPE)) {
	    PyErr_SetString(PyExc_ValueError,
			    "mime_type field has no valid value");
	    return NULL;
	}
	if (finfo->mime_type)
	    return PyString_FromString(finfo->mime_type);
	Py_INCREF(Py_None);
	return Py_None;
    } else {
	PyObject *name = PyString_FromString(attr);
	PyObject *ret = PyObject_GenericGetAttr((PyObject *)self, name);

	Py_DECREF(name);
	return ret;
    }
}