Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I've tried many little things to make WeasyPrint work with both Python 2 and 3, and here's the best solution I've found.
pathname2url
doesn't accept bytestrings with Python 3 on Windows. As Python 2 allows bytes and Python 3 allows unicode with all OSes, I've added theencode
in thecompat
module'spathname2url
implementation.path2url
: unicode is actually already returned because of the implicit cast due tou'abc' + b'abc'
at the end of the function.open
instead ofurlopen
is a good idea, but it's not related to this problem. For the record, I've tried to useopen
, but URIs for Windows filenames have an extra slash before the volume (something like/C:/path
). This leading path is explained by the RFC and it's handled correctly byurlopen
, duplicating code to handle it (and other needed features such as guessing mimetypes) in WP may be useless. We can do this later if we want.FILESYSTEM_ENCODING
variable in thecompat
module: it's not a bad place and avoids a circular import.Finally, this PR is pretty equivalent to #132, but a bit cleaner 😄.
It's been tested with Python 2.7 and 3.5, on Windows 10 and Linux. Some tests launched with
py.test
even work on Windows (but some tests make Python crash, fun fun fun).