You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
FileDocumentLoader serves file: URLs only, and RequestsDocumentLoader / AioHttpDocumentLoader serve http/https only. A local JSON-LD document whose @context is a remote https: URL therefore cannot be processed by either loader alone.
Proposal
Add ChoiceBySchemeDocumentLoader, a DocumentLoader subclass that dispatches by URL scheme:
Constructed as ChoiceBySchemeDocumentLoader(**loaders), storing the keyword mapping as a scheme-to-loader dict.
__call__(url, options) delegates to self.loaders[urlparse(url).scheme or 'file'].
An empty / missing scheme is treated as file.
Values may be DocumentLoader instances or plain callables, per the loader contract in lib/pyld/documentloader/base.py.
An unregistered scheme raises JsonLdError with code loading document failed and details naming the schemes that are registered.
Out of scope
Do not change _default_document_loader in lib/pyld/jsonld.py. Serving file: by default would let any document with "@context": "file:///etc/passwd" read local files. Callers should opt in by passing the composed loader as documentLoader per operation.
Deliverables
lib/pyld/documentloader/choice_by_scheme.py
Export from lib/pyld/__init__.py
tests/test_choice_by_scheme_document_loader.py
docs/reference/document-loaders/choice-by-scheme.md following the shape of docs/reference/document-loaders/frozen.md, plus a card in docs/reference/document-loaders/index.md
CHANGELOG.md entry under the unreleased section
Related
Prerequisite: FileDocumentLoader (see branch file-document-loader)
Problem
FileDocumentLoaderservesfile:URLs only, andRequestsDocumentLoader/AioHttpDocumentLoaderservehttp/httpsonly. A local JSON-LD document whose@contextis a remotehttps:URL therefore cannot be processed by either loader alone.Proposal
Add
ChoiceBySchemeDocumentLoader, aDocumentLoadersubclass that dispatches by URL scheme:Behavior
ChoiceBySchemeDocumentLoader(**loaders), storing the keyword mapping as a scheme-to-loader dict.__call__(url, options)delegates toself.loaders[urlparse(url).scheme or 'file'].file.DocumentLoaderinstances or plain callables, per the loader contract inlib/pyld/documentloader/base.py.JsonLdErrorwith codeloading document failedand details naming the schemes that are registered.Out of scope
Do not change
_default_document_loaderinlib/pyld/jsonld.py. Servingfile:by default would let any document with"@context": "file:///etc/passwd"read local files. Callers should opt in by passing the composed loader asdocumentLoaderper operation.Deliverables
lib/pyld/documentloader/choice_by_scheme.pylib/pyld/__init__.pytests/test_choice_by_scheme_document_loader.pydocs/reference/document-loaders/choice-by-scheme.mdfollowing the shape ofdocs/reference/document-loaders/frozen.md, plus a card indocs/reference/document-loaders/index.mdCHANGELOG.mdentry under the unreleased sectionRelated
FileDocumentLoader(see branchfile-document-loader)