rocky / python-filecache

module for Python module for reading and caching lines. This may be useful for example in a debugger where the same lines are shown many times.
GNU General Public License v3.0
4 stars 4 forks source link

Add raw newline mode support #1

Closed jayvdb closed 7 years ago

jayvdb commented 7 years ago

I am looking for a file (line) cache that can open files with the real EOL bytes preserved. In Python 3, this can be achieved using open(..., newline='').

The primary need is https://github.com/coala/coala-bears/issues/815 , which is influencing the technical requirements for our file cache rewrite (https://github.com/coala/cEPs/pull/31).

As I only need Python 3 support, a very hacky approach is to allow the client to pass parameters to the open call in update_cache, currently at line 540.

The alternative is to add a newline parameter/option to opts everywhere, using the Python 3 functionality, and either raise NotImplementedError on Python 2 or use/build a backport of the Python 3 newline mode when on Python 2.

Keen to know your thoughts on how I should proceed.

rocky commented 7 years ago

Sure, let's fix pyficache. I believe Universal Newline Support or PEP-0278 works on both Python 2 and Python 3. Basically one opens a file with mode 'rU', for example f = open('/tmp/foo.py', 'rU').

And this can be added as an option for compatibility.

Would you care to submit a patch?

One other feature I have been meaning to add is this feature to return the file size (mod 2**32) as listed in the compiled binary which can be used to verify that code source matches a file found on disk. So a release with these two feature would come out soon.

jayvdb commented 7 years ago

Python 2 supports universal new lines, but this Python 3 only newlines parameter does not exist in Python 2, but ... there is a newline attribute ... and that could be sufficient for my needs if it is exposed.

Ok, I'll submit a patch shortly.

rocky commented 7 years ago

Thanks for handling.

rocky commented 7 years ago

@jayvdb Just reworked the change so we don't get the deprecation warning. Please review 490cfe5 . If that's okay, I'll make another release.