Use bytes type consistently #75

Closed
opened 2022-05-16 19:51:27 +02:00 by pfm · 7 comments
Collaborator

Since Python 3.x uses bytes for I/O and IPC, and we only did an automatic migration from 2.x to 3.x, we didn't take care of the types.

To ensure stable operation, we need to:

  1. Unify the type used to handle messages internally.
  2. Convert between types at boundaries when necessary.
Since Python 3.x uses `bytes` for I/O and IPC, and we only did an automatic migration from 2.x to 3.x, we didn't take care of the types. To ensure stable operation, we need to: 1. Unify the type used to handle messages internally. 2. Convert between types at boundaries when necessary.
pfm self-assigned this 2022-05-16 19:51:35 +02:00
pfm added the
BUG
ISSUE
labels 2022-05-16 19:53:24 +02:00
Author
Collaborator

Traceback:

File "/opt/gpg-lacre/gpg-mailgate.py", line 436, in <module>
  sort_recipients(raw_message, from_addr, to_addrs)
File "/opt/gpg-lacre/gpg-mailgate.py", line 410, in sort_recipients
  recipients_left = gpg_encrypt(raw_message, recipients_left)
File "/opt/gpg-lacre/gpg-mailgate.py", line 138, in gpg_encrypt
  encrypted_payloads = encrypt_all_payloads_mime( raw_message_mime, gpg_to_cmdline_mime )
File "/opt/gpg-lacre/gpg-mailgate.py", line 200, in encrypt_all_payloads_mime
  submsg2.set_payload(additionalSubHeader+"\n"+message.get_payload(decode=True))
TypeError: can only concatenate str (not "bytes") to str
Traceback: ``` File "/opt/gpg-lacre/gpg-mailgate.py", line 436, in <module> sort_recipients(raw_message, from_addr, to_addrs) File "/opt/gpg-lacre/gpg-mailgate.py", line 410, in sort_recipients recipients_left = gpg_encrypt(raw_message, recipients_left) File "/opt/gpg-lacre/gpg-mailgate.py", line 138, in gpg_encrypt encrypted_payloads = encrypt_all_payloads_mime( raw_message_mime, gpg_to_cmdline_mime ) File "/opt/gpg-lacre/gpg-mailgate.py", line 200, in encrypt_all_payloads_mime submsg2.set_payload(additionalSubHeader+"\n"+message.get_payload(decode=True)) TypeError: can only concatenate str (not "bytes") to str ```
Author
Collaborator

It seems that sys.stdin.read() can only return str.

It seems that `sys.stdin.read()` can only return `str`.
pfm added reference 75-unify-types 2022-05-16 20:59:30 +02:00
pfm added this to the Test deployment findings milestone 2022-05-16 21:43:38 +02:00
Author
Collaborator

The plan:

  1. Identify components that expect or produce a specific data representation (either bytes or str).
  2. Identify types used at boundaries, i.e. for consuming input and producing output.
  3. Design a coherent data flow ensuring each of the constraints above is taken into account.
The plan: 1. Identify components that expect or produce a specific data representation (either `bytes` or `str`). 2. Identify types used at boundaries, i.e. for consuming input and producing output. 3. Design a coherent data flow ensuring each of the constraints above is taken into account.
Author
Collaborator

Python's built-in package email always produces str, regardless of the input type. See EmailParsingTest in commit 558872d9d0.

Python's built-in package `email` always produces `str`, regardless of the input type. See `EmailParsingTest` in commit [558872d9d0](https://git.disroot.org/Disroot/gpg-lacre/commit/558872d9d0bc559e76aaaf91c8ac70113bb236ba).
Owner

So do we need to then convert everything pushed to email t str?

So do we need to then convert everything pushed to email t str?
Author
Collaborator

I don't think so, email accepts anything but produces a str.

I haven't finished analysing the flow, just dumping findings here -- I hope you don't mind. (Just don't want it to disappear if something happens to my laptop, or to me.)

I don't think so, `email` accepts anything but *produces* a `str`. I haven't finished analysing the flow, just dumping findings here -- I hope you don't mind. (Just don't want it to disappear if something happens to my laptop, or to me.)
Author
Collaborator

Fixed with #82.

Fixed with #82.
pfm closed this issue 2022-06-02 00:46:28 +02:00
Sign in to join this conversation.
No description provided.