Prepare for alternative property names

main
Bob Mottram 2022-05-11 17:10:38 +01:00
parent ad1dad2144
commit 6033fca4d4
14 changed files with 300 additions and 90 deletions

View File

@ -14,9 +14,14 @@ def get_briar_address(actor_json: {}) -> str:
if not actor_json.get('attachment'):
return ''
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
if not property_value['name'].lower().startswith('briar'):
if not name_value.lower().startswith('briar'):
continue
if not property_value.get('type'):
continue
@ -71,11 +76,16 @@ def set_briar_address(actor_json: {}, briar_address: str) -> None:
# remove any existing value
property_found = None
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
if not property_value.get('type'):
continue
if not property_value['name'].lower().startswith('briar'):
if not name_value.lower().startswith('briar'):
continue
property_found = property_value
break
@ -85,11 +95,16 @@ def set_briar_address(actor_json: {}, briar_address: str) -> None:
return
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
if not property_value.get('type'):
continue
if not property_value['name'].lower().startswith('briar'):
if not name_value.lower().startswith('briar'):
continue
if property_value['type'] != 'PropertyValue':
continue

View File

@ -16,9 +16,14 @@ def get_cwtch_address(actor_json: {}) -> str:
if not actor_json.get('attachment'):
return ''
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
if not property_value['name'].lower().startswith('cwtch'):
if not name_value.lower().startswith('cwtch'):
continue
if not property_value.get('type'):
continue
@ -59,11 +64,16 @@ def set_cwtch_address(actor_json: {}, cwtch_address: str) -> None:
# remove any existing value
property_found = None
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
if not property_value.get('type'):
continue
if not property_value['name'].lower().startswith('cwtch'):
if not name_value.lower().startswith('cwtch'):
continue
property_found = property_value
break
@ -73,11 +83,16 @@ def set_cwtch_address(actor_json: {}, cwtch_address: str) -> None:
return
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
if not property_value.get('type'):
continue
if not property_value['name'].lower().startswith('cwtch'):
if not name_value.lower().startswith('cwtch'):
continue
if property_value['type'] != 'PropertyValue':
continue

View File

@ -25,9 +25,14 @@ def get_donation_url(actor_json: {}) -> str:
return ''
donation_type = _get_donation_types()
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
if property_value['name'].lower() not in donation_type:
if name_value.lower() not in donation_type:
continue
if not property_value.get('type'):
continue
@ -51,9 +56,14 @@ def get_website(actor_json: {}, translate: {}) -> str:
match_strings = _get_website_strings()
match_strings.append(translate['Website'].lower())
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
if property_value['name'].lower() not in match_strings:
if name_value.lower() not in match_strings:
continue
if not property_value.get('type'):
continue
@ -92,11 +102,16 @@ def set_donation_url(actor_json: {}, donate_url: str) -> None:
# remove any existing value
property_found = None
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
if not property_value.get('type'):
continue
if not property_value['name'].lower() != donate_name:
if not name_value.lower() != donate_name:
continue
property_found = property_value
break
@ -111,11 +126,16 @@ def set_donation_url(actor_json: {}, donate_url: str) -> None:
donate_url + '</a>'
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
if not property_value.get('type'):
continue
if property_value['name'].lower() != donate_name:
if name_value.lower() != donate_name:
continue
if property_value['type'] != 'PropertyValue':
continue

View File

@ -14,9 +14,14 @@ def get_enigma_pub_key(actor_json: {}) -> str:
if not actor_json.get('attachment'):
return ''
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
if not property_value['name'].lower().startswith('enigma'):
if not name_value.lower().startswith('enigma'):
continue
if not property_value.get('type'):
continue
@ -41,11 +46,16 @@ def set_enigma_pub_key(actor_json: {}, enigma_pub_key: str) -> None:
# remove any existing value
property_found = None
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
if not property_value.get('type'):
continue
if not property_value['name'].lower().startswith('enigma'):
if not name_value.lower().startswith('enigma'):
continue
property_found = property_value
break
@ -55,11 +65,16 @@ def set_enigma_pub_key(actor_json: {}, enigma_pub_key: str) -> None:
return
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
if not property_value.get('type'):
continue
if not property_value['name'].lower().startswith('enigma'):
if not name_value.lower().startswith('enigma'):
continue
if property_value['type'] != 'PropertyValue':
continue

View File

@ -73,11 +73,16 @@ def set_actor_languages(base_dir: str, actor_json: {},
# remove any existing value
property_found = None
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
if not property_value.get('type'):
continue
if not property_value['name'].lower().startswith('languages'):
if not name_value.lower().startswith('languages'):
continue
property_found = property_value
break

View File

@ -14,9 +14,14 @@ def get_matrix_address(actor_json: {}) -> str:
if not actor_json.get('attachment'):
return ''
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
if not property_value['name'].lower().startswith('matrix'):
if not name_value.lower().startswith('matrix'):
continue
if not property_value.get('type'):
continue
@ -45,11 +50,16 @@ def set_matrix_address(actor_json: {}, matrix_address: str) -> None:
# remove any existing value
property_found = None
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
if not property_value.get('type'):
continue
if not property_value['name'].lower().startswith('matrix'):
if not name_value.lower().startswith('matrix'):
continue
property_found = property_value
break
@ -70,11 +80,16 @@ def set_matrix_address(actor_json: {}, matrix_address: str) -> None:
return
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
if not property_value.get('type'):
continue
if not property_value['name'].lower().startswith('matrix'):
if not name_value.lower().startswith('matrix'):
continue
if property_value['type'] != 'PropertyValue':
continue

View File

@ -130,9 +130,14 @@ def _person_receive_update_outbox(recent_posts_cache: {},
# update fields within actor
if 'attachment' in updated_actor_json:
for new_property_value in updated_actor_json['attachment']:
if not new_property_value.get('name'):
name_value = None
if new_property_value.get('name'):
name_value = new_property_value['name']
elif new_property_value.get('schema:name'):
name_value = new_property_value['schema:name']
if not name_value:
continue
if new_property_value['name'] not in updatable_attachments:
if name_value not in updatable_attachments:
continue
if not new_property_value.get('type'):
continue
@ -147,8 +152,14 @@ def _person_receive_update_outbox(recent_posts_cache: {},
if actor_json['attachment'][attach_idx]['type'] != \
'PropertyValue':
continue
if actor_json['attachment'][attach_idx]['name'] != \
new_property_value['name']:
attach_name = ''
if actor_json['attachment'][attach_idx].get('name'):
attach_name = \
actor_json['attachment'][attach_idx]['name']
elif actor_json['attachment'][attach_idx].get('schema:name'):
attach_name = \
actor_json['attachment'][attach_idx]['schema:name']
if attach_name != name_value:
continue
if actor_json['attachment'][attach_idx]['value'] != \
new_property_value['value']:
@ -159,7 +170,7 @@ def _person_receive_update_outbox(recent_posts_cache: {},
break
if not found:
actor_json['attachment'].append({
"name": new_property_value['name'],
"name": name_value,
"type": "PropertyValue",
"value": new_property_value['value']
})

81
pgp.py
View File

@ -36,9 +36,14 @@ def get_email_address(actor_json: {}) -> str:
if not actor_json.get('attachment'):
return ''
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
if not property_value['name'].lower().startswith('email'):
if not name_value.lower().startswith('email'):
continue
if not property_value.get('type'):
continue
@ -60,9 +65,14 @@ def get_pgp_pub_key(actor_json: {}) -> str:
if not actor_json.get('attachment'):
return ''
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
if not property_value['name'].lower().startswith('pgp'):
if not name_value.lower().startswith('pgp'):
continue
if not property_value.get('type'):
continue
@ -82,9 +92,14 @@ def get_pgp_fingerprint(actor_json: {}) -> str:
if not actor_json.get('attachment'):
return ''
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
if not property_value['name'].lower().startswith('openpgp'):
if not name_value.lower().startswith('openpgp'):
continue
if not property_value.get('type'):
continue
@ -117,11 +132,16 @@ def set_email_address(actor_json: {}, email_address: str) -> None:
# remove any existing value
property_found = None
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
if not property_value.get('type'):
continue
if not property_value['name'].lower().startswith('email'):
if not name_value.lower().startswith('email'):
continue
property_found = property_value
break
@ -131,11 +151,16 @@ def set_email_address(actor_json: {}, email_address: str) -> None:
return
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
if not property_value.get('type'):
continue
if not property_value['name'].lower().startswith('email'):
if not name_value.lower().startswith('email'):
continue
if property_value['type'] != 'PropertyValue':
continue
@ -168,11 +193,16 @@ def set_pgp_pub_key(actor_json: {}, pgp_pub_key: str) -> None:
# remove any existing value
property_found = None
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
if not property_value.get('type'):
continue
if not property_value['name'].lower().startswith('pgp'):
if not name_value.lower().startswith('pgp'):
continue
property_found = property_value
break
@ -182,11 +212,16 @@ def set_pgp_pub_key(actor_json: {}, pgp_pub_key: str) -> None:
return
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
if not property_value.get('type'):
continue
if not property_value['name'].lower().startswith('pgp'):
if not name_value.lower().startswith('pgp'):
continue
if property_value['type'] != 'PropertyValue':
continue
@ -217,11 +252,16 @@ def set_pgp_fingerprint(actor_json: {}, fingerprint: str) -> None:
# remove any existing value
property_found = None
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
if not property_value.get('type'):
continue
if not property_value['name'].lower().startswith('openpgp'):
if not name_value.lower().startswith('openpgp'):
continue
property_found = property_value
break
@ -231,11 +271,16 @@ def set_pgp_fingerprint(actor_json: {}, fingerprint: str) -> None:
return
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
if not property_value.get('type'):
continue
if not property_value['name'].lower().startswith('openpgp'):
if not name_value.lower().startswith('openpgp'):
continue
if property_value['type'] != 'PropertyValue':
continue

27
ssb.py
View File

@ -14,9 +14,14 @@ def get_ssb_address(actor_json: {}) -> str:
if not actor_json.get('attachment'):
return ''
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
if not property_value['name'].lower().startswith('ssb'):
if not name_value.lower().startswith('ssb'):
continue
if not property_value.get('type'):
continue
@ -62,11 +67,16 @@ def set_ssb_address(actor_json: {}, ssb_address: str) -> None:
# remove any existing value
property_found = None
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
if not property_value.get('type'):
continue
if not property_value['name'].lower().startswith('ssb'):
if not name_value.lower().startswith('ssb'):
continue
property_found = property_value
break
@ -76,11 +86,16 @@ def set_ssb_address(actor_json: {}, ssb_address: str) -> None:
return
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
if not property_value.get('type'):
continue
if not property_value['name'].lower().startswith('ssb'):
if not name_value.lower().startswith('ssb'):
continue
if property_value['type'] != 'PropertyValue':
continue

27
tox.py
View File

@ -14,9 +14,14 @@ def get_tox_address(actor_json: {}) -> str:
if not actor_json.get('attachment'):
return ''
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
if not property_value['name'].lower().startswith('tox'):
if not name_value.lower().startswith('tox'):
continue
if not property_value.get('type'):
continue
@ -67,11 +72,16 @@ def set_tox_address(actor_json: {}, tox_address: str) -> None:
# remove any existing value
property_found = None
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
if not property_value.get('type'):
continue
if not property_value['name'].lower().startswith('tox'):
if not name_value.lower().startswith('tox'):
continue
property_found = property_value
break
@ -81,11 +91,16 @@ def set_tox_address(actor_json: {}, tox_address: str) -> None:
return
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
if not property_value.get('type'):
continue
if not property_value['name'].lower().startswith('tox'):
if not name_value.lower().startswith('tox'):
continue
if property_value['type'] != 'PropertyValue':
continue

View File

@ -52,9 +52,14 @@ def get_actor_languages_list(actor_json: {}) -> []:
if not actor_json.get('attachment'):
return []
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
if not property_value['name'].lower().startswith('languages'):
if not name_value.lower().startswith('languages'):
continue
if not property_value.get('type'):
continue
@ -3113,9 +3118,14 @@ def get_actor_property_url(actor_json: {}, property_name: str) -> str:
return ''
property_name = property_name.lower()
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
if not property_value['name'].lower().startswith(property_name):
if not name_value.lower().startswith(property_name):
continue
if not property_value.get('type'):
continue

View File

@ -183,11 +183,16 @@ def _set_actor_property_url(actor_json: {},
# remove any existing value
property_found = None
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
if not property_value.get('type'):
continue
if not property_value['name'].lower().startswith(property_name_lower):
if not name_value.lower().startswith(property_name_lower):
continue
property_found = property_value
break
@ -210,11 +215,16 @@ def _set_actor_property_url(actor_json: {},
return
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
if not property_value.get('type'):
continue
if not property_value['name'].lower().startswith(property_name_lower):
if not name_value.lower().startswith(property_name_lower):
continue
if property_value['type'] != 'PropertyValue':
continue

View File

@ -414,9 +414,14 @@ def _webfinger_updateFromProfile(wf_json: {}, actor_json: {}) -> bool:
aliases_not_found.append(alias)
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
property_name = property_value['name'].lower()
property_name = name_value.lower()
found = False
for name, alias in webfinger_property_name.items():
if name == property_name:

36
xmpp.py
View File

@ -14,11 +14,15 @@ def get_xmpp_address(actor_json: {}) -> str:
if not actor_json.get('attachment'):
return ''
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name'].lower()
elif property_value.get('schema:name'):
name_value = property_value['schema:name'].lower()
if not name_value:
continue
name_lower = property_value['name'].lower()
if not (name_lower.startswith('xmpp') or
name_lower.startswith('jabber')):
if not (name_value.startswith('xmpp') or
name_value.startswith('jabber')):
continue
if not property_value.get('type'):
continue
@ -53,12 +57,17 @@ def set_xmpp_address(actor_json: {}, xmpp_address: str) -> None:
# remove any existing value
property_found = None
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
if not property_value.get('type'):
continue
if not (property_value['name'].lower().startswith('xmpp') or
property_value['name'].lower().startswith('jabber')):
if not (name_value.lower().startswith('xmpp') or
name_value.lower().startswith('jabber')):
continue
property_found = property_value
break
@ -68,13 +77,18 @@ def set_xmpp_address(actor_json: {}, xmpp_address: str) -> None:
return
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
if not property_value.get('type'):
continue
name_lower = property_value['name'].lower()
if not (name_lower.startswith('xmpp') or
name_lower.startswith('jabber')):
name_value = name_value.lower()
if not (name_value.startswith('xmpp') or
name_value.startswith('jabber')):
continue
if property_value['type'] != 'PropertyValue':
continue