New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: introduce ProblemReport._write_base64_encoded_line #238
Conversation
Codecov Report
@@ Coverage Diff @@
## main #238 +/- ##
===========================================
+ Coverage 73.16% 83.69% +10.52%
===========================================
Files 91 93 +2
Lines 18031 18756 +725
===========================================
+ Hits 13193 15698 +2505
+ Misses 4838 3058 -1780
|
Introduce `ProblemReport._write_base64_encoded_line` which writes one line of a RFC822 multiline. This will write blocks line by line instead of writing the leading space after writing a line. Signed-off-by: Benjamin Drung <benjamin.drung@canonical.com>
7e01fbf
to
9f853d3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you put the cursor far enough in the refactoring. The new method is still a footgun, as it requires the caller to actually prepare the terrain first by writing out the RFC822 key and base64 header, which means the base64-specific knowledge is split in two places.
Instead, I suggest having something like this:
def _write_base64_paragraph(file, typing.BinaryIO, key: str, data: list[bytes]):
"""Write the data out in a RFC 822 base64 multiline paragraph, using one line per item in the data list.
"""
This would even make the control flow a bit easier in _write_key_and_binary_value_compressed_and_encoded_to_file
(wow that name is a handful, typing it out takes forever). You don't have to rewind the file in case of aborted write, you just never call the helper method :)
issue: |
Meh, that's barely relevant 😉. Maybe have def _binary_chunks_from_value(v: Any) -> Generator[bytes, None, None]:
pass
def _write_base64_paragraph(file, typing.BinaryIO, key: str, data: Iterable[bytes]):
pass
def _write_key_and_binary_value_compressed_and_encoded_to_file(
self, file: typing.BinaryIO, key: str
) -> None:
_write_base64_paragraph(key, file, _binary_chunks_from_value(self.data[key])) With WDYT? |
That idea sounds promising. Do you want to implement it or should I give it a try? |
I'll give it a shot. |
Closing this PR in favor of #242. |
Introduce
ProblemReport._write_base64_encoded_line
which writes one line of a RFC822 multiline. This will write blocks line by line instead of writing the leading space after writing a line.