Add a utility function for returning encoded newlines for a type.

Review Request #11742 — Created July 23, 2021 and submitted

Information

DiffX
master

Reviewers

This introduces get_newline_for_type(), a utility function that takes
a LineEndings type value and returns newlines encoded as either ASCII
or the given encoding (with BOM stripped).

This logic was previously contained in DiffXReader, but is generally
useful, so it's being split out. That simplifies the DiffXReader code
as well, making some of the logic a lot more clear.

Unit tests pass on Python 2 and 3.

Summary ID
Add a utility function for returning encoded newlines for a type.
This introduces `get_newline_for_type()`, a utility function that takes a `LineEndings` type value and returns newlines encoded as either ASCII or the given encoding (with BOM stripped). This logic was previously contained in `DiffXReader`, but is generally useful, so it's being split out. That simplifies the `DiffXReader` code as well, making some of the logic a lot more clear.
1245d7bec05ef7ad783c64e1cf9a807ba91e6dd7
Description From Last Updated

What's the reason to not just do encoding='ascii' in the args list?

daviddavid
david
  1. 
      
  2. python/pydiffx/utils/text.py (Diff revision 1)
     
     
     
    Show all issues

    What's the reason to not just do encoding='ascii' in the args list?

    1. Values get passed down directly into this from DiffXReader and, in a change I just posted, DiffXFileSection. Those values are legally allowed to be None, and should not be hard-coded to ascii (None for a diff means "no encoding is known or guaranteed"). To default this to ascii, the call sites would need to conditionally call this with/without the encoding parameter based on their own encoding value.

  3. 
      
david
  1. Ship It!
  2. 
      
chipx86
Review request changed
Status:
Completed
Change Summary:
Pushed to master (161143d)