mirror of
https://github.com/thp/pyotherside.git
synced 2025-01-17 23:22:53 +08:00
Python 3.3 unicode strings
This commit is contained in:
parent
16aa5ad2d0
commit
3b0c325fd0
@ -1367,6 +1367,12 @@ Known Problems:
|
||||
ChangeLog
|
||||
=========
|
||||
|
||||
Version UNRELEASED (YYYY-MM-DD)
|
||||
-------------------------------
|
||||
|
||||
* Use `PyUnicode_AsUTF8` from Python 3.3 when converting strings; strings returned
|
||||
from the converter are now valid as long as the `PyObject` is alive (previously
|
||||
they were valid until the next string conversion or until converter was destroyed)
|
||||
|
||||
Version 1.5.9 (2020-01-17)
|
||||
--------------------------
|
||||
|
@ -125,16 +125,13 @@ class PyObjectDictIterator : public DictIterator<PyObject *> {
|
||||
|
||||
class PyObjectConverter : public Converter<PyObject *> {
|
||||
public:
|
||||
PyObjectConverter() : stringcontainer(NULL) {
|
||||
PyObjectConverter() {
|
||||
if (!PyDateTimeAPI) {
|
||||
PyDateTime_IMPORT;
|
||||
}
|
||||
}
|
||||
|
||||
virtual ~PyObjectConverter() {
|
||||
if (stringcontainer != NULL) {
|
||||
Py_DECREF(stringcontainer);
|
||||
}
|
||||
}
|
||||
|
||||
virtual enum Type type(PyObject * const & o) {
|
||||
@ -176,14 +173,7 @@ class PyObjectConverter : public Converter<PyObject *> {
|
||||
virtual long long integer(PyObject *&o) { return PyLong_AsLongLong(o); }
|
||||
virtual double floating(PyObject *&o) { return PyFloat_AsDouble(o); }
|
||||
virtual bool boolean(PyObject *&o) { return (o == Py_True); }
|
||||
virtual const char *string(PyObject *&o) {
|
||||
// XXX: In Python 3.3, we can use PyUnicode_UTF8()
|
||||
if (stringcontainer != NULL) {
|
||||
Py_DECREF(stringcontainer);
|
||||
}
|
||||
stringcontainer = PyUnicode_AsUTF8String(o);
|
||||
return PyBytes_AsString(stringcontainer);
|
||||
}
|
||||
virtual const char *string(PyObject *&o) { return PyUnicode_AsUTF8(o); }
|
||||
virtual QByteArray bytes(PyObject *&o) {
|
||||
return QByteArray(PyBytes_AsString(o), PyBytes_Size(o));
|
||||
}
|
||||
@ -238,9 +228,6 @@ class PyObjectConverter : public Converter<PyObject *> {
|
||||
virtual ListBuilder<PyObject *> *newList() { return new PyObjectListBuilder(); }
|
||||
virtual DictBuilder<PyObject *> *newDict() { return new PyObjectDictBuilder(); }
|
||||
virtual PyObject * none() { Py_RETURN_NONE; }
|
||||
|
||||
private:
|
||||
PyObject *stringcontainer;
|
||||
};
|
||||
|
||||
#endif /* PYOTHERSIDE_PYOBJECT_CONVERTER_H */
|
||||
|
Loading…
x
Reference in New Issue
Block a user