Skip to content

Commit 540e35f

Browse files
committed
fix issues with non-ascii characters in paradox files
1 parent 99151a4 commit 540e35f

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

pxpy.pyx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ import datetime
2222
cdef extern from "Python.h":
2323
object PyString_FromStringAndSize(char *s, int len)
2424
object PyString_Decode(char *s, int len, char *encoding, char *errors)
25+
object PyString_FromStringAndSize(char *v, int len)
26+
object PyString_AsDecodedObject(object str, char *encoding, char *errors)
27+
2528

2629
cdef extern from "string.h":
2730
int strnlen(char *s, int maxlen)
@@ -369,8 +372,10 @@ cdef class Field:
369372
if size==0:
370373
return None
371374
else:
372-
return PyString_Decode(<char*> self.data, size,
373-
codepage, "replace")
375+
py_string = PyString_FromStringAndSize(<char*> self.data, size);
376+
if not py_string:
377+
raise "Cannot get value from string %s" % self.fname
378+
return PyString_AsDecodedObject(py_string, codepage, "replace")
374379

375380
elif self.ftype == pxfDate:
376381
if PX_get_data_long(self.record.table.doc,
@@ -423,7 +428,10 @@ cdef class Field:
423428
&mod_nr, &size)
424429
if blobdata and size>0:
425430
codepage = self.record.table.getCodePage()
426-
return PyString_Decode(blobdata, size, codepage, "replace")
431+
py_string = PyString_FromStringAndSize(<char*> blobdata, size);
432+
if not py_string:
433+
raise "Cannot get value from string %s" % self.fname
434+
return PyString_AsDecodedObject(py_string, codepage, "replace")
427435

428436
elif self.ftype in [pxfBLOb, pxfGraphic]:
429437
if not self.record.table.blob:

0 commit comments

Comments
 (0)