File tree Expand file tree Collapse file tree 1 file changed +8
-2
lines changed
Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -255,18 +255,24 @@ class StdSim(object):
255255 """
256256 class ByteBuf (object ):
257257 """Inner class which stores an actual bytes buffer and does the actual output if echo is enabled."""
258- def __init__ (self , inner_stream , echo : bool = False ) -> None :
258+ def __init__ (self , inner_stream , echo : bool = False ,
259+ encoding : str = 'utf-8' , errors : str = 'replace' ) -> None :
259260 self .byte_buf = b''
260261 self .inner_stream = inner_stream
261262 self .echo = echo
263+ self .encoding = encoding
264+ self .errors = errors
262265
263266 def write (self , b : bytes ) -> None :
264267 """Add bytes to internal bytes buffer and if echo is True, echo contents to inner stream."""
265268 if not isinstance (b , bytes ):
266269 raise TypeError ('a bytes-like object is required, not {}' .format (type (b )))
267270 self .byte_buf += b
268271 if self .echo :
269- self .inner_stream .buffer .write (b )
272+ if hasattr (self .inner_stream , 'buffer' ):
273+ self .inner_stream .buffer .write (b )
274+ else :
275+ self .inner_stream .write (b .decode (encoding = self .encoding , errors = self .errors ))
270276
271277 def __init__ (self , inner_stream , echo : bool = False ,
272278 encoding : str = 'utf-8' , errors : str = 'replace' ) -> None :
You can’t perform that action at this time.
0 commit comments