[Python-modules-commits] [python-pyld] 244/276: Add gzip support for remote document loading.
Wolfgang Borgert
debacle at moszumanska.debian.org
Wed Oct 8 23:48:16 UTC 2014
This is an automated email from the git hooks/post-receive script.
debacle pushed a commit to branch master
in repository python-pyld.
commit e64ba5de116335cf67477883ff91867cd4d5d8b7
Author: Dave Longley <dlongley at digitalbazaar.com>
Date: Thu May 15 11:05:07 2014 -0400
Add gzip support for remote document loading.
- Addresses #28.
---
lib/pyld/jsonld.py | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/lib/pyld/jsonld.py b/lib/pyld/jsonld.py
index 5922874..480f973 100644
--- a/lib/pyld/jsonld.py
+++ b/lib/pyld/jsonld.py
@@ -24,7 +24,9 @@ __all__ = [
'JsonLdProcessor', 'JsonLdError', 'ActiveContextCache']
import copy
+import gzip
import hashlib
+import io
import json
import os
import posixpath
@@ -304,12 +306,19 @@ def load_document(url):
https_handler = VerifiedHTTPSHandler()
url_opener = urllib_build_opener(https_handler)
url_opener.addheaders = [
- ('Accept', 'application/ld+json, application/json')]
+ ('Accept', 'application/ld+json, application/json'),
+ ('Accept-Encoding', 'deflate')]
with closing(url_opener.open(url)) as handle:
+ if handle.info().get('Content-Encoding') == 'gzip':
+ buf = io.BytesIO(handle.read())
+ f = gzip.GzipFile(fileobj=buf, mode='rb')
+ data = f.read()
+ else:
+ data = handle.read()
doc = {
'contextUrl': None,
'documentUrl': url,
- 'document': handle.read().decode('utf8')
+ 'document': data.decode('utf8')
}
doc['documentUrl'] = handle.geturl()
headers = dict(handle.info())
--
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