Changes between Initial Version and Version 1 of Ticket #31375, comment 3
- Timestamp:
- Mar 18, 2020, 3:09:38 PM (5 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #31375, comment 3
initial v1 34 34 2. 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. 35 35 36 Edit: of course, we need to add a separate if statement for `str` itself. 37 36 38 {{{#!python 37 39 def to_bytes(s, encoding='utf-8', strings_only=False, errors='strict', force=True): … … 45 47 if isinstance(s, memoryview): 46 48 return bytes(s) 49 if isinstance(s, str): 50 return s.encode(encoding, errors) 47 51 if force: 48 52 return str(s).encode(encoding, errors)