예제 #1
0
파일: dbm.py 프로젝트: w3c-social/activipy
    assert asobj.id is not None
    del db[asobj.id]


dbm_save_method = core.MethodId("save", "Save object to the DBM store.",
                                core.handle_one)
dbm_delete_method = core.MethodId("delete",
                                  "Delete object from the DBM store.",
                                  core.handle_one)

DbmEnv = core.Environment(vocabs=[vocab.CoreVocab],
                          methods={
                              (dbm_save_method, vocab.Object): dbm_save,
                              (dbm_delete_method, vocab.Object): dbm_delete
                          },
                          shortids=core.shortids_from_vocab(vocab.CoreVocab),
                          c_accessors=core.shortids_from_vocab(
                              vocab.CoreVocab))


def dbm_activity_normalized_save(asobj, db):
    assert asobj.id is not None
    as_json = asobj.json()

    def maybe_normalize(key):
        val = as_json.get(key)
        # Skip if not a dictionary with a "@type"
        if not isinstance(val, dict) or not "@type" in val:
            return

        val_asobj = core.ASObj(val, asobj.env)
예제 #2
0
파일: dbm.py 프로젝트: gobengo/activipy
    del db[asobj.id]


dbm_save_method = core.MethodId(
    "save", "Save object to the DBM store.",
    core.handle_one)
dbm_delete_method = core.MethodId(
    "delete", "Delete object from the DBM store.",
    core.handle_one)

DbmEnv = core.Environment(
    vocabs=[vocab.CoreVocab],
    methods={
        (dbm_save_method, vocab.Object): dbm_save,
        (dbm_delete_method, vocab.Object): dbm_delete},
    shortids=core.shortids_from_vocab(vocab.CoreVocab),
    c_accessors=core.shortids_from_vocab(vocab.CoreVocab))


def dbm_activity_normalized_save(asobj, db):
    assert asobj.id is not None
    as_json = asobj.json()

    def maybe_normalize(key):
        val = as_json.get(key)
        # Skip if not a dictionary with a "@type"
        if not isinstance(val, dict) or not "@type" in val:
            return

        val_asobj = core.ASObj(val, asobj.env)
        # yup, time to normalize
예제 #3
0
파일: checkup.py 프로젝트: gobengo/activipy
    "Coupon",
    notes=("A redeemable voucher (by redeem_url) for hopefully " "something exciting!"),
)

RoyalStatus = ASType(
    checkup_uri("RoyalStatus"), [vocab.Object], "RoyalStatus", notes=("How royal you are at a given location!")
)


CheckUpVocab = ASVocab([CheckIn, Coupon, RoyalStatus])

CHECKUP_EXTRA_CONTEXT_NAMESPACED = {"CheckUp": "http://checkup.example/ns#"}

CheckUpNSEnv = Environment(
    vocabs=[vocab.CoreVocab],
    shortids=chain_dicts(shortids_from_vocab(vocab.CoreVocab), shortids_from_vocab(CheckUpVocab, "CheckUp")),
    c_accessors=chain_dicts(shortids_from_vocab(vocab.CoreVocab), shortids_from_vocab(CheckUpVocab)),
    extra_context=CHECKUP_EXTRA_CONTEXT_NAMESPACED,
)

CHECKUP_EXTRA_CONTEXT_VERBOSE = {
    "CheckIn": {"@id": CheckIn.id_uri, "@type": "@id"},
    "Coupon": {"@id": Coupon.id_uri, "@type": "@id"},
    "RoyalStatus": {"@id": RoyalStatus.id_uri, "@type": "@id"},
}

CheckUpVerboseEnv = Environment(
    vocabs=[vocab.CoreVocab],
    shortids=chain_dicts(shortids_from_vocab(vocab.CoreVocab), shortids_from_vocab(CheckUpVocab)),
    c_accessors=chain_dicts(shortids_from_vocab(vocab.CoreVocab), shortids_from_vocab(CheckUpVocab)),
    extra_context=CHECKUP_EXTRA_CONTEXT_VERBOSE,
예제 #4
0
Coupon = ASType(checkup_uri("Coupon"), [vocab.Object],
                "Coupon",
                notes=("A redeemable voucher (by redeem_url) for hopefully "
                       "something exciting!"))

RoyalStatus = ASType(checkup_uri("RoyalStatus"), [vocab.Object],
                     "RoyalStatus",
                     notes=("How royal you are at a given location!"))

CheckUpVocab = ASVocab([CheckIn, Coupon, RoyalStatus])

CHECKUP_EXTRA_CONTEXT_NAMESPACED = {"CheckUp": "http://checkup.example/ns#"}

CheckUpNSEnv = Environment(
    vocabs=[vocab.CoreVocab],
    shortids=chain_dicts(shortids_from_vocab(vocab.CoreVocab),
                         shortids_from_vocab(CheckUpVocab, "CheckUp")),
    c_accessors=chain_dicts(shortids_from_vocab(vocab.CoreVocab),
                            shortids_from_vocab(CheckUpVocab)),
    extra_context=CHECKUP_EXTRA_CONTEXT_NAMESPACED)

CHECKUP_EXTRA_CONTEXT_VERBOSE = {
    "CheckIn": {
        "@id": CheckIn.id_uri,
        "@type": "@id"
    },
    "Coupon": {
        "@id": Coupon.id_uri,
        "@type": "@id"
    },
    "RoyalStatus": {
예제 #5
0
# BS testing widget
ASWidget = core.ASType(fake_type_uri("widget"), [ASObject], "Widget")

ASFancyWidget = core.ASType(fake_type_uri("fancywidget"), [ASWidget],
                            "FancyWidget")

# Example vocab and environment
ExampleVocab = core.ASVocab([
    ASObject, ASLink, ASActivity, ASPost, ASDelete, ASCollection,
    ASOrderedCollection, ASCollectionPage, ASOrderedCollectionPage, ASWidget,
    ASFancyWidget
])

ExampleEnv = core.Environment(
    vocabs=[ExampleVocab],
    shortids=core.shortids_from_vocab(ExampleVocab),
    c_accessors=core.shortids_from_vocab(ExampleVocab))

# Basic tests


def test_inheritance_list():
    # Should just be itself
    assert core.astype_inheritance_list(ASObject) == \
        [ASObject]
    assert core.astype_inheritance_list(ASLink) == \
        [ASLink]

    # Should be itself, then its parent
    assert core.astype_inheritance_list(ASActivity) == \
        [ASActivity, ASObject]
예제 #6
0
    fake_type_uri("fancywidget"),
    [ASWidget],
    "FancyWidget")


# Example vocab and environment
ExampleVocab = core.ASVocab(
    [ASObject, ASLink,
     ASActivity, ASPost, ASDelete,
     ASCollection, ASOrderedCollection, ASCollectionPage,
     ASOrderedCollectionPage,
     ASWidget, ASFancyWidget])

ExampleEnv = core.Environment(
    vocabs=[ExampleVocab],
    shortids=core.shortids_from_vocab(ExampleVocab),
    c_accessors=core.shortids_from_vocab(ExampleVocab))




# Basic tests

def test_inheritance_list():
    # Should just be itself
    assert core.astype_inheritance_list(ASObject) == \
        [ASObject]
    assert core.astype_inheritance_list(ASLink) == \
        [ASLink]

    # Should be itself, then its parent