Fix render_markdown_from_file() on Python 3.

Review Request #11766 — Created Aug. 1, 2021 and submitted

Information

Djblets
release-2.x

Reviewers

render_markdown_from_file() was using a cStringIO as the file
output, which wasn't compatible with the results from
markdownFromFile() on Python 3. This wasn't caught due to the lack of
unit tests for this function.

Now, the stream is written to a io.BytesIO. Missing documentation was
added that specifies that the input stream must be a byte stream.

Along with this, the code has been made safer from leaks by closing the
outgoing stream in a finally: clause. While this shouldn't technically
be necessary (garbage collection should handle closing this for us), it
is slightly more correct.

A unit test was added to ensure this works on Python 2 and 3.

Unit tests pass on Python 2 and 3.

Without the fix, the test fails on Python 3 .

Summary ID
Fix render_markdown_from_file() on Python 3.
`render_markdown_from_file()` was using a `cStringIO` as the file output, which wasn't compatible with the results from `markdownFromFile()` on Python 3. This wasn't caught due to the lack of unit tests for this function. Now, the stream is written to a `io.BytesIO`. Missing documentation was added that specifies that the input stream must be a byte stream. Along with this, the code has been made safer from leaks by closing the outgoing stream in a `finally:` clause. While this shouldn't technically be necessary (garbage collection should handle closing this for us), it is slightly more correct.
992539a2ab1271c228b1a8a85bccfe436ee7ed18
david
  1. Ship It!
  2. 
      
chipx86
Review request changed

Status: Closed (submitted)

Change Summary:

Pushed to release-2.x (1b1a5e6)
Loading...