Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
554 changes: 554 additions & 0 deletions lib/pyld/canon.py

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions lib/pyld/context_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ def _fetch_context(self, active_ctx, url, cycles):
'non-JSON response, or more than one HTTP Link Header was ' +
'provided for a remote context.',
'jsonld.InvalidUrl',
{'url': url, 'cause': cause},
code='loading remote context failed')
{'url': url},
code='loading remote context failed') from cause

# ensure ctx is an object
if not isinstance(context, dict) and not isinstance(context, frozendict):
Expand Down
4 changes: 2 additions & 2 deletions lib/pyld/documentloader/aiohttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ async def async_loader(url, headers):
except Exception as cause:
raise JsonLdError(
'Could not retrieve a JSON-LD document from the URL.',
'jsonld.LoadDocumentError', code='loading document failed',
cause=cause)
'jsonld.LoadDocumentError',
code='loading document failed') from cause

def loader(url, options=None):
"""
Expand Down
4 changes: 2 additions & 2 deletions lib/pyld/documentloader/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def loader(url, options={}):
except Exception as cause:
raise JsonLdError(
'Could not retrieve a JSON-LD document from the URL.',
'jsonld.LoadDocumentError', code='loading document failed',
cause=cause)
'jsonld.LoadDocumentError',
code='loading document failed') from cause

return loader
52 changes: 52 additions & 0 deletions lib/pyld/identifier_issuer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
class IdentifierIssuer(object):
"""
An IdentifierIssuer issues unique identifiers, keeping track of any
previously issued identifiers.
"""

def __init__(self, prefix):
"""
Initializes a new IdentifierIssuer.

:param prefix: the prefix to use ('<prefix><counter>').
"""
self.prefix = prefix
self.counter = 0
self.existing = {}
self.order = []

"""
Gets the new identifier for the given old identifier, where if no old
identifier is given a new identifier will be generated.

:param [old]: the old identifier to get the new identifier for.

:return: the new identifier.
"""
def get_id(self, old=None):
# return existing old identifier
if old and old in self.existing:
return self.existing[old]

# get next identifier
id_ = self.prefix + str(self.counter)
self.counter += 1

# save mapping
if old is not None:
self.existing[old] = id_
self.order.append(old)

return id_

def has_id(self, old):
"""
Returns True if the given old identifier has already been assigned a
new identifier.

:param old: the old identifier to check.

:return: True if the old identifier has been assigned a new identifier,
False if not.
"""
return old in self.existing
Loading
Loading