-
Notifications
You must be signed in to change notification settings - Fork 282
fix: make file extension guessing with uri query parameters #879
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
base: main
Are you sure you want to change the base?
Conversation
parsed = urlparse(file_path) | ||
except Exception: | ||
return None | ||
split = parsed.path.split(".") |
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.
As we use urlparse, this give us just the path without the query parameters.
6b0d3ba
to
cb1bdda
Compare
parsed = urlparse(file_path) | ||
except Exception: | ||
return None | ||
split = parsed.path.split(".") |
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.
As we use urlparse, this give us just the path without the query parameters.
|
||
def guess_filetype(file_like: BytesIO, file_path: str | None = None) -> str | None: | ||
guess = filetype.guess(file_like) # type: ignore | ||
extension = filetype.guess_extension(file_like) # type: ignore |
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 is a simplification. Calling guess_extension calls guess internally and just returns the extension, which is all we need.
cb1bdda
to
b8a8e63
Compare
parsed = urlparse(file_path) | ||
except Exception: | ||
return None | ||
split = parsed.path.split(".") |
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.
Why not use splitext here?
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.
Done
|
||
def guess_filetype(file_like: BytesIO, file_path: str | None = None) -> str | None: | ||
guess = filetype.guess(file_like) # type: ignore | ||
guess = filetype.guess(file_like) # type: ignore[reportUnknownArgumentType,reportUnknownMemberType] |
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 error wasn't popping previously but now it does. Im just skipping. Other solution would be to do explicit casts.
except Exception: | ||
return None | ||
|
||
return ext[1:].lower() if ext else None |
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.
Added the .lower()
so we ensure always to go with lowercase extensions. Just for consistency.
No description provided.