-
Notifications
You must be signed in to change notification settings - Fork 78
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
Error ByteIO #379
Comments
Thank you for raising your first issue! Your help to improve svglib is much appreciated! |
You are right, if paths in the content are absolute paths, we should not fail with that message (around Line 707 in 7742244
|
I suck at handling forked changes, so I'm just gonna dump the code here. These changes really helped me out. Write that up as lit. reworked lines 707-722 if iri:
import io
# Only local relative paths and BytesIO objects are supported
if not isinstance(self.source_path, (str, io.BytesIO)):
logger.error(
"Unable to resolve image path %r as the SVG source is not "
"a file system path or BytesIO object.",
iri
)
return None
if isinstance(self.source_path, str):
path = os.path.normpath(os.path.join(os.path.dirname(self.source_path), iri))
if not os.access(path, os.R_OK):
return None
if path == self.source_path:
# Self-referencing, ignore the IRI part
iri = None
else:
# self.source_path is of type io.BytesIO
# We need to read the data from BytesIO object so that it can be accessed like a regular file system path.
try:
path = self.source_path.name
except AttributeError:
path = '<BytesIO>'
with open(path, 'wb') as f:
f.write(self.source_path.read())
path = os.path.normpath(os.path.join(os.path.dirname(path), iri))
if path == '<BytesIO>':
iri = None
elif not os.access(path, os.R_OK):
return None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There is such a function:
It gives such an error:
The images are present along these paths, but okay, I rewrote the string to an absolute path.
I checked lib and i find there was an isinstance check for str, and I had byteIO there.
So I replaced everything with a different approach, which I will attach if it helps someone.
So what was my problem?
The text was updated successfully, but these errors were encountered: