Skip to content

bovine.jsonld

This modules contains some helper functions to deal with json-ld <https://json-ld.org/>. It realies on the pyld <https://github.com/digitalbazaar/pyld> library to perform the actual algorithms on json-ld.

The goal of using with_bovine_context is to achieve simpler access for certain values. With the base ActivityStreams Namespace <https://www.w3.org/ns/activitystreams>_ the value of to can either be a string or a list. With the bovine context, it will always be a list.

bovine_context = ['https://www.w3.org/ns/activitystreams', {'publicKey': {'@id': 'https://w3id.org/security#publicKey', '@type': '@id'}, 'publicKeyPem': 'https://w3id.org/security#publicKeyPem', 'owner': {'@id': 'https://w3id.org/security#owner', '@type': '@id'}, 'to': {'@id': 'as:to', '@type': '@id', '@container': '@set'}, 'cc': {'@id': 'as:cc', '@type': '@id', '@container': '@set'}, 'tag': {'@id': 'as:tag', '@type': '@id', '@container': '@set'}, 'items': {'@id': 'as:items', '@type': '@id', '@container': '@set'}, 'attachment': {'@id': 'as:attachment', '@type': '@id', '@container': '@set'}, 'Hashtag': 'as:Hashtag'}, 'https://www.w3.org/ns/did/v1', 'https://w3id.org/security/multikey/v1'] module-attribute

Defines the context about:bovine used internally in the bovine stack

bovine_context_name = 'about:bovine' module-attribute

Defines the name of the bovine context

default_context = ['https://www.w3.org/ns/activitystreams', 'https://w3id.org/security/v1', 'https://www.w3.org/ns/did/v1', 'https://w3id.org/security/multikey/v1', {'Hashtag': 'as:Hashtag'}] module-attribute

Defines the context used to communicate with other Fediverse software

jsonld_cache = JsonLDCache() module-attribute

Stores the cached contexts

combine_items(data, items)

Takes data and replaces ids by the corresponding objects from items

Source code in bovine/bovine/jsonld/__init__.py
def combine_items(data: dict, items: List[dict]) -> dict:
    """Takes data and replaces ids by the corresponding objects from items"""
    return frame_object(data, items, data["@context"])

split_into_objects(input_data) async

Takes an object with an “id” property and separates out all the subobjects with an id

Source code in bovine/bovine/jsonld/__init__.py
async def split_into_objects(input_data: dict) -> List[dict]:
    """Takes an object with an "id" property and separates
    out all the subobjects with an id"""

    if "@context" not in input_data:
        logger.warning("@context missing in %s", json.dumps(input_data))
        input_data["@context"] = default_context

    context = input_data["@context"]
    flattened = jsonld.flatten(input_data)
    compacted = jsonld.compact(flattened, context)

    if "@graph" not in compacted:
        return [compacted]

    local, remote = split_remote_local(compacted["@graph"])

    return [frame_object(obj, local, context) for obj in remote]

with_activitystreams_context(data)

Returns the object with the ActivityStreams context

Source code in bovine/bovine/jsonld/__init__.py
def with_activitystreams_context(data: dict) -> dict:
    """Returns the object with the ActivityStreams context"""
    return use_context(data, "https://www.w3.org/ns/activitystreams")

with_bovine_context(data)

Returns the object with the about:bovine context

Source code in bovine/bovine/jsonld/__init__.py
def with_bovine_context(data: dict) -> dict:
    """Returns the object with the about:bovine context"""
    return use_context(data, "about:bovine")

with_external_context(data)

Returns the object with the default external context

Source code in bovine/bovine/jsonld/__init__.py
def with_external_context(data: dict) -> dict:
    """Returns the object with the default external context"""
    return use_context(data, default_context)