From 305f95865c6d1c7e9618c7e2ae4d1e369cf6ad25 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Mon, 3 Jun 2024 17:59:09 +0200 Subject: [PATCH] fix documentloader --- pyvckit/document_loader.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pyvckit/document_loader.py b/pyvckit/document_loader.py index 0b00298..1710234 100644 --- a/pyvckit/document_loader.py +++ b/pyvckit/document_loader.py @@ -9,9 +9,11 @@ Remote document loader using Requests. .. moduleauthor:: Tim McNamara .. moduleauthor:: Olaf Conradi """ +import re import string import json import urllib.parse as urllib_parse +from pyld import jsonld from pyld.jsonld import (JsonLdError, parse_link_header, LINK_HEADER_REL) @@ -20,7 +22,6 @@ def get_cache(): with open("cache_context.json") as f: doc_str = f.read() if doc_str: - # import pdb; pdb.set_trace() return json.loads(doc_str) return {} @@ -48,7 +49,6 @@ def requests_document_loader(secure=False, **kwargs): :return: the RemoteDocument. """ - # import pdb; pdb.set_trace() cache = get_cache() if cache.get(url): return cache[url] @@ -109,11 +109,11 @@ def requests_document_loader(secure=False, **kwargs): not re.match(r'^application\/(\w*\+)?json$', content_type)): doc['contentType'] = 'application/ld+json' doc['documentUrl'] = jsonld.prepend_base(url, linked_alternate['target']) - # import pdb; pdb.set_trace() + cache[url] = doc - f = open("cache_context.json", "w") - f.write(json.dumps(cache)) - f.close() + with open("cache_context.json", "w") as f: + f.write(json.dumps(cache)) + return doc except JsonLdError as e: raise e