mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Use mbcs encoding when passing filenames to windows
This commit is contained in:
parent
470e6b56fe
commit
5e7c625685
@ -163,6 +163,7 @@ def test_save_to(src, dest):
|
||||
|
||||
|
||||
def test_podofo():
|
||||
import tempfile
|
||||
from io import BytesIO
|
||||
from calibre.ebooks.metadata.book.base import Metadata
|
||||
from calibre.ebooks.metadata.xmp import metadata_to_xmp_packet
|
||||
@ -178,14 +179,19 @@ def test_podofo():
|
||||
buf = BytesIO()
|
||||
p.save_to_fileobj(buf)
|
||||
raw = buf.getvalue()
|
||||
p = podofo.PDFDoc()
|
||||
p.load(raw)
|
||||
if (p.title, p.author) != (mi.title, mi.authors[0]):
|
||||
raise ValueError('podofo failed to set title and author in Info dict %s != %s' % (
|
||||
(p.title, p.author), (mi.title, mi.authors[0])))
|
||||
if not p.get_xmp_metadata():
|
||||
raise ValueError('podofo failed to write XMP packet')
|
||||
del p
|
||||
with tempfile.NamedTemporaryFile(suffix='.pdf', delete=False) as f:
|
||||
f.write(raw)
|
||||
try:
|
||||
p = podofo.PDFDoc()
|
||||
p.open(f.name)
|
||||
if (p.title, p.author) != (mi.title, mi.authors[0]):
|
||||
raise ValueError('podofo failed to set title and author in Info dict %s != %s' % (
|
||||
(p.title, p.author), (mi.title, mi.authors[0])))
|
||||
if not p.get_xmp_metadata():
|
||||
raise ValueError('podofo failed to write XMP packet')
|
||||
del p
|
||||
finally:
|
||||
os.remove(f.name)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
@ -62,16 +62,21 @@ PDFDoc_load(PDFDoc *self, PyObject *args) {
|
||||
static PyObject *
|
||||
PDFDoc_open(PDFDoc *self, PyObject *args) {
|
||||
char *fname;
|
||||
|
||||
if (PyArg_ParseTuple(args, "s", &fname)) {
|
||||
try {
|
||||
self->doc->Load(fname);
|
||||
} catch(const PdfError & err) {
|
||||
podofo_set_exception(err);
|
||||
return NULL;
|
||||
}
|
||||
} else return NULL;
|
||||
|
||||
#ifdef _WIN32
|
||||
#define ENCODING "mbcs"
|
||||
#else
|
||||
#define ENCODING "utf-8"
|
||||
#endif
|
||||
if (!PyArg_ParseTuple(args, "es", ENCODING, &fname)) return NULL;
|
||||
#undef ENCODING
|
||||
try {
|
||||
self->doc->Load(fname);
|
||||
} catch(const PdfError & err) {
|
||||
podofo_set_exception(err);
|
||||
PyMem_Free(fname);
|
||||
return NULL;
|
||||
}
|
||||
PyMem_Free(fname);
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user