@@ -254,21 +254,21 @@ def _cleanup_remaining_instances():
254254 latex_manager ._cleanup ()
255255
256256 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 ()
260260
261261 def _expect (self , s ):
262- exp = s . encode ( "utf8" )
263- buf = bytearray ()
262+ s = list ( s )
263+ chars = []
264264 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 :
268268 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 )
272272
273273 def _expect_prompt (self ):
274274 return self ._expect ("\n *" )
@@ -287,28 +287,27 @@ def __init__(self):
287287 self .latex_header = LatexManager ._build_latex_header ()
288288 latex_end = "\n \\ makeatletter\n \\ @@end\n "
289289 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 )
294294 except FileNotFoundError :
295295 raise RuntimeError (
296296 "Latex command not found. Install %r or change "
297297 "pgf.texsystem to the desired command." % self .texcommand )
298298 except OSError :
299299 raise RuntimeError ("Error starting process %r" % self .texcommand )
300300 test_input = self .latex_header + latex_end
301- stdout , stderr = latex .communicate (test_input . encode ( "utf-8" ) )
301+ stdout , stderr = latex .communicate (test_input )
302302 if latex .returncode != 0 :
303303 raise LatexError ("LaTeX returned an error, probably missing font "
304304 "or error in preamble:\n %s" % stdout )
305305
306306 # 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 )
312311 # write header with 'pgf_backend_query_start' token
313312 self ._stdin_writeln (self ._build_latex_header ())
314313 # read all lines until our 'pgf_backend_query_start' token appears
@@ -318,13 +317,15 @@ def __init__(self):
318317 # cache for strings already processed
319318 self .str_cache = {}
320319
320+ @cbook .deprecated ("3.3" )
321+ def latex_stdin_utf8 (self ):
322+ return self .latex .stdin
323+
321324 def _cleanup (self ):
322325 if not self ._os_path .isdir (self .tmpdir ):
323326 return
324327 try :
325328 self .latex .communicate ()
326- self .latex_stdin_utf8 .close ()
327- self .latex .stdout .close ()
328329 except Exception :
329330 pass
330331 try :
0 commit comments