Created
August 27, 2014 22:50
-
-
Save tomprince/d6534c855fe264626f37 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class SchemaNotProvided(Exception): | |
| """ | |
| Tried to reference a schema that wasn't predefined. | |
| """ | |
| class LocalRefResolver(RefResolver): | |
| """ | |
| A L{RefResolver} that doesn't try to resolve remote schema. | |
| """ | |
| def resolve_remote(self, uri): | |
| raise SchemaNotProvided(uri) | |
| SCHEMA_BASE = PACKAGE.descendant([b'publicapi', b'schema']) | |
| SCHEMAS = { | |
| b'/v2/types.json': yaml.safe_load(SCHEMA_BASE.child(b'types.yml').getContent()), | |
| b'/v2/endpoints.json': yaml.safe_load(SCHEMA_BASE.child(b'endpoints.yml').getContent()), | |
| } | |
| def getValidator(schema): | |
| """ | |
| Get a L{jsonschema} validator for C{schema}. | |
| @param schema: The JSON Schema to validate against. | |
| @type schema: L{dict} | |
| """ | |
| # The base_uri here isn't correct for the schema, | |
| # but does give proper relative paths. | |
| resolver = LocalRefResolver( | |
| base_uri=b'', | |
| referrer=schema, store=SCHEMAS) | |
| resolver.resolution_scope = b'' | |
| return validator_for(schema)( | |
| schema, resolver=resolver, format_checker=draft4_format_checker) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment