[Python-modules-commits] [python-pyld] 02/03: Move remote context URL validation to document loader.
Wolfgang Borgert
debacle at moszumanska.debian.org
Tue Oct 13 22:56:21 UTC 2015
This is an automated email from the git hooks/post-receive script.
debacle pushed a commit to tag 0.6.4
in repository python-pyld.
commit 556b22cff9955e4f4ed323fd62ed24f6ea98b105
Author: Dave Longley <dlongley at digitalbazaar.com>
Date: Thu Nov 6 10:27:18 2014 -0500
Move remote context URL validation to document loader.
- Pushes URL validation responbility and/or special
URL-scheme support determination to the document
loader API to allow for customization.
---
lib/pyld/jsonld.py | 32 ++++++++++++++++++++------------
1 file changed, 20 insertions(+), 12 deletions(-)
diff --git a/lib/pyld/jsonld.py b/lib/pyld/jsonld.py
index a12edaa..9d32ad0 100644
--- a/lib/pyld/jsonld.py
+++ b/lib/pyld/jsonld.py
@@ -339,6 +339,17 @@ def load_document(url):
:return: the RemoteDocument.
"""
try:
+ # validate URL
+ pieces = urllib_parse.urlparse(url)
+ if (not all([pieces.scheme, pieces.netloc]) or
+ pieces.scheme not in ['http', 'https'] or
+ set(pieces.netloc) > set(
+ string.ascii_letters + string.digits + '-.:')):
+ raise JsonLdError(
+ 'URL could not be dereferenced; only "http" and "https" '
+ 'URLs are supported.',
+ 'jsonld.InvalidUrl', {'url': url},
+ code='loading document failed')
https_handler = VerifiedHTTPSHandler()
url_opener = urllib_build_opener(https_handler)
url_opener.addheaders = [
@@ -4146,16 +4157,6 @@ class JsonLdProcessor(object):
queue = []
for url, ctx in urls.items():
if ctx is False:
- # validate URL
- pieces = urllib_parse.urlparse(url)
- if (not all([pieces.scheme, pieces.netloc]) or
- pieces.scheme not in ['http', 'https'] or
- set(pieces.netloc) > set(
- string.ascii_letters + string.digits + '-.:')):
- raise JsonLdError(
- 'Malformed or unsupported URL.',
- 'jsonld.InvalidUrl', {'url': url},
- code='loading remote context failed')
queue.append(url)
# retrieve URLs in queue
@@ -4170,8 +4171,15 @@ class JsonLdProcessor(object):
cycles_[url] = True
# retrieve URL
- remote_doc = load_document(url)
- ctx = remote_doc['document']
+ try:
+ remote_doc = load_document(url)
+ ctx = remote_doc['document']
+ except Exception as cause:
+ raise JsonLdError(
+ 'Dereferencing a URL did not result in a valid JSON-LD '
+ 'context.',
+ 'jsonld.ContextUrlError', {'url': url},
+ code='loading remote context failed', cause=cause)
# parse string context as JSON
if _is_string(ctx):
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-pyld.git
More information about the Python-modules-commits
mailing list