merge-requests/30/head
Bob Mottram 2024-05-07 13:13:25 +01:00
parent 327c218986
commit 4b04f1ce17
1 changed files with 45 additions and 32 deletions

View File

@ -46,16 +46,14 @@ def get_individual_post_context() -> []:
] ]
def has_valid_context(post_json_object: {}) -> bool: def _has_valid_context_list(post_json_object: {}) -> bool:
"""Are the links within the @context of a post recognised? """Are the links within the @context of a post recognised?
""" """
if not post_json_object.get('@context'):
return False
if isinstance(post_json_object['@context'], list):
for url in post_json_object['@context']: for url in post_json_object['@context']:
if not isinstance(url, str): if not isinstance(url, str):
continue continue
if url not in VALID_CONTEXTS: if url in VALID_CONTEXTS:
continue
# is this a wildcard context? # is this a wildcard context?
wildcard_found = False wildcard_found = False
for cont in VALID_CONTEXTS: for cont in VALID_CONTEXTS:
@ -67,7 +65,12 @@ def has_valid_context(post_json_object: {}) -> bool:
if not wildcard_found: if not wildcard_found:
print('Unrecognized @context: ' + url) print('Unrecognized @context: ' + url)
return False return False
elif isinstance(post_json_object['@context'], str): return True
def _has_valid_context_str(post_json_object: {}) -> bool:
"""Are the links within the @context of a post recognised?
"""
url = post_json_object['@context'] url = post_json_object['@context']
if url not in VALID_CONTEXTS: if url not in VALID_CONTEXTS:
wildcard_found = False wildcard_found = False
@ -80,10 +83,20 @@ def has_valid_context(post_json_object: {}) -> bool:
if not wildcard_found: if not wildcard_found:
print('Unrecognized @context: ' + url) print('Unrecognized @context: ' + url)
return False return False
else: return True
def has_valid_context(post_json_object: {}) -> bool:
"""Are the links within the @context of a post recognised?
"""
if not post_json_object.get('@context'):
return False
if isinstance(post_json_object['@context'], list):
return _has_valid_context_list(post_json_object)
if isinstance(post_json_object['@context'], str):
return _has_valid_context_str(post_json_object)
# not a list or string # not a list or string
return False return False
return True
def get_data_integrity_v1_schema() -> {}: def get_data_integrity_v1_schema() -> {}: