Skip to content
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

Files arg #189

Merged
merged 16 commits into from
May 17, 2024
Merged

Files arg #189

merged 16 commits into from
May 17, 2024

Conversation

FoamyGuy
Copy link
Contributor

This change adds a files argument that can be passed to post()

The value supported is dictionary with string keys and tuple values. The behavior when passed matches the behavior of CPython requests.

A new example was added illustrating the functionality, I've only tested with native wifi on ESP32 S3, so that is the only one added.

I was able to confirm the upload is working correctly by using a local simple flask server that acceps file upload and by examining the result returned by httpbin.org when the new example runs. It returns the image back in base64 format. This cyberchef recipe was used to validate that the original image does pop back out the other side https://cyberchef.org/#recipe=From_Base64('A-Za-z0-9%2B/%3D',true,false)Render_Image('Raw')

Note that the CPYthon implementation of this also supports a files dictionary with string keys and file_handle values (as opposed to tupple containing the file_handle and other things). That form of the argument is not supported on circuitpython. In order for that to be supported I believe we would need access to FileIO.name property or something that provides similar functionality. I've created #9195 in the core inquiring about adding that, but at present time this is not supported in the circuitpython version.

adafruit_requests.py Outdated Show resolved Hide resolved
@dhalbert
Copy link
Contributor

@FoamyGuy is this ready for final review or is it still in progress/

@FoamyGuy FoamyGuy requested a review from a team April 27, 2024 02:11
@FoamyGuy
Copy link
Contributor Author

I believe this is ready for review now. I've merged Justin's changes that were submitted against my branch to this so they are included here now.

@justmobilize
Copy link
Collaborator

@dhalbert I created a new PR into his branch to add some tests back in. Would love to see those in (can add later if wanted)

@justmobilize
Copy link
Collaborator

@dhalbert my tests are merged and this is ready for review!

Copy link
Contributor

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few suggestions.

adafruit_requests.py Show resolved Hide resolved
adafruit_requests.py Outdated Show resolved Hide resolved
adafruit_requests.py Outdated Show resolved Hide resolved
@justmobilize
Copy link
Collaborator

@FoamyGuy shall I make another PR into this branch with the changes?

@FoamyGuy
Copy link
Contributor Author

FoamyGuy commented May 2, 2024

@FoamyGuy shall I make another PR into this branch with the changes?

I got the change to os.urandom() with the latest commit, if you've got a clear idea how to tackle reducing the string concatenation then definitely feel free to PR to this branch.

I'll try to take a crack at it over the weekend if you don't have the opportunity to get it first.

@justmobilize
Copy link
Collaborator

@FoamyGuy created here: FoamyGuy#4

@justmobilize
Copy link
Collaborator

@dhalbert ready to go again!

Copy link
Contributor

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are more AttributeError usages that what I marked. They are in older code that isn't touched by this PR. Could you change those as well? Thanks. The tests will also need to be changed to use ValueError.

I looked at the bundle and there are many libraries that use AttributeError in places where should use ValueError. Maybe I should bring this up in the Monday meeting. There are also some references in Learn code.

This will be a major version change due to the exception changes.

adafruit_requests.py Show resolved Hide resolved
adafruit_requests.py Show resolved Hide resolved
@dhalbert
Copy link
Contributor

Maybe the ValueError -> AttributeError should be a separate PR.

@justmobilize
Copy link
Collaborator

@dhalbert I'm happy to work through this repo and fix up the exceptions and tests, and can do so after this is merged if that is the only concern.

Copy link
Contributor

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am willing to add this -- I am a little worried about library size but we'll see if it causes issues when frozen.

@justmobilize
Copy link
Collaborator

@dhalbert I had this idea of a requests-plus. That requires normal requests but has extra methods and overrides. The other option is that requests-plus could just have add-in methods (like in this case _build_boundary_string, _build_boundary_data etc. And if you pass in files and we got an import error for requests-plus it would error...

@FoamyGuy FoamyGuy merged commit d28ab9d into adafruit:main May 17, 2024
1 check passed
@dhalbert
Copy link
Contributor

@FoamyGuy Thanks for merging. This is an upward-compatible improvement, so it deserved a minor version bump. But no need to change the version number now.

adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request May 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants