diff options
author | Todd Leonhardt <todd.leonhardt@gmail.com> | 2018-10-09 20:04:50 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-09 20:04:50 -0400 |
commit | f38e100fd77f4a136a4883d23b2f4f8b3cd934b7 (patch) | |
tree | c289c216807646567953191d35ebdc5c07198c24 /cmd2/utils.py | |
parent | 467be57e647112f536becc8625ffa080cb67a0ce (diff) | |
parent | 84f290bfdd82eb1c2eaf26b5936f7088b4911f2c (diff) | |
download | cmd2-git-f38e100fd77f4a136a4883d23b2f4f8b3cd934b7.tar.gz |
Merge pull request #571 from python-cmd2/argparse_remainder
Fixes related to handling of argparse.REMAINDER
Diffstat (limited to 'cmd2/utils.py')
-rw-r--r-- | cmd2/utils.py | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/cmd2/utils.py b/cmd2/utils.py index 501733a9..d4a3db2f 100644 --- a/cmd2/utils.py +++ b/cmd2/utils.py @@ -255,10 +255,13 @@ class StdSim(object): """ class ByteBuf(object): """Inner class which stores an actual bytes buffer and does the actual output if echo is enabled.""" - def __init__(self, inner_stream, echo: bool = False) -> None: + def __init__(self, inner_stream, echo: bool = False, + encoding: str='utf-8', errors: str='replace') -> None: self.byte_buf = b'' self.inner_stream = inner_stream self.echo = echo + self.encoding = encoding + self.errors = errors def write(self, b: bytes) -> None: """Add bytes to internal bytes buffer and if echo is True, echo contents to inner stream.""" @@ -266,7 +269,10 @@ class StdSim(object): raise TypeError('a bytes-like object is required, not {}'.format(type(b))) self.byte_buf += b if self.echo: - self.inner_stream.buffer.write(b) + if hasattr(self.inner_stream, 'buffer'): + self.inner_stream.buffer.write(b) + else: + self.inner_stream.write(b.decode(encoding=self.encoding, errors=self.errors)) def __init__(self, inner_stream, echo: bool = False, encoding: str='utf-8', errors: str='replace') -> None: |