@@ -145,10 +145,10 @@ fz_set_stderr(gctx, JM_fitz_stderr);
145
145
if (JM_fitz_stderr && JM_fitz_stdout)
146
146
{;}
147
147
else
148
- PySys_WriteStdout (" error redirecting stdout/stderr!\n " );
148
+ PySys_WriteStderr (" error redirecting stdout/stderr!\n " );
149
149
150
- JM_error_log = PyList_New ( 0 );
151
- JM_output_log = PyList_New ( 0 );
150
+ JM_error_log = PyByteArray_FromStringAndSize ( " " , 0 );
151
+ JM_output_log = PyByteArray_FromStringAndSize ( " " , 0 );
152
152
153
153
// -----------------------------------------------------------------------------
154
154
// STOP redirect stdout/stderr
@@ -172,6 +172,7 @@ struct DeviceWrapper {
172
172
// include version information and several other helpers
173
173
// -----------------------------------------------------------------------------
174
174
%pythoncode %{
175
+ import os
175
176
import weakref
176
177
from binascii import hexlify
177
178
import math
@@ -211,18 +212,27 @@ struct fz_document_s
211
212
FITZEXCEPTION (fz_document_s, !result)
212
213
213
214
%pythonprepend fz_document_s %{
214
- if not filename or type (filename) == str:
215
+ if not filename or type (filename) is str:
215
216
pass
216
- elif type (filename) == unicode:
217
- filename = filename.encode (' utf8' )
218
217
else :
219
- raise TypeError (" filename must be string or None" )
220
- self.name = filename if filename else " "
218
+ if str is bytes: # Python 2
219
+ if type (filename) is unicode:
220
+ filename = filename.encode (" utf8" )
221
+ else :
222
+ filename = str (filename) # should take care of pathlib
223
+
221
224
self.streamlen = len (stream) if stream else 0
222
- if stream and not (filename or filetype):
223
- raise ValueError (" filetype missing with stream specified" )
224
- if stream and type (stream) not in (bytes, bytearray):
225
- raise ValueError (" stream must be bytes or bytearray" )
225
+
226
+ self.name = " "
227
+ if filename and self.streamlen == 0 :
228
+ self.name = filename
229
+
230
+ if self.streamlen > 0 :
231
+ if not (filename or filetype):
232
+ raise ValueError (" filetype missing with stream specified" )
233
+ if type (stream) not in (bytes, bytearray):
234
+ raise ValueError (" stream must be bytes or bytearray" )
235
+
226
236
self.isClosed = False
227
237
self.isEncrypted = 0
228
238
self.metadata = None
@@ -2102,18 +2112,18 @@ struct fz_page_s {
2102
2112
inklist = pdf_new_array(gctx, annot->page->doc, n0);
2103
2113
for (j = 0; j < n0; j++)
2104
2114
{
2105
- sublist = PySequence_GetItem (list, j);
2115
+ sublist = PySequence_ITEM (list, j);
2106
2116
n1 = PySequence_Size(sublist);
2107
2117
stroke = pdf_new_array(gctx, annot->page->doc, 2 * n1);
2108
2118
for (i = 0; i < n1; i++)
2109
2119
{
2110
- p = PySequence_GetItem (sublist, i);
2120
+ p = PySequence_ITEM (sublist, i);
2111
2121
if (!PySequence_Check(p) || PySequence_Size(p) != 2)
2112
2122
THROWMSG(" 3rd level entries must be pairs of floats" );
2113
- x = PyFloat_AsDouble(PySequence_GetItem (p, 0));
2123
+ x = PyFloat_AsDouble(PySequence_ITEM (p, 0));
2114
2124
if (PyErr_Occurred())
2115
2125
THROWMSG(" invalid point coordinate" );
2116
- y = PyFloat_AsDouble(PySequence_GetItem (p, 1));
2126
+ y = PyFloat_AsDouble(PySequence_ITEM (p, 1));
2117
2127
if (PyErr_Occurred())
2118
2128
THROWMSG(" invalid point coordinate" );
2119
2129
Py_CLEAR(p);
@@ -4559,7 +4569,7 @@ struct fz_annot_s
4559
4569
if (n>0)
4560
4570
{
4561
4571
for (i=0; i<n; i++)
4562
- col[i] = (float) PyFloat_AsDouble(PySequence_GetItem (ccol, i));
4572
+ col[i] = (float) PyFloat_AsDouble(PySequence_ITEM (ccol, i));
4563
4573
fz_try(gctx)
4564
4574
pdf_set_annot_color(gctx, annot, n, col);
4565
4575
fz_catch(gctx)
@@ -4577,7 +4587,7 @@ struct fz_annot_s
4577
4587
return;
4578
4588
}
4579
4589
for (i=0; i<n; i++)
4580
- col[i] = (float) PyFloat_AsDouble(PySequence_GetItem (icol, i));
4590
+ col[i] = (float) PyFloat_AsDouble(PySequence_ITEM (icol, i));
4581
4591
fz_try(gctx)
4582
4592
pdf_set_annot_interior_color(gctx, annot, n, col);
4583
4593
fz_catch(gctx)
@@ -5998,16 +6008,34 @@ struct Tools
5998
6008
}
5999
6009
6000
6010
%pythoncode%{@property%}
6001
- PyObject *fitz_stderr ()
6011
+ char *fitz_stdout ()
6002
6012
{
6003
- return PyUnicode_Join(Py_BuildValue(" s" , " " ), JM_error_log);
6013
+ return PyByteArray_AS_STRING(JM_output_log);
6014
+ }
6015
+
6016
+ %feature(" autodoc" ," Empty fitz output log ." ) empty_error_log;
6017
+ void fitz_stdout_reset()
6018
+ {
6019
+ Py_CLEAR(JM_output_log);
6020
+ JM_output_log = PyByteArray_FromStringAndSize(" " , 0);
6021
+ }
6022
+
6023
+ %pythoncode%{@property%}
6024
+ char *fitz_stderr()
6025
+ {
6026
+ return PyByteArray_AS_STRING(JM_error_log);
6004
6027
}
6005
6028
6006
6029
%feature(" autodoc" ," Empty fitz error log ." ) empty_error_log;
6007
6030
void fitz_stderr_reset()
6008
6031
{
6009
6032
Py_CLEAR(JM_error_log);
6010
- JM_error_log = PyList_New(0);
6033
+ JM_error_log = PyByteArray_FromStringAndSize(" " , 0);
6034
+ }
6035
+
6036
+ char *mupdf_version()
6037
+ {
6038
+ return FZ_VERSION;
6011
6039
}
6012
6040
6013
6041
PyObject *transform_rect(PyObject *rect, PyObject *matrix)
0 commit comments