-
-
Notifications
You must be signed in to change notification settings - Fork 574
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
Make sure empty fragment and no fragment are the same in $schema #77
Make sure empty fragment and no fragment are the same in $schema #77
Conversation
|
||
""" | ||
|
||
if uri: |
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.
What's this? Is this to handle a uri of ""
? If so then it then turns it into None
which is almost certainly not what we want.
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.
Yeah, this was to counter a bug? in urlparse.defrag, when an empty uri was passed in it returned a tuple of empty byte strings rather than unicode strings, which could not be concatenated with the unicode '#'. If it returns '' when the uri given was empty is that better?
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.
It looks like it returns whatever type you pass in, no? I get back unicode for unicode uris and bytes for bytes uris on both Py2 and Py3?
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.
I need to double check. I just know it was crashing on the tests without that conditional.
Other than my comment this is fine as is but maybe we should look into a |
Maybe we should use |
Sounds good. Makes me even more likely to think that we need to wrap all this somehow though in a way that users can actually transparently use. |
I think I agree, not quite sure how you are thinking to do that though. |
Haven't thought it fully through yet, but probably with a combination of a Open for better ideas though. |
Hmm, yeah, we should probably use something like this when adding and looking up in the RefResolver store too. |
What if we made the metaschema dict, and the RefResolver store into something like this: class URIDict(dict):
def normalize(self, uri):
return urlparse.urlsplit(uri).geturl()
def __getitem__(self, uri):
return super(URIDict, self).__getitem__(self.normalize(uri))
def __setitem__(self, uri, value):
super(URIDict, self).__setitem__(self.normalize(uri), value) This isn't quite complete, due to not having init, delitem etc. defined, trying to figure if there is an easier way to do all that than just redefine them all. |
Right that was what I meant by
We'd want to do it using |
Okay, gotcha. Thought you meant something along those lines. Well, I think it's a good plan, sucks something like this has to redefine all the dict methods though, seems like there should be some way to provide a normalization function and get all this functionality. |
What do we gain by using |
Subclassing built in types is unreliable ( for the same reason subclassing So MutableMapping makes sure all of that happens correctly as long as you
|
Okay, MutableMapping gives us those things? I thought we still had to define all of those methods. I'll look into it. |
Ahh, seems it does. Nice, well in that case, I'm all for it, good call. :) |
Sucks a little that we need that much code for a simple problem, but is this what you were thinking? |
Oh, good call. Seems I need to fix something on python 2.7 too. |
Yeah it does a bit. But yeah looks like it. We should probably make it private too (So _URIDict). Otherwise looks good. |
@@ -1235,6 +1270,7 @@ def _uniq(container): | |||
|
|||
def validate(instance, schema, cls=None, *args, **kwargs): | |||
if cls is None: | |||
cls = meta_schemas.get(schema.get("$schema"), Draft4Validator) | |||
cls = meta_schemas.get(schema.get("$schema"), |
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.
Looks like this line is unchanged now.
Okay, think I got everything sorted now. |
Make sure empty fragment and no fragment are the same in $schema
My idea for the issue in #73