PyObject * PyObject_GetAttr(PyObject *v, PyObject *name) { PyTypeObject *tp = v->ob_type; #ifdef Py_USING_UNICODE /* The Unicode to string conversion is done here because the existing tp_getattro slots expect a string object as name and we wouldn't want to break those. */ if (PyUnicode_Check(name)) { name = _PyUnicode_AsDefaultEncodedString(name, NULL); if (name == NULL) return NULL; } else #endif if (!PyString_Check(name)) { PyErr_SetString(PyExc_TypeError, "attribute name must be string"); return NULL; } if (tp->tp_getattro != NULL) return (*tp->tp_getattro)(v, name); if (tp->tp_getattr != NULL) return (*tp->tp_getattr)(v, PyString_AS_STRING(name)); PyErr_Format(PyExc_AttributeError, "'%.50s' object has no attribute '%.400s'", tp->tp_name, PyString_AS_STRING(name)); return NULL; }
static char *_PyUnicode_AS_STRING( PyObject *unicode ) { #if PYTHON_VERSION < 330 PyObject *bytes = _PyUnicode_AsDefaultEncodedString( unicode, NULL ); if (unlikely( bytes == NULL )) { return NULL; } return PyBytes_AS_STRING( bytes ); #else return PyUnicode_AsUTF8( unicode ); #endif }
static int np_char(char *p, PyObject *v, const formatdef *f) { if (PyUnicode_Check(v)) { v = _PyUnicode_AsDefaultEncodedString(v, NULL); if (v == NULL) return -1; } if (!PyBytes_Check(v) || PyBytes_Size(v) != 1) { PyErr_SetString(StructError, "char format requires bytes or string of length 1"); return -1; } *p = *PyBytes_AsString(v); return 0; }
int BUILTIN_HASATTR_BOOL(PyObject *source, PyObject *attr_name) { CHECK_OBJECT(source); CHECK_OBJECT(attr_name); #if PYTHON_VERSION < 300 if (PyUnicode_Check(attr_name)) { attr_name = _PyUnicode_AsDefaultEncodedString(attr_name, NULL); if (unlikely(attr_name == NULL)) { return -1; } } if (unlikely(!PyString_Check(attr_name))) { PyErr_Format(PyExc_TypeError, "hasattr(): attribute name must be string"); return -1; } #else if (unlikely(!PyUnicode_Check(attr_name))) { PyErr_Format(PyExc_TypeError, "hasattr(): attribute name must be string"); return -1; } #endif PyObject *value = PyObject_GetAttr(source, attr_name); if (value == NULL) { if (PyErr_ExceptionMatches(PyExc_AttributeError)) { CLEAR_ERROR_OCCURRED(); return 0; } return -1; } Py_DECREF(value); return 1; }
static PyObject *aqbanking_Account_transactions(aqbanking_Account* self, PyObject *args, PyObject *kwds) { int rv; double tmpDateTime = 0; const char *bank_code; const char *account_no; #if PY_VERSION_HEX >= 0x03030000 bank_code = PyUnicode_AsUTF8(self->bank_code); account_no = PyUnicode_AsUTF8(self->no); #else PyObject *s = _PyUnicode_AsDefaultEncodedString(self->bank_code, NULL); bank_code = PyBytes_AS_STRING(s); s = _PyUnicode_AsDefaultEncodedString(self->no, NULL); account_no = PyBytes_AS_STRING(s); #endif GWEN_TIME *gwTime; const char *dateFrom=NULL, *dateTo=NULL; static char *kwlist[] = {"dateFrom", "dateTo", NULL}; if (! PyArg_ParseTupleAndKeywords(args, kwds, "|ss", kwlist, &dateFrom, &dateTo)) { return NULL; } AB_ACCOUNT *a; AB_JOB *job = 0; AB_JOB_LIST2 *jl = 0; AB_IMEXPORTER_CONTEXT *ctx = 0; AB_IMEXPORTER_ACCOUNTINFO *ai; /*aqbanking_Transaction *trans = NULL;*/ PyObject *transList = PyList_New(0); // Valid data set? if (self->no == NULL) { PyErr_SetString(PyExc_AttributeError, "no"); } if (self->bank_code == NULL) { PyErr_SetString(PyExc_AttributeError, "bank_code"); } // Initialize aqbanking. rv = AB_create(self); if (rv > 0) { Py_DECREF(transList); return NULL; } // Let us find the account! a = AB_Banking_GetAccountByCodeAndNumber(self->ab, bank_code, account_no); if (!a) { PyErr_SetString(AccountNotFound, "Could not find the given account! "); Py_DECREF(transList); return NULL; } // Create job and execute it. job = AB_JobGetTransactions_new(a); if (dateFrom != NULL) { gwTime = GWEN_Time_fromString(dateFrom, "YYYYMMDD"); AB_JobGetTransactions_SetFromTime(job, gwTime); } if (dateTo != NULL) { gwTime = GWEN_Time_fromString(dateTo, "YYYYMMDD"); AB_JobGetTransactions_SetToTime(job, gwTime); } // Check for availability rv = AB_Job_CheckAvailability(job); if (rv) { PyErr_SetString(ExecutionFailed, "Transaction retrieval is not supported!"); Py_DECREF(transList); return NULL; } jl = AB_Job_List2_new(); AB_Job_List2_PushBack(jl, job); ctx = AB_ImExporterContext_new(); rv = AB_Banking_ExecuteJobs(self->ab, jl, ctx); if (rv) { PyErr_SetString(ExecutionFailed, "Could not retrieve transactions!"); Py_DECREF(transList); return NULL; } // With success. No process the result. ai = AB_ImExporterContext_GetFirstAccountInfo (ctx); while(ai) { const AB_TRANSACTION *t; t = AB_ImExporterAccountInfo_GetFirstTransaction(ai); while(t) { const AB_VALUE *v; AB_TRANSACTION_STATUS state; v=AB_Transaction_GetValue(t); if (v) { const GWEN_STRINGLIST *sl; const GWEN_TIME *tdtime; const char *purpose; const char *remoteName; aqbanking_Transaction *trans = (aqbanking_Transaction*) PyObject_CallObject((PyObject *) &aqbanking_TransactionType, NULL); /* The purpose (memo field) might contain multiple lines. * Therefore AqBanking stores the purpose in a string list * of which the first entry is used in this tutorial */ sl = AB_Transaction_GetPurpose(t); if (sl) { purpose = GWEN_StringList_FirstString(sl); if (purpose == NULL) { purpose = ""; } } else { purpose = ""; } #ifdef DEBUGSTDERR fprintf(stderr, "[%-10d]: [%-10s/%-10s][%-10s/%-10s] %-32s (%.2f %s)\n", AB_Transaction_GetUniqueId(t), AB_Transaction_GetRemoteIban(t), AB_Transaction_GetRemoteBic(t), AB_Transaction_GetRemoteAccountNumber(t), AB_Transaction_GetRemoteBankCode(t), purpose, AB_Value_GetValueAsDouble(v), AB_Value_GetCurrency(v) ); #endif tdtime = AB_Transaction_GetDate(t); tmpDateTime = PyLong_AsDouble(PyLong_FromSize_t(GWEN_Time_Seconds(tdtime))); trans->date = PyDate_FromTimestamp(Py_BuildValue("(O)", PyFloat_FromDouble(tmpDateTime))); tdtime = AB_Transaction_GetValutaDate(t); tmpDateTime = PyLong_AsDouble(PyLong_FromSize_t(GWEN_Time_Seconds(tdtime))); trans->valutaDate = PyDate_FromTimestamp(Py_BuildValue("(O)", PyFloat_FromDouble(tmpDateTime))); trans->purpose = PyUnicode_FromString(purpose); // Local user if (AB_Transaction_GetLocalAccountNumber(t) == NULL) { trans->localAccount = Py_None; Py_INCREF(Py_None); } else { trans->localAccount = PyUnicode_FromString(AB_Transaction_GetLocalAccountNumber(t)); } if (AB_Transaction_GetLocalBankCode(t) == NULL) { trans->localBank = Py_None; Py_INCREF(Py_None); } else { trans->localBank = PyUnicode_FromString(AB_Transaction_GetLocalBankCode(t)); } if (AB_Transaction_GetLocalIban(t) == NULL) { trans->localIban = Py_None; Py_INCREF(Py_None); } else { trans->localIban = PyUnicode_FromString(AB_Transaction_GetLocalIban(t)); } if (AB_Transaction_GetLocalBic(t) == NULL) { trans->localBic = Py_None; Py_INCREF(Py_None); } else { trans->localBic = PyUnicode_FromString(AB_Transaction_GetLocalBic(t)); } if (AB_Transaction_GetLocalName(t) == NULL) { trans->localName = Py_None; Py_INCREF(Py_None); } else { trans->localName = PyUnicode_FromString(AB_Transaction_GetLocalName(t)); } // Remote user if (AB_Transaction_GetRemoteAccountNumber(t) == NULL) { trans->remoteAccount = Py_None; Py_INCREF(Py_None); } else { trans->remoteAccount = PyUnicode_FromString(AB_Transaction_GetRemoteAccountNumber(t)); } if (AB_Transaction_GetRemoteBankCode(t) == NULL) { trans->remoteBank = Py_None; Py_INCREF(Py_None); } else { trans->remoteBank = PyUnicode_FromString(AB_Transaction_GetRemoteBankCode(t)); } if (AB_Transaction_GetRemoteIban(t) == NULL) { trans->remoteIban = Py_None; Py_INCREF(Py_None); } else { trans->remoteIban = PyUnicode_FromString(AB_Transaction_GetRemoteIban(t)); } if (AB_Transaction_GetRemoteBic(t) == NULL) { trans->remoteBic = Py_None; Py_INCREF(Py_None); } else { trans->remoteBic = PyUnicode_FromString(AB_Transaction_GetRemoteBic(t)); } if (AB_Transaction_GetRemoteName(t) == NULL) { trans->remoteName = Py_None; Py_INCREF(Py_None); } else { sl = AB_Transaction_GetRemoteName(t); remoteName = GWEN_StringList_FirstString(sl); if (remoteName == NULL) { trans->remoteName = Py_None; } else { trans->remoteName = PyUnicode_FromString(remoteName); } } trans->value = PyFloat_FromDouble(AB_Value_GetValueAsDouble(v)); trans->currency = PyUnicode_FromString("EUR"); trans->uniqueId = PyLong_FromLong(AB_Transaction_GetUniqueId(t)); if (AB_Transaction_GetTransactionText(t) == NULL) { trans->transactionText = PyUnicode_FromString(""); } else { trans->transactionText = PyUnicode_FromString(AB_Transaction_GetTransactionText(t)); } trans->transactionCode = PyLong_FromLong(AB_Transaction_GetTransactionCode(t)); trans->textKey = PyLong_FromLong(AB_Transaction_GetTextKey(t)); trans->textKeyExt = PyLong_FromLong(AB_Transaction_GetTextKeyExt(t)); if (AB_Transaction_GetMandateId(t) == NULL) { trans->sepaMandateId = Py_None; } else { trans->sepaMandateId = PyUnicode_FromString(AB_Transaction_GetMandateId(t)); } if (AB_Transaction_GetCustomerReference(t) == NULL) { trans->customerReference = PyUnicode_FromString(""); } else { trans->customerReference = PyUnicode_FromString(AB_Transaction_GetCustomerReference(t)); } if (AB_Transaction_GetBankReference(t) == NULL) { trans->bankReference = PyUnicode_FromString(""); } else { trans->bankReference = PyUnicode_FromString(AB_Transaction_GetBankReference(t)); } if (AB_Transaction_GetEndToEndReference(t) == NULL) { trans->endToEndReference = PyUnicode_FromString(""); } else { trans->endToEndReference = PyUnicode_FromString(AB_Transaction_GetEndToEndReference(t)); } trans->state = 0; state = AB_Transaction_GetStatus(t); switch(state) { case AB_Transaction_StatusUnknown: trans->state = -1; break; case AB_Transaction_StatusNone: trans->state = 0; break; case AB_Transaction_StatusAccepted: trans->state = 1; break; case AB_Transaction_StatusRejected: trans->state = 2; break; case AB_Transaction_StatusPending: trans->state = 4; break; case AB_Transaction_StatusSending: trans->state = 8; break; case AB_Transaction_StatusAutoReconciled: trans->state = 16; break; case AB_Transaction_StatusManuallyReconciled: trans->state = 32; break; case AB_Transaction_StatusRevoked: trans->state = 64; break; case AB_Transaction_StatusAborted: trans->state = 128; break; } PyList_Append(transList, (PyObject *)trans); Py_DECREF(trans); } t = AB_ImExporterAccountInfo_GetNextTransaction(ai); } ai = AB_ImExporterContext_GetNextAccountInfo(ctx); } // Free jobs. AB_Job_free(job); AB_Job_List2_free(jl); AB_ImExporterContext_free(ctx); // Exit aqbanking. rv = AB_free(self); if (rv > 0) { //Py_XDECREF(trans); Py_DECREF(transList); return NULL; } return transList; }
static PyObject *aqbanking_Account_available_jobs(aqbanking_Account* self, PyObject *args, PyObject *keywds) { // ##LUS TODO int rv; AB_ACCOUNT *a; const char *bank_code; const char *account_no; #if PY_VERSION_HEX >= 0x03030000 bank_code = PyUnicode_AsUTF8(self->bank_code); account_no = PyUnicode_AsUTF8(self->no); #else PyObject *s = _PyUnicode_AsDefaultEncodedString(self->bank_code, NULL); bank_code = PyBytes_AS_STRING(s); s = _PyUnicode_AsDefaultEncodedString(self->no, NULL); account_no = PyBytes_AS_STRING(s); #endif PyObject *featList = PyList_New(0); // Valid data set? if (self->no == NULL) { PyErr_SetString(PyExc_AttributeError, "no"); } if (self->bank_code == NULL) { PyErr_SetString(PyExc_AttributeError, "bank_code"); } // Initialize aqbanking. rv = AB_create(self); if (rv > 0) { Py_DECREF(featList); return NULL; } // Let us find the account! a = AB_Banking_GetAccountByCodeAndNumber(self->ab, bank_code, account_no); if (!a) { PyErr_SetString(AccountNotFound, "Could not find the given account! "); Py_DECREF(featList); return NULL; } // Check availableJobs // national transfer PyObject *feature; AB_JOB *abJob = AB_JobSingleTransfer_new(a); if (AB_Job_CheckAvailability(abJob) == 0) { feature = PyUnicode_FromString("nationalTransfer"); PyList_Append(featList, (PyObject *)feature); Py_DECREF(feature); } AB_Job_free(abJob); // sepa transfer abJob = AB_JobSepaTransfer_new(a); if (AB_Job_CheckAvailability(abJob) == 0) { feature = PyUnicode_FromString("sepaTransfer"); PyList_Append(featList, (PyObject *)feature); Py_DECREF(feature); } AB_Job_free(abJob); PyList_Append(featList, (PyObject *)feature); Py_DECREF(feature); // Exit aqbanking. rv = AB_free(self); if (rv > 0) { Py_DECREF(featList); return NULL; } return featList; }
static PyObject *aqbanking_Account_balance(aqbanking_Account* self, PyObject *args, PyObject *keywds) { const AB_ACCOUNT_STATUS * status; const AB_BALANCE * bal; const AB_VALUE *v = 0; int rv; double balance; const char *bank_code; const char *account_no; #if PY_VERSION_HEX >= 0x03030000 bank_code = PyUnicode_AsUTF8(self->bank_code); account_no = PyUnicode_AsUTF8(self->no); #else PyObject *s = _PyUnicode_AsDefaultEncodedString(self->bank_code, NULL); bank_code = PyBytes_AS_STRING(s); s = _PyUnicode_AsDefaultEncodedString(self->no, NULL); account_no = PyBytes_AS_STRING(s); #endif AB_ACCOUNT *a; AB_JOB *job = 0; AB_JOB_LIST2 *jl = 0; AB_IMEXPORTER_CONTEXT *ctx = 0; AB_IMEXPORTER_ACCOUNTINFO *ai; // Valid data set? if (self->no == NULL) { PyErr_SetString(PyExc_AttributeError, "no"); } if (self->bank_code == NULL) { PyErr_SetString(PyExc_AttributeError, "bank_code"); } // Initialize aqbanking. rv = AB_create(self); if (rv > 0) { return NULL; } // Let us find the account! a = AB_Banking_GetAccountByCodeAndNumber(self->ab, bank_code, account_no); if (!a) { PyErr_SetString(AccountNotFound, "Could not find the given account! "); return NULL; } // Create job and execute it. ctx = AB_ImExporterContext_new(); jl = AB_Job_List2_new(); job = AB_JobGetBalance_new(a); AB_Job_List2_PushBack(jl, job); rv = AB_Banking_ExecuteJobs(self->ab, jl, ctx); if (rv) { PyErr_SetString(ExecutionFailed, "Could not get the balance!"); return NULL; } // With success. No process the result. ai = AB_ImExporterContext_GetFirstAccountInfo (ctx); status = AB_ImExporterAccountInfo_GetFirstAccountStatus (ai); bal = AB_AccountStatus_GetBookedBalance (status); v = AB_Balance_GetValue (bal); balance = AB_Value_GetValueAsDouble(v); // Free jobs. AB_Job_List2_free(jl); AB_ImExporterContext_free(ctx); // Exit aqbanking. rv = AB_free(self); if (rv > 0) { return NULL; } // FIXME: currency! return Py_BuildValue("(d,s)", balance, "EUR"); }
static CYTHON_INLINE char* __Pyx_PyObject_AsStringAndSize(PyObject* o, Py_ssize_t *length) { #if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT if ( #if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII __Pyx_sys_getdefaultencoding_not_ascii && #endif PyUnicode_Check(o)) { #if PY_VERSION_HEX < 0x03030000 char* defenc_c; // borrowed, cached reference PyObject* defenc = _PyUnicode_AsDefaultEncodedString(o, NULL); if (!defenc) return NULL; defenc_c = PyBytes_AS_STRING(defenc); #if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII { char* end = defenc_c + PyBytes_GET_SIZE(defenc); char* c; for (c = defenc_c; c < end; c++) { if ((unsigned char) (*c) >= 128) { // raise the error PyUnicode_AsASCIIString(o); return NULL; } } } #endif /*__PYX_DEFAULT_STRING_ENCODING_IS_ASCII*/ *length = PyBytes_GET_SIZE(defenc); return defenc_c; #else /* PY_VERSION_HEX < 0x03030000 */ if (PyUnicode_READY(o) == -1) return NULL; #if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII if (PyUnicode_IS_ASCII(o)) { // cached for the lifetime of the object *length = PyUnicode_GET_DATA_SIZE(o); return PyUnicode_AsUTF8(o); } else { // raise the error PyUnicode_AsASCIIString(o); return NULL; } #else /* __PYX_DEFAULT_STRING_ENCODING_IS_ASCII */ return PyUnicode_AsUTF8AndSize(o, length); #endif /* __PYX_DEFAULT_STRING_ENCODING_IS_ASCII */ #endif /* PY_VERSION_HEX < 0x03030000 */ } else #endif /* __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT */ #if PY_VERSION_HEX >= 0x02060000 if (PyByteArray_Check(o)) { *length = PyByteArray_GET_SIZE(o); return PyByteArray_AS_STRING(o); } else #endif { char* result; int r = PyBytes_AsStringAndSize(o, &result, length); if (unlikely(r < 0)) { return NULL; } else { return result; } } }
NUITKA_MAY_BE_UNUSED static PyObject *TO_UNICODE3( PyObject *value, PyObject *encoding, PyObject *errors ) { CHECK_OBJECT( value ); if ( encoding ) CHECK_OBJECT( encoding ); if ( errors ) CHECK_OBJECT( errors ); char *encoding_str; if ( encoding == NULL ) { encoding_str = NULL; } else if ( Nuitka_String_Check( encoding ) ) { encoding_str = Nuitka_String_AsString_Unchecked( encoding ); } #if PYTHON_VERSION < 300 else if ( PyUnicode_Check( encoding ) ) { PyObject *uarg2 = _PyUnicode_AsDefaultEncodedString( encoding, NULL ); CHECK_OBJECT( uarg2 ); encoding_str = Nuitka_String_AsString_Unchecked( uarg2 ); } #endif else { PyErr_Format( PyExc_TypeError, "unicode() argument 2 must be string, not %s", Py_TYPE( encoding )->tp_name ); return NULL; } char *errors_str; if ( errors == NULL ) { errors_str = NULL; } else if ( Nuitka_String_Check( errors ) ) { errors_str = Nuitka_String_AsString_Unchecked( errors ); } #if PYTHON_VERSION < 300 else if ( PyUnicode_Check( errors ) ) { PyObject *uarg3 = _PyUnicode_AsDefaultEncodedString( errors, NULL ); CHECK_OBJECT( uarg3 ); errors_str = Nuitka_String_AsString_Unchecked( uarg3 ); } #endif else { PyErr_Format( PyExc_TypeError, "unicode() argument 3 must be string, not %s", Py_TYPE( errors )->tp_name ); return NULL; } PyObject *result = PyUnicode_FromEncodedObject( value, encoding_str, errors_str ); if (unlikely( result == NULL )) { return NULL; } assert( PyUnicode_Check( result ) ); return result; }
static char * convertsimple1(PyObject *arg, char **p_format, va_list *p_va) { char *format = *p_format; char c = *format++; switch (c) { case 'b': /* unsigned byte -- very short int */ { char *p = va_arg(*p_va, char *); long ival = PyInt_AsLong(arg); if (ival == -1 && PyErr_Occurred()) return "integer<b>"; else if (ival < 0) { PyErr_SetString(PyExc_OverflowError, "unsigned byte integer is less than minimum"); return "integer<b>"; } else if (ival > UCHAR_MAX) { PyErr_SetString(PyExc_OverflowError, "unsigned byte integer is greater than maximum"); return "integer<b>"; } else *p = (unsigned char) ival; break; } case 'B': /* byte sized bitfield - both signed and unsigned values allowed */ { char *p = va_arg(*p_va, char *); long ival = PyInt_AsLong(arg); if (ival == -1 && PyErr_Occurred()) return "integer<b>"; else if (ival < SCHAR_MIN) { PyErr_SetString(PyExc_OverflowError, "byte-sized integer bitfield is less than minimum"); return "integer<B>"; } else if (ival > (int)UCHAR_MAX) { PyErr_SetString(PyExc_OverflowError, "byte-sized integer bitfield is greater than maximum"); return "integer<B>"; } else *p = (unsigned char) ival; break; } case 'h': /* signed short int */ { short *p = va_arg(*p_va, short *); long ival = PyInt_AsLong(arg); if (ival == -1 && PyErr_Occurred()) return "integer<h>"; else if (ival < SHRT_MIN) { PyErr_SetString(PyExc_OverflowError, "signed short integer is less than minimum"); return "integer<h>"; } else if (ival > SHRT_MAX) { PyErr_SetString(PyExc_OverflowError, "signed short integer is greater than maximum"); return "integer<h>"; } else *p = (short) ival; break; } case 'H': /* short int sized bitfield, both signed and unsigned allowed */ { unsigned short *p = va_arg(*p_va, unsigned short *); long ival = PyInt_AsLong(arg); if (ival == -1 && PyErr_Occurred()) return "integer<H>"; else if (ival < SHRT_MIN) { PyErr_SetString(PyExc_OverflowError, "short integer bitfield is less than minimum"); return "integer<H>"; } else if (ival > USHRT_MAX) { PyErr_SetString(PyExc_OverflowError, "short integer bitfield is greater than maximum"); return "integer<H>"; } else *p = (unsigned short) ival; break; } case 'i': /* signed int */ { int *p = va_arg(*p_va, int *); long ival = PyInt_AsLong(arg); if (ival == -1 && PyErr_Occurred()) return "integer<i>"; else if (ival > INT_MAX) { PyErr_SetString(PyExc_OverflowError, "signed integer is greater than maximum"); return "integer<i>"; } else if (ival < INT_MIN) { PyErr_SetString(PyExc_OverflowError, "signed integer is less than minimum"); return "integer<i>"; } else *p = ival; break; } case 'l': /* long int */ { long *p = va_arg(*p_va, long *); long ival = PyInt_AsLong(arg); if (ival == -1 && PyErr_Occurred()) return "integer<l>"; else *p = ival; break; } #ifdef HAVE_LONG_LONG case 'L': /* LONG_LONG */ { LONG_LONG *p = va_arg( *p_va, LONG_LONG * ); LONG_LONG ival = PyLong_AsLongLong( arg ); if( ival == (LONG_LONG)-1 && PyErr_Occurred() ) { return "long<L>"; } else { *p = ival; } break; } #endif case 'f': /* float */ { float *p = va_arg(*p_va, float *); double dval = PyFloat_AsDouble(arg); if (PyErr_Occurred()) return "float<f>"; else *p = (float) dval; break; } case 'd': /* double */ { double *p = va_arg(*p_va, double *); double dval = PyFloat_AsDouble(arg); if (PyErr_Occurred()) return "float<d>"; else *p = dval; break; } #ifndef WITHOUT_COMPLEX case 'D': /* complex double */ { Py_complex *p = va_arg(*p_va, Py_complex *); Py_complex cval; cval = PyComplex_AsCComplex(arg); if (PyErr_Occurred()) return "complex<D>"; else *p = cval; break; } #endif /* WITHOUT_COMPLEX */ case 'c': /* char */ { char *p = va_arg(*p_va, char *); if (PyString_Check(arg) && PyString_Size(arg) == 1) *p = PyString_AsString(arg)[0]; else return "char"; break; } case 's': /* string */ { if (*format == '#') { void **p = (void **)va_arg(*p_va, char **); int *q = va_arg(*p_va, int *); if (PyString_Check(arg)) { *p = PyString_AS_STRING(arg); *q = PyString_GET_SIZE(arg); } else if (PyUnicode_Check(arg)) { arg = _PyUnicode_AsDefaultEncodedString( arg, NULL); if (arg == NULL) return "unicode conversion error"; *p = PyString_AS_STRING(arg); *q = PyString_GET_SIZE(arg); } else { /* any buffer-like object */ PyBufferProcs *pb = arg->ob_type->tp_as_buffer; int count; if ( pb == NULL || pb->bf_getreadbuffer == NULL || pb->bf_getsegcount == NULL ) return "read-only buffer"; if ( (*pb->bf_getsegcount)(arg, NULL) != 1 ) return "single-segment read-only buffer"; if ( (count = (*pb->bf_getreadbuffer)(arg, 0, p)) < 0 ) return "(unspecified)"; *q = count; } format++; } else { char **p = va_arg(*p_va, char **); if (PyString_Check(arg)) *p = PyString_AS_STRING(arg); else if (PyUnicode_Check(arg)) { arg = _PyUnicode_AsDefaultEncodedString( arg, NULL); if (arg == NULL) return "unicode conversion error"; *p = PyString_AS_STRING(arg); } else return "string"; if ((int)strlen(*p) != PyString_Size(arg)) return "string without null bytes"; } break; }