-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
parse charset and decode text #11
Conversation
|
||
@CachedProperty | ||
def text(self): | ||
if not self.media_type.startswith('text/'): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
intuitively i'd say utf-8 is a saner and more useful default. or does the spec explicitly forbid that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it is:
If one is not specified, the media type of the data URI is assumed to be text/plain;charset=US-ASCIIQ
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok cool ascii it is then
@@ -6,3 +6,6 @@ deps=-rrequirements-test.txt | |||
commands= | |||
pytest --cov {envsitepackagesdir}/datauri {posargs} tests/ | |||
flake8 datauri/ | |||
|
|||
[flake8] | |||
max-line-length = 90 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this seems unrelated but ok
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, not related to the issue, but with 79 chars I can't even put the link on the source of CachedProperty
without splitting it. That's silly.
@@ -22,6 +22,18 @@ class DataURIError(ValueError): | |||
pass | |||
|
|||
|
|||
# https://github.com/bottlepy/bottle/commit/fa7733e075da0d790d809aa3d2f53071897e6f76 | |||
class CachedProperty(object): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: cached_property
(or an alias cached_property = CachedProperty
) makes usage look more like @property
for which this is a drop-in replacement anyway
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed 👍
in general, looks good. changelog entry and docs + example in README would be needed as well |
Oh, right. Sorry. Fixed 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good. added a remark about dealing with unknown encodings, other than that, all fine! 🚀
def text(self): | ||
if not self.media_type.startswith('text/'): | ||
return None | ||
return self.data.decode(self.charset or 'ascii') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will raise LookupError
in case the encoding is a weird name like foo
. should we error out or return None
in that case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think, something should be raised to allow lib users to make the decision about such cases themself.
close #3
close #6