Correctly declare the parameter annotations as BinaryIO, because in fact it works only with byte-based buffers.
Attempt at running code both before and after this change:
>>> from markdown import Markdown
>>> from io import StringIO, BytesIO
>>> Markdown().convertFile(BytesIO(b'input'), output=BytesIO())
<markdown.core.Markdown object at 0x7fe3bba7c710>
>>> Markdown().convertFile(StringIO('input'), output=BytesIO())
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "markdown/core.py", line 423, in convertFile
text = input_file.read()
^^^^^^^^^^^^^^^^^
File "<frozen codecs>", line 500, in read
TypeError: can't concat str to bytes
>>> Markdown().convertFile(BytesIO(b'input'), output=StringIO())
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "markdown/core.py", line 446, in convertFile
output_file.write(html)
File "<frozen codecs>", line 378, in write
TypeError: string argument expected, got 'bytes'
sys.stdin.read() is always a string, so remove the Python2-specific check.
Correct the patch in the test which incorrectly sets sys.stdin to a bytes buffer which it never is.
sys.stdout.buffer always exists, so remove the Python2-specific fallback.
Correct the patch in the test which incorrectly sets sys.stdout to a bytes buffer which it never is. And fix a matching mistake because this necessitated stdout.read().decode().
Correctly declare the parameter annotations as
BinaryIO
, because in fact it works only with byte-based buffers.Attempt at running code both before and after this change:
sys.stdin.read()
is always a string, so remove the Python2-specific check.sys.stdin
to a bytes buffer which it never is.sys.stdout.buffer
always exists, so remove the Python2-specific fallback.sys.stdout
to a bytes buffer which it never is. And fix a matching mistake because this necessitatedstdout.read().decode()
.