Skip to content

bovine.jsonld

This modules contains some helper functions to deal with json-ld. It realies on the 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 the value of to can either be a string or a list. With the bovine context, it will always be a list.

bovine.jsonld

bovine_context module-attribute

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",
]

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

bovine_context_name module-attribute

bovine_context_name = 'about:bovine'

Defines the name of the bovine context

default_context module-attribute

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"},
]

Defines the context used to communicate with other Fediverse software

jsonld_cache module-attribute

jsonld_cache = JsonLDCache()

Stores the cached contexts

combine_items

combine_items(data: dict, items: List[dict]) -> dict

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 async

split_into_objects(input_data: dict) -> List[dict]

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

with_activitystreams_context(data: dict) -> dict

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

with_bovine_context(data: dict) -> dict

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

with_external_context(data: dict) -> dict

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)