-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Support FileResponse from any pathlib.Path compatible object #7933
base: master
Are you sure you want to change the base?
Conversation
name: str | ||
|
||
def open(self, mode: str) -> IO[Any]: | ||
... |
Check notice
Code scanning / CodeQL
Statement has no effect Note
... | ||
|
||
def stat(self, *, follow_symlinks=True) -> os.stat_result: | ||
... |
Check notice
Code scanning / CodeQL
Statement has no effect Note
... | ||
|
||
def with_name(self, name: str) -> PathlibPathNamedLike: | ||
... |
Check notice
Code scanning / CodeQL
Statement has no effect Note
Why do we need the protocol? If you've subclassed Path, then shouldn't it be a subclass of |
If you do not have the file on filesystem, it would be best if it is not a subclass of |
But, Though looking closer, Another complication with your custom classes, is that someone expects things like |
Hmm, I guess your point is you want something that looks like a |
f5059ac
to
bd3af50
Compare
Yes. A My application generates the file and has the content and timestamp in-memory. It does not change for every request, so much of the functionality in For now I assign the own Path like to |
I guess my question is why use FileResponse? If you already have the file contents in memory, why not use a regular Response? |
OK, I'm getting the feeling it would make more sense to expand FileResponse, or add another subclass, which supports this more directly. e.g. Instead of a path object, it could accept a file-like object directly, then you can just pass io.StringIO. |
That thought occurred to me also. It needs the modification time, size, maybe something for the content-type so any If the |
Right, we could add attributes for these on the response object itself so they could be managed there. I was also thinking that modification time could be set automatically when assigning an attribute, but that'd only work if it was str/bytes rather than a file-like object (len() could also work for size in that instance). |
bd3af50
to
f07b1e3
Compare
What do these changes do?
Add support for passing to web.FileResponse any object with required attributes of pathlib.Path.
Are there changes in behavior for the user?
Responses can be sent from files not in the filesystem.
Related issue number
Fixes #7928
Checklist
CONTRIBUTORS.txt
CHANGES
folder<issue_id>.<type>
for example (588.bugfix)issue_id
change it to the pr id after creating the pr.feature
: Signifying a new feature..bugfix
: Signifying a bug fix..doc
: Signifying a documentation improvement..removal
: Signifying a deprecation or removal of public API..misc
: A ticket has been closed, but it is not of interest to users.