mirror of https://gitlab.com/bashrc2/epicyon
Tidying
parent
327c218986
commit
4b04f1ce17
77
context.py
77
context.py
|
@ -46,44 +46,57 @@ def get_individual_post_context() -> []:
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def _has_valid_context_list(post_json_object: {}) -> bool:
|
||||||
|
"""Are the links within the @context of a post recognised?
|
||||||
|
"""
|
||||||
|
for url in post_json_object['@context']:
|
||||||
|
if not isinstance(url, str):
|
||||||
|
continue
|
||||||
|
if url in VALID_CONTEXTS:
|
||||||
|
continue
|
||||||
|
# is this a wildcard context?
|
||||||
|
wildcard_found = False
|
||||||
|
for cont in VALID_CONTEXTS:
|
||||||
|
if cont.startswith('*'):
|
||||||
|
cont = cont.replace('*', '')
|
||||||
|
if url.endswith(cont):
|
||||||
|
wildcard_found = True
|
||||||
|
break
|
||||||
|
if not wildcard_found:
|
||||||
|
print('Unrecognized @context: ' + url)
|
||||||
|
return False
|
||||||
|
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']
|
||||||
|
if url not in VALID_CONTEXTS:
|
||||||
|
wildcard_found = False
|
||||||
|
for cont in VALID_CONTEXTS:
|
||||||
|
if cont.startswith('*'):
|
||||||
|
cont = cont.replace('*', '')
|
||||||
|
if url.endswith(cont):
|
||||||
|
wildcard_found = True
|
||||||
|
break
|
||||||
|
if not wildcard_found:
|
||||||
|
print('Unrecognized @context: ' + url)
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def has_valid_context(post_json_object: {}) -> bool:
|
def has_valid_context(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'):
|
if not post_json_object.get('@context'):
|
||||||
return False
|
return False
|
||||||
if isinstance(post_json_object['@context'], list):
|
if isinstance(post_json_object['@context'], list):
|
||||||
for url in post_json_object['@context']:
|
return _has_valid_context_list(post_json_object)
|
||||||
if not isinstance(url, str):
|
if isinstance(post_json_object['@context'], str):
|
||||||
continue
|
return _has_valid_context_str(post_json_object)
|
||||||
if url not in VALID_CONTEXTS:
|
# not a list or string
|
||||||
# is this a wildcard context?
|
return False
|
||||||
wildcard_found = False
|
|
||||||
for cont in VALID_CONTEXTS:
|
|
||||||
if cont.startswith('*'):
|
|
||||||
cont = cont.replace('*', '')
|
|
||||||
if url.endswith(cont):
|
|
||||||
wildcard_found = True
|
|
||||||
break
|
|
||||||
if not wildcard_found:
|
|
||||||
print('Unrecognized @context: ' + url)
|
|
||||||
return False
|
|
||||||
elif isinstance(post_json_object['@context'], str):
|
|
||||||
url = post_json_object['@context']
|
|
||||||
if url not in VALID_CONTEXTS:
|
|
||||||
wildcard_found = False
|
|
||||||
for cont in VALID_CONTEXTS:
|
|
||||||
if cont.startswith('*'):
|
|
||||||
cont = cont.replace('*', '')
|
|
||||||
if url.endswith(cont):
|
|
||||||
wildcard_found = True
|
|
||||||
break
|
|
||||||
if not wildcard_found:
|
|
||||||
print('Unrecognized @context: ' + url)
|
|
||||||
return False
|
|
||||||
else:
|
|
||||||
# not a list or string
|
|
||||||
return False
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
def get_data_integrity_v1_schema() -> {}:
|
def get_data_integrity_v1_schema() -> {}:
|
||||||
|
|
Loading…
Reference in New Issue