From 758747740e01a909ec9e6b8a2d84c6b6c3e9a88a Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sun, 10 Jan 2021 14:14:40 +0000 Subject: [PATCH] Wildcard schemas --- context.py | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/context.py b/context.py index de97cb38b..4375df9fc 100644 --- a/context.py +++ b/context.py @@ -11,7 +11,7 @@ validContexts = ( "https://www.w3.org/ns/activitystreams", "https://w3id.org/identity/v1", "https://w3id.org/security/v1", - "https://raitisoja.com/apschema/v1.21" + "*/apschema/v1.21" ) @@ -25,13 +25,29 @@ def hasValidContext(postJsonObject: {}) -> bool: if not isinstance(url, str): continue if url not in validContexts: - print('Unrecognized @context: ' + url) - return False + wildcardFound = False + for c in validContexts: + if c.startswith('*'): + c = c.replace('*', '') + if url.endswith(c): + wildcardFound = True + break + if not wildcardFound: + print('Unrecognized @context: ' + url) + return False elif isinstance(postJsonObject['@context'], str): url = postJsonObject['@context'] if url not in validContexts: - print('Unrecognized @context: ' + url) - return False + wildcardFound = False + for c in validContexts: + if c.startswith('*'): + c = c.replace('*', '') + if url.endswith(c): + wildcardFound = True + break + if not wildcardFound: + print('Unrecognized @context: ' + url) + return False else: # not a list or string return False @@ -39,7 +55,7 @@ def hasValidContext(postJsonObject: {}) -> bool: def getApschemaV1_21() -> {}: - # https://raitisoja.com/apschema/v1.21 + # https://domain/apschema/v1.21 return { "@context": { "zot": "https://raitisoja.com/apschema#",