Changes between Initial Version and Version 1 of Ticket #31375, comment 3


Ignore:
Timestamp:
Mar 18, 2020, 3:09:38 PM (5 years ago)
Author:
iamdavidcz

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #31375, comment 3

    initial v1  
    34342. Change `force_bytes` utility to `to_bytes` and add default keyword argument `force=True`. Then, hasher's `encode` method would use `to_bytes` function with `force=False` argument. In all other `force_bytes` occurrences in the codebase, changing from `force_bytes` to `to_bytes` should be sufficient.
    3535
     36Edit: of course, we need to add a separate if statement for `str` itself.
     37
    3638{{{#!python
    3739def to_bytes(s, encoding='utf-8', strings_only=False, errors='strict', force=True):
     
    4547    if isinstance(s, memoryview):
    4648        return bytes(s)
     49    if isinstance(s, str):
     50        return s.encode(encoding, errors)
    4751    if force:
    4852        return str(s).encode(encoding, errors)
Back to Top