-
Notifications
You must be signed in to change notification settings - Fork 14
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
Add support for base64 encoded images #43
Add support for base64 encoded images #43
Conversation
Can you explain the advantage of this approach over supporting base64 data URLs? https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs |
I did not think of using The only advantage I see to accepting |
ed47bef
to
acf9f4c
Compare
fb8c724
to
7d154ae
Compare
Now supports base64 encoded images. |
7d154ae
to
2e29003
Compare
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.
Nice!
@@ -30,7 +50,7 @@ def load_image(src: str) -> io.BytesIO: | |||
# Read up to MAX_IMAGE_SIZE when response does not contain | |||
# the Content-Length header. The extra byte avoids an extra read to | |||
# check whether the EOF was reached. | |||
data = response.read(MAX_IMAGE_SIZE + 1) | |||
data = cast(bytes, response.read(MAX_IMAGE_SIZE + 1)) |
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.
If you're interested, we could contribute to typeshed to avoid this type cast.
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 looked into this option. urlopen()
returns either a HTTPResponse
or an addinfourl
. Both implement a read()
that returns bytes
. The return type used to be specified as the Union
of both types, but returning a Union
type is discouraged and the urlopen()
was changed to return type Any
.
An option might be to use structural subtyping and create a Protocol
, so that methods common to addinfourl
and HTTPResponse
are hinted correctly. That would cover the read()
method and probably a few others, but adds a maintenance burden.
e146726
to
2b2a949
Compare
Changes:
|
Reviewed-by: Jon Dufresne
2b2a949
to
d81339a
Compare
Allows constructing documents with images that are not available publicly over the Internet.