-
-
Notifications
You must be signed in to change notification settings - Fork 570
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
remote ref parsing #61
Comments
The unit test doesn't have a problem, because the mock urlopen returns a string. |
I think the correct method would be to check headers for an encoding first. If it is not specified there, the json spec says that the encoding will either be utf-8 16 or 32. It's tempting to just require requests for remote ref support, here are the relevant parts from their project. getting encoding from headers, guessing utf version |
Ouch :/. OK. I'm fine with adding a dependency on requests. We will need to check that requests supports all the reasonable URI schemes that urlopen does. |
requests does not support file or ftp schemes. :/ Is that something we want to work as well? |
Um. I guess having a way to add handlers for schemes like I originally envisioned would be nice if it doesn't.. |
What were you envisioning? Requests does have support for adding handlers for different schemas, maybe we could implement your idea using that. |
In fact, in FlexGet, we handle transparent file: and ftp: schema support by just farming it out to urllib from requests. |
All I meant was that it'd be nice to do things like:
and have that resolver's |
Sounds good, I'll put something together. Do you think handlers should be defined on the instance or for the whole class? |
Also, what should happen when a refresolver encounters a scheme it cannot handle? Raise a SchemaError? |
No preference. Probably will be easier on the instance though. |
A |
Oh shit, didn't even see that one, much better. |
Right now I have it in the same style as FormatChecker, i.e. try:
import requests
# We need requests >= 1.0.0
if requests.__version__.split(".") < ["1"]:
raise ImportError
except ImportError:
pass
else:
@RefResolver.handles("http")
@RefResolver.handles("https")
def handle_http_ref(uri):
"""
Retrieves and parses json from ``uri``.
Only handles http and https uri scheme.
:argument str uri: the URI to resolve
:returns: the retrieved document
"""
return requests.get(uri).json() That sound okay? |
I feel uncomfortable depending on requests for this and doing absolutely nothing without it. Can we optionally depend on requests to automagically detect encoding, otherwise fall back to urllib and just assume UTF-8, and of course allow someone to replace urllib? So essentially this but rather than doing nothing without requests, try as best we can. Also I'm not sure we need such a heavy handed interface for this one. Creating new formats seemed like a common enough thing to want, so I went with the decorators, but here it's probably enough to just go with passing a dict to |
Oh and btw I forget if I've mentioned that we have some docs now :) So it'd be great if we doc'ed this when we settle on something. |
Sounds good on both counts, I'll fix that up then send a PR for you to check out. |
Oh and -- for the ones requests / urllib support, it's probably unnecessary to specify them explicitly for each scheme I guess. Just fall back to requests/urllib if nothing matches the scheme, and allow people to add additional ones or superceed them by being explicit. Sound reasonable? |
Sounds good to me. |
Add ability to specify handlers for different uri schemes in RefResolver Add unit tests for new features
There is currently a problem with the remote ref parsing (at least on python 3.)
urlopen
returns bytes, whichjson.load
doesn't like; he wants a string.The text was updated successfully, but these errors were encountered: