@@ -254,21 +254,21 @@ def _cleanup_remaining_instances():
254
254
latex_manager ._cleanup ()
255
255
256
256
def _stdin_writeln (self , s ):
257
- self .latex_stdin_utf8 .write (s )
258
- self .latex_stdin_utf8 .write ("\n " )
259
- self .latex_stdin_utf8 .flush ()
257
+ self .latex . stdin .write (s )
258
+ self .latex . stdin .write ("\n " )
259
+ self .latex . stdin .flush ()
260
260
261
261
def _expect (self , s ):
262
- exp = s . encode ( "utf8" )
263
- buf = bytearray ()
262
+ s = list ( s )
263
+ chars = []
264
264
while True :
265
- b = self .latex .stdout .read (1 )
266
- buf += b
267
- if buf [- len (exp ):] == exp :
265
+ c = self .latex .stdout .read (1 )
266
+ chars . append ( c )
267
+ if chars [- len (s ):] == s :
268
268
break
269
- if not len ( b ) :
270
- raise LatexError ("LaTeX process halted" , buf . decode ( "utf8" ))
271
- return buf . decode ( "utf8" )
269
+ if not c :
270
+ raise LatexError ("LaTeX process halted" , "" . join ( chars ))
271
+ return "" . join ( chars )
272
272
273
273
def _expect_prompt (self ):
274
274
return self ._expect ("\n *" )
@@ -287,28 +287,27 @@ def __init__(self):
287
287
self .latex_header = LatexManager ._build_latex_header ()
288
288
latex_end = "\n \\ makeatletter\n \\ @@end\n "
289
289
try :
290
- latex = subprocess .Popen ([ self . texcommand , "-halt-on-error" ],
291
- stdin = subprocess . PIPE ,
292
- stdout = subprocess .PIPE ,
293
- cwd = self .tmpdir )
290
+ latex = subprocess .Popen (
291
+ [ self . texcommand , "-halt-on-error" ] ,
292
+ stdin = subprocess . PIPE , stdout = subprocess .PIPE ,
293
+ encoding = "utf-8" , cwd = self .tmpdir )
294
294
except FileNotFoundError :
295
295
raise RuntimeError (
296
296
"Latex command not found. Install %r or change "
297
297
"pgf.texsystem to the desired command." % self .texcommand )
298
298
except OSError :
299
299
raise RuntimeError ("Error starting process %r" % self .texcommand )
300
300
test_input = self .latex_header + latex_end
301
- stdout , stderr = latex .communicate (test_input . encode ( "utf-8" ) )
301
+ stdout , stderr = latex .communicate (test_input )
302
302
if latex .returncode != 0 :
303
303
raise LatexError ("LaTeX returned an error, probably missing font "
304
304
"or error in preamble:\n %s" % stdout )
305
305
306
306
# open LaTeX process for real work
307
- latex = subprocess .Popen ([self .texcommand , "-halt-on-error" ],
308
- stdin = subprocess .PIPE , stdout = subprocess .PIPE ,
309
- cwd = self .tmpdir )
310
- self .latex = latex
311
- self .latex_stdin_utf8 = codecs .getwriter ("utf8" )(self .latex .stdin )
307
+ self .latex = subprocess .Popen (
308
+ [self .texcommand , "-halt-on-error" ],
309
+ stdin = subprocess .PIPE , stdout = subprocess .PIPE ,
310
+ encoding = "utf-8" , cwd = self .tmpdir )
312
311
# write header with 'pgf_backend_query_start' token
313
312
self ._stdin_writeln (self ._build_latex_header ())
314
313
# read all lines until our 'pgf_backend_query_start' token appears
@@ -318,13 +317,15 @@ def __init__(self):
318
317
# cache for strings already processed
319
318
self .str_cache = {}
320
319
320
+ @cbook .deprecated ("3.3" )
321
+ def latex_stdin_utf8 (self ):
322
+ return self .latex .stdin
323
+
321
324
def _cleanup (self ):
322
325
if not self ._os_path .isdir (self .tmpdir ):
323
326
return
324
327
try :
325
328
self .latex .communicate ()
326
- self .latex_stdin_utf8 .close ()
327
- self .latex .stdout .close ()
328
329
except Exception :
329
330
pass
330
331
try :
0 commit comments