From ad1dad2144c93947a7f66ef6fefd3b2bb1f53958 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Wed, 11 May 2022 15:34:05 +0100 Subject: [PATCH 1/9] Change to schema.org in actor --- person.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/person.py b/person.py index 98e6206a0..941aa43b5 100644 --- a/person.py +++ b/person.py @@ -232,7 +232,7 @@ def get_actor_update_json(actor_json: {}) -> {}: "@id": "as:movedTo", "@type": "@id" }, - "schema": "http://schema.org#", + "schema": "http://schema.org/", "PropertyValue": "schema:PropertyValue", "value": "schema:value", "IdentityProof": "toot:IdentityProof", @@ -338,7 +338,7 @@ def get_default_person_context() -> str: 'messageType': 'toot:messageType', 'movedTo': {'@id': 'as:movedTo', '@type': '@id'}, 'publicKeyBase64': 'toot:publicKeyBase64', - 'schema': 'http://schema.org#', + 'schema': 'http://schema.org/', 'suspended': 'toot:suspended', 'toot': 'http://joinmastodon.org/ns#', 'value': 'schema:value', From 6033fca4d462d8a54d5e33068ab0f1b13d403209 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Wed, 11 May 2022 17:10:38 +0100 Subject: [PATCH 2/9] Prepare for alternative property names --- briar.py | 27 +++++++++++++---- cwtch.py | 27 +++++++++++++---- donate.py | 36 +++++++++++++++++----- enigma.py | 27 +++++++++++++---- languages.py | 9 ++++-- matrix.py | 27 +++++++++++++---- outbox.py | 21 ++++++++++--- pgp.py | 81 ++++++++++++++++++++++++++++++++++++++----------- ssb.py | 27 +++++++++++++---- tox.py | 27 +++++++++++++---- utils.py | 18 ++++++++--- webapp_utils.py | 18 ++++++++--- webfinger.py | 9 ++++-- xmpp.py | 36 +++++++++++++++------- 14 files changed, 300 insertions(+), 90 deletions(-) diff --git a/briar.py b/briar.py index 006f2cc9b..01a64e2f5 100644 --- a/briar.py +++ b/briar.py @@ -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 diff --git a/cwtch.py b/cwtch.py index 9f531e6f7..85eef02c8 100644 --- a/cwtch.py +++ b/cwtch.py @@ -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 diff --git a/donate.py b/donate.py index 7ec71e4b6..c013b7ea4 100644 --- a/donate.py +++ b/donate.py @@ -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 + '' 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 diff --git a/enigma.py b/enigma.py index 99820529d..1cdcd7fc5 100644 --- a/enigma.py +++ b/enigma.py @@ -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 diff --git a/languages.py b/languages.py index 2a2ed4869..16f59742c 100644 --- a/languages.py +++ b/languages.py @@ -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 diff --git a/matrix.py b/matrix.py index 1fcd7b801..94d0fdb28 100644 --- a/matrix.py +++ b/matrix.py @@ -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 diff --git a/outbox.py b/outbox.py index 055d01933..f6074e9c5 100644 --- a/outbox.py +++ b/outbox.py @@ -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'] }) diff --git a/pgp.py b/pgp.py index 687baea71..1d4c8f734 100644 --- a/pgp.py +++ b/pgp.py @@ -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 diff --git a/ssb.py b/ssb.py index be7bec425..0b015095e 100644 --- a/ssb.py +++ b/ssb.py @@ -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 diff --git a/tox.py b/tox.py index c1e940043..ad3f84ffb 100644 --- a/tox.py +++ b/tox.py @@ -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 diff --git a/utils.py b/utils.py index 1b647e116..93acbd98b 100644 --- a/utils.py +++ b/utils.py @@ -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 diff --git a/webapp_utils.py b/webapp_utils.py index aaf7863c4..94002da9b 100644 --- a/webapp_utils.py +++ b/webapp_utils.py @@ -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 diff --git a/webfinger.py b/webfinger.py index c7735ed2c..a674f7310 100644 --- a/webfinger.py +++ b/webfinger.py @@ -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: diff --git a/xmpp.py b/xmpp.py index 17c672ff1..daa16c5e5 100644 --- a/xmpp.py +++ b/xmpp.py @@ -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 From 5b02a225191268f75d9ea0b06640503c9607e410 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Wed, 11 May 2022 17:16:34 +0100 Subject: [PATCH 3/9] Prepare for alternative property value --- briar.py | 4 ++-- cwtch.py | 4 ++-- donate.py | 6 +++--- enigma.py | 4 ++-- matrix.py | 4 ++-- pgp.py | 12 ++++++------ ssb.py | 4 ++-- tox.py | 4 ++-- utils.py | 4 ++-- webapp_utils.py | 2 +- webfinger.py | 2 +- xmpp.py | 4 ++-- 12 files changed, 27 insertions(+), 27 deletions(-) diff --git a/briar.py b/briar.py index 01a64e2f5..66ef59080 100644 --- a/briar.py +++ b/briar.py @@ -27,7 +27,7 @@ def get_briar_address(actor_json: {}) -> str: continue if not property_value.get('value'): continue - if property_value['type'] != 'PropertyValue': + if not property_value['type'].endswith('PropertyValue'): continue property_value['value'] = property_value['value'].strip() if len(property_value['value']) < 50: @@ -106,7 +106,7 @@ def set_briar_address(actor_json: {}, briar_address: str) -> None: continue if not name_value.lower().startswith('briar'): continue - if property_value['type'] != 'PropertyValue': + if not property_value['type'].endswith('PropertyValue'): continue property_value['value'] = briar_address return diff --git a/cwtch.py b/cwtch.py index 85eef02c8..a52b2c492 100644 --- a/cwtch.py +++ b/cwtch.py @@ -29,7 +29,7 @@ def get_cwtch_address(actor_json: {}) -> str: continue if not property_value.get('value'): continue - if property_value['type'] != 'PropertyValue': + if not property_value['type'].endswith('PropertyValue'): continue property_value['value'] = property_value['value'].strip() if len(property_value['value']) < 2: @@ -94,7 +94,7 @@ def set_cwtch_address(actor_json: {}, cwtch_address: str) -> None: continue if not name_value.lower().startswith('cwtch'): continue - if property_value['type'] != 'PropertyValue': + if not property_value['type'].endswith('PropertyValue'): continue property_value['value'] = cwtch_address return diff --git a/donate.py b/donate.py index c013b7ea4..987b01ab8 100644 --- a/donate.py +++ b/donate.py @@ -38,7 +38,7 @@ def get_donation_url(actor_json: {}) -> str: continue if not property_value.get('value'): continue - if property_value['type'] != 'PropertyValue': + if not property_value['type'].endswith('PropertyValue'): continue if ' str: """Returns briar address for the given actor """ @@ -25,26 +28,29 @@ def get_briar_address(actor_json: {}) -> str: continue if not property_value.get('type'): continue - if not property_value.get('value'): + prop_value_name, prop_value = \ + get_attachment_property_value(property_value) + if not prop_value: continue if not property_value['type'].endswith('PropertyValue'): continue - property_value['value'] = property_value['value'].strip() - if len(property_value['value']) < 50: + property_value[prop_value_name] = prop_value.strip() + if len(property_value[prop_value_name]) < 50: continue - if not property_value['value'].startswith('briar://'): + if not property_value[prop_value_name].startswith('briar://'): continue - if property_value['value'].lower() != property_value['value']: + if property_value[prop_value_name].lower() != \ + property_value[prop_value_name]: continue - if '"' in property_value['value']: + if '"' in property_value[prop_value_name]: continue - if ' ' in property_value['value']: + if ' ' in property_value[prop_value_name]: continue - if ',' in property_value['value']: + if ',' in property_value[prop_value_name]: continue - if '.' in property_value['value']: + if '.' in property_value[prop_value_name]: continue - return property_value['value'] + return property_value[prop_value_name] return '' @@ -108,7 +114,11 @@ def set_briar_address(actor_json: {}, briar_address: str) -> None: continue if not property_value['type'].endswith('PropertyValue'): continue - property_value['value'] = briar_address + prop_value_name, _ = \ + get_attachment_property_value(property_value) + if not prop_value_name: + continue + property_value[prop_value_name] = briar_address return new_briar_address = { diff --git a/cwtch.py b/cwtch.py index a52b2c492..4849ac014 100644 --- a/cwtch.py +++ b/cwtch.py @@ -8,6 +8,7 @@ __status__ = "Production" __module_group__ = "Profile Metadata" import re +from utils import get_attachment_property_value def get_cwtch_address(actor_json: {}) -> str: @@ -27,22 +28,25 @@ def get_cwtch_address(actor_json: {}) -> str: continue if not property_value.get('type'): continue - if not property_value.get('value'): + prop_value_name, prop_value = \ + get_attachment_property_value(property_value) + if not prop_value: continue if not property_value['type'].endswith('PropertyValue'): continue - property_value['value'] = property_value['value'].strip() - if len(property_value['value']) < 2: + property_value[prop_value_name] = \ + property_value[prop_value_name].strip() + if len(property_value[prop_value_name]) < 2: continue - if '"' in property_value['value']: + if '"' in property_value[prop_value_name]: continue - if ' ' in property_value['value']: + if ' ' in property_value[prop_value_name]: continue - if ',' in property_value['value']: + if ',' in property_value[prop_value_name]: continue - if '.' in property_value['value']: + if '.' in property_value[prop_value_name]: continue - return property_value['value'] + return property_value[prop_value_name] return '' @@ -96,7 +100,11 @@ def set_cwtch_address(actor_json: {}, cwtch_address: str) -> None: continue if not property_value['type'].endswith('PropertyValue'): continue - property_value['value'] = cwtch_address + prop_value_name, prop_value = \ + get_attachment_property_value(property_value) + if not prop_value_name: + continue + property_value[prop_value_name] = cwtch_address return new_cwtch_address = { diff --git a/donate.py b/donate.py index 987b01ab8..343c8a817 100644 --- a/donate.py +++ b/donate.py @@ -8,6 +8,9 @@ __status__ = "Production" __module_group__ = "Profile Metadata" +from utils import get_attachment_property_value + + def _get_donation_types() -> []: return ('patreon', 'paypal', 'gofundme', 'liberapay', 'kickstarter', 'indiegogo', 'crowdsupply', @@ -36,13 +39,15 @@ def get_donation_url(actor_json: {}) -> str: continue if not property_value.get('type'): continue - if not property_value.get('value'): + prop_value_name, prop_value = \ + get_attachment_property_value(property_value) + if not prop_value: continue if not property_value['type'].endswith('PropertyValue'): continue - if ' str: continue if not property_value.get('type'): continue - if not property_value.get('value'): + prop_value_name, _ = \ + get_attachment_property_value(property_value) + if not prop_value_name: continue if not property_value['type'].endswith('PropertyValue'): continue - return property_value['value'] + return property_value[prop_value_name] return '' @@ -139,7 +146,11 @@ def set_donation_url(actor_json: {}, donate_url: str) -> None: continue if not property_value['type'].endswith('PropertyValue'): continue - property_value['value'] = donate_value + prop_value_name, _ = \ + get_attachment_property_value(property_value) + if not prop_value_name: + continue + property_value[prop_value_name] = donate_value return new_donate = { diff --git a/enigma.py b/enigma.py index f6810733c..0612548b5 100644 --- a/enigma.py +++ b/enigma.py @@ -8,6 +8,9 @@ __status__ = "Production" __module_group__ = "Profile Metadata" +from utils import get_attachment_property_value + + def get_enigma_pub_key(actor_json: {}) -> str: """Returns Enigma public key for the given actor """ @@ -25,11 +28,13 @@ def get_enigma_pub_key(actor_json: {}) -> str: continue if not property_value.get('type'): continue - if not property_value.get('value'): + prop_value_name, _ = \ + get_attachment_property_value(property_value) + if not prop_value_name: continue if not property_value['type'].endswith('PropertyValue'): continue - return property_value['value'] + return property_value[prop_value_name] return '' @@ -78,7 +83,11 @@ def set_enigma_pub_key(actor_json: {}, enigma_pub_key: str) -> None: continue if not property_value['type'].endswith('PropertyValue'): continue - property_value['value'] = enigma_pub_key + prop_value_name, _ = \ + get_attachment_property_value(property_value) + if not prop_value_name: + continue + property_value[prop_value_name] = enigma_pub_key return new_enigma_pub_key = { diff --git a/matrix.py b/matrix.py index c332df3aa..e9cf81483 100644 --- a/matrix.py +++ b/matrix.py @@ -8,6 +8,9 @@ __status__ = "Production" __module_group__ = "Profile Metadata" +from utils import get_attachment_property_value + + def get_matrix_address(actor_json: {}) -> str: """Returns matrix address for the given actor """ @@ -25,19 +28,21 @@ def get_matrix_address(actor_json: {}) -> str: continue if not property_value.get('type'): continue - if not property_value.get('value'): + prop_value_name, _ = \ + get_attachment_property_value(property_value) + if not prop_value_name: continue if not property_value['type'].endswith('PropertyValue'): continue - if '@' not in property_value['value']: + if '@' not in property_value[prop_value_name]: continue - if not property_value['value'].startswith('@'): + if not property_value[prop_value_name].startswith('@'): continue - if ':' not in property_value['value']: + if ':' not in property_value[prop_value_name]: continue - if '"' in property_value['value']: + if '"' in property_value[prop_value_name]: continue - return property_value['value'] + return property_value[prop_value_name] return '' @@ -93,7 +98,11 @@ def set_matrix_address(actor_json: {}, matrix_address: str) -> None: continue if not property_value['type'].endswith('PropertyValue'): continue - property_value['value'] = matrix_address + prop_value_name, _ = \ + get_attachment_property_value(property_value) + if not prop_value_name: + continue + property_value[prop_value_name] = matrix_address return new_matrix_address = { diff --git a/outbox.py b/outbox.py index f6074e9c5..63973e610 100644 --- a/outbox.py +++ b/outbox.py @@ -15,6 +15,7 @@ from posts import outbox_message_create_wrap from posts import save_post_to_box from posts import send_to_followers_thread from posts import send_to_named_addresses_thread +from utils import get_attachment_property_value from utils import get_account_timezone from utils import has_object_string_type from utils import get_base_content_from_post @@ -141,7 +142,9 @@ def _person_receive_update_outbox(recent_posts_cache: {}, continue if not new_property_value.get('type'): continue - if not new_property_value.get('value'): + prop_value_name, _ = \ + get_attachment_property_value(new_property_value) + if not prop_value_name: continue if new_property_value['type'] != 'PropertyValue': continue @@ -161,10 +164,10 @@ def _person_receive_update_outbox(recent_posts_cache: {}, actor_json['attachment'][attach_idx]['schema:name'] if attach_name != name_value: continue - if actor_json['attachment'][attach_idx]['value'] != \ - new_property_value['value']: - actor_json['attachment'][attach_idx]['value'] = \ - new_property_value['value'] + if actor_json['attachment'][attach_idx][prop_value_name] != \ + new_property_value[prop_value_name]: + actor_json['attachment'][attach_idx][prop_value_name] = \ + new_property_value[prop_value_name] actor_changed = True found = True break @@ -172,7 +175,7 @@ def _person_receive_update_outbox(recent_posts_cache: {}, actor_json['attachment'].append({ "name": name_value, "type": "PropertyValue", - "value": new_property_value['value'] + "value": new_property_value[prop_value_name] }) actor_changed = True # save actor to file diff --git a/pgp.py b/pgp.py index ebbaa1ef1..cb32e20d7 100644 --- a/pgp.py +++ b/pgp.py @@ -30,6 +30,9 @@ from cwtch import get_cwtch_address from blog import get_blog_address +from utils import get_attachment_property_value + + def get_email_address(actor_json: {}) -> str: """Returns the email address for the given actor """ @@ -47,15 +50,17 @@ def get_email_address(actor_json: {}) -> str: continue if not property_value.get('type'): continue - if not property_value.get('value'): + prop_value_name, _ = \ + get_attachment_property_value(property_value) + if not prop_value_name: continue if not property_value['type'].endswith('PropertyValue'): continue - if '@' not in property_value['value']: + if '@' not in property_value[prop_value_name]: continue - if '.' not in property_value['value']: + if '.' not in property_value[prop_value_name]: continue - return property_value['value'] + return property_value[prop_value_name] return '' @@ -76,13 +81,15 @@ def get_pgp_pub_key(actor_json: {}) -> str: continue if not property_value.get('type'): continue - if not property_value.get('value'): + prop_value_name, _ = \ + get_attachment_property_value(property_value) + if not prop_value_name: continue if not property_value['type'].endswith('PropertyValue'): continue - if not contains_pgp_public_key(property_value['value']): + if not contains_pgp_public_key(property_value[prop_value_name]): continue - return property_value['value'] + return property_value[prop_value_name] return '' @@ -103,13 +110,15 @@ def get_pgp_fingerprint(actor_json: {}) -> str: continue if not property_value.get('type'): continue - if not property_value.get('value'): + prop_value_name, _ = \ + get_attachment_property_value(property_value) + if not prop_value_name: continue if not property_value['type'].endswith('PropertyValue'): continue - if len(property_value['value']) < 10: + if len(property_value[prop_value_name]) < 10: continue - return property_value['value'] + return property_value[prop_value_name] return '' @@ -164,7 +173,11 @@ def set_email_address(actor_json: {}, email_address: str) -> None: continue if not property_value['type'].endswith('PropertyValue'): continue - property_value['value'] = email_address + prop_value_name, _ = \ + get_attachment_property_value(property_value) + if not prop_value_name: + continue + property_value[prop_value_name] = email_address return new_email_address = { diff --git a/ssb.py b/ssb.py index 576253b46..f13e5fd66 100644 --- a/ssb.py +++ b/ssb.py @@ -8,6 +8,9 @@ __status__ = "Production" __module_group__ = "Profile Metadata" +from utils import get_attachment_property_value + + def get_ssb_address(actor_json: {}) -> str: """Returns ssb address for the given actor """ @@ -25,22 +28,25 @@ def get_ssb_address(actor_json: {}) -> str: continue if not property_value.get('type'): continue - if not property_value.get('value'): + prop_value_name, _ = \ + get_attachment_property_value(property_value) + if not prop_value_name: continue if not property_value['type'].endswith('PropertyValue'): continue - property_value['value'] = property_value['value'].strip() - if not property_value['value'].startswith('@'): + property_value[prop_value_name] = \ + property_value[prop_value_name].strip() + if not property_value[prop_value_name].startswith('@'): continue - if '=.' not in property_value['value']: + if '=.' not in property_value[prop_value_name]: continue - if '"' in property_value['value']: + if '"' in property_value[prop_value_name]: continue - if ' ' in property_value['value']: + if ' ' in property_value[prop_value_name]: continue - if ',' in property_value['value']: + if ',' in property_value[prop_value_name]: continue - return property_value['value'] + return property_value[prop_value_name] return '' @@ -99,7 +105,11 @@ def set_ssb_address(actor_json: {}, ssb_address: str) -> None: continue if not property_value['type'].endswith('PropertyValue'): continue - property_value['value'] = ssb_address + prop_value_name, _ = \ + get_attachment_property_value(property_value) + if not prop_value_name: + continue + property_value[prop_value_name] = ssb_address return new_ssb_address = { diff --git a/tox.py b/tox.py index f49b37fe8..682f389a2 100644 --- a/tox.py +++ b/tox.py @@ -8,6 +8,9 @@ __status__ = "Production" __module_group__ = "Profile Metadata" +from utils import get_attachment_property_value + + def get_tox_address(actor_json: {}) -> str: """Returns tox address for the given actor """ @@ -25,24 +28,28 @@ def get_tox_address(actor_json: {}) -> str: continue if not property_value.get('type'): continue - if not property_value.get('value'): + prop_value_name, _ = \ + get_attachment_property_value(property_value) + if not prop_value_name: continue if not property_value['type'].endswith('PropertyValue'): continue - property_value['value'] = property_value['value'].strip() - if len(property_value['value']) != 76: + property_value[prop_value_name] = \ + property_value[prop_value_name].strip() + if len(property_value[prop_value_name]) != 76: continue - if property_value['value'].upper() != property_value['value']: + if property_value[prop_value_name].upper() != \ + property_value[prop_value_name]: continue - if '"' in property_value['value']: + if '"' in property_value[prop_value_name]: continue - if ' ' in property_value['value']: + if ' ' in property_value[prop_value_name]: continue - if ',' in property_value['value']: + if ',' in property_value[prop_value_name]: continue - if '.' in property_value['value']: + if '.' in property_value[prop_value_name]: continue - return property_value['value'] + return property_value[prop_value_name] return '' @@ -104,7 +111,11 @@ def set_tox_address(actor_json: {}, tox_address: str) -> None: continue if not property_value['type'].endswith('PropertyValue'): continue - property_value['value'] = tox_address + prop_value_name, _ = \ + get_attachment_property_value(property_value) + if not prop_value_name: + continue + property_value[prop_value_name] = tox_address return new_tox_address = { diff --git a/utils.py b/utils.py index 0f43f078b..6d852772e 100644 --- a/utils.py +++ b/utils.py @@ -63,16 +63,18 @@ def get_actor_languages_list(actor_json: {}) -> []: continue if not property_value.get('type'): continue - if not property_value.get('value'): + prop_value_name, _ = \ + get_attachment_property_value(property_value) + if not prop_value_name: continue if not property_value['type'].endswith('PropertyValue'): continue - if isinstance(property_value['value'], list): - lang_list = property_value['value'] + if isinstance(property_value[prop_value_name], list): + lang_list = property_value[prop_value_name] lang_list.sort() return lang_list - if isinstance(property_value['value'], str): - lang_str = property_value['value'] + if isinstance(property_value[prop_value_name], str): + lang_str = property_value[prop_value_name] lang_list_temp = [] if ',' in lang_str: lang_list_temp = lang_str.split(',') @@ -3129,26 +3131,28 @@ def get_actor_property_url(actor_json: {}, property_name: str) -> str: continue if not property_value.get('type'): continue - if not property_value.get('value'): + prop_value_name, _ = \ + get_attachment_property_value(property_value) + if not prop_value_name: continue if not property_value['type'].endswith('PropertyValue'): continue - property_value['value'] = property_value['value'].strip() + property_value['value'] = property_value[prop_value_name].strip() prefixes = get_protocol_prefixes() prefix_found = False for prefix in prefixes: - if property_value['value'].startswith(prefix): + if property_value[prop_value_name].startswith(prefix): prefix_found = True break if not prefix_found: continue - if '.' not in property_value['value']: + if '.' not in property_value[prop_value_name]: continue - if ' ' in property_value['value']: + if ' ' in property_value[prop_value_name]: continue - if ',' in property_value['value']: + if ',' in property_value[prop_value_name]: continue - return property_value['value'] + return property_value[prop_value_name] return '' @@ -3662,3 +3666,20 @@ def disallow_reply(content: str) -> bool: if diss in content: return True return False + + +def get_attachment_property_value(property_value: {}) -> (str, str): + """Returns the fieldname and value for an attachment property + """ + prop_value = None + prop_value_name = None + if property_value.get('value'): + prop_value = property_value['value'] + prop_value_name = 'value' + elif property_value.get('http://schema.org#value'): + prop_value = property_value['http://schema.org#value'] + prop_value_name = 'http://schema.org#value' + elif property_value.get('https://schema.org#value'): + prop_value = property_value['https://schema.org#value'] + prop_value_name = 'https://schema.org#value' + return prop_value_name, prop_value diff --git a/webapp_utils.py b/webapp_utils.py index b25b550c9..5cfee26bd 100644 --- a/webapp_utils.py +++ b/webapp_utils.py @@ -11,6 +11,7 @@ import os from shutil import copyfile from collections import OrderedDict from session import get_json +from utils import get_attachment_property_value from utils import is_account_dir from utils import remove_html from utils import get_protocol_prefixes @@ -228,7 +229,11 @@ def _set_actor_property_url(actor_json: {}, continue if not property_value['type'].endswith('PropertyValue'): continue - property_value['value'] = url + prop_value_name, _ = \ + get_attachment_property_value(property_value) + if not prop_value_name: + continue + property_value[prop_value_name] = url return new_address = { diff --git a/webfinger.py b/webfinger.py index d2b936f8c..d2feaec80 100644 --- a/webfinger.py +++ b/webfinger.py @@ -12,6 +12,7 @@ import urllib.parse from session import get_json from cache import store_webfinger_in_cache from cache import get_webfinger_from_cache +from utils import get_attachment_property_value from utils import get_full_domain from utils import load_json from utils import load_json_onionify @@ -433,12 +434,14 @@ def _webfinger_updateFromProfile(wf_json: {}, actor_json: {}) -> bool: continue if not property_value.get('type'): continue - if not property_value.get('value'): + prop_value_name, _ = \ + get_attachment_property_value(property_value) + if not prop_value_name: continue if not property_value['type'].endswith('PropertyValue'): continue - new_value = property_value['value'].strip() + new_value = property_value[prop_value_name].strip() if '://' in new_value: new_value = new_value.split('://')[1] diff --git a/xmpp.py b/xmpp.py index 2c940213b..1cdc57510 100644 --- a/xmpp.py +++ b/xmpp.py @@ -8,6 +8,9 @@ __status__ = "Production" __module_group__ = "Profile Metadata" +from utils import get_attachment_property_value + + def get_xmpp_address(actor_json: {}) -> str: """Returns xmpp address for the given actor """ @@ -26,15 +29,17 @@ def get_xmpp_address(actor_json: {}) -> str: continue if not property_value.get('type'): continue - if not property_value.get('value'): + prop_value_name, _ = \ + get_attachment_property_value(property_value) + if not prop_value_name: continue if not property_value['type'].endswith('PropertyValue'): continue - if '@' not in property_value['value']: + if '@' not in property_value[prop_value_name]: continue - if '"' in property_value['value']: + if '"' in property_value[prop_value_name]: continue - return property_value['value'] + return property_value[prop_value_name] return '' @@ -92,7 +97,11 @@ def set_xmpp_address(actor_json: {}, xmpp_address: str) -> None: continue if not property_value['type'].endswith('PropertyValue'): continue - property_value['value'] = xmpp_address + prop_value_name, _ = \ + get_attachment_property_value(property_value) + if not prop_value_name: + continue + property_value[prop_value_name] = xmpp_address return new_xmpp_address = { From fc2697c97669335f9448c4c81f507502f8291130 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Wed, 11 May 2022 18:23:01 +0100 Subject: [PATCH 5/9] Alternative property value field --- outbox.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/outbox.py b/outbox.py index 63973e610..bd16edfb7 100644 --- a/outbox.py +++ b/outbox.py @@ -146,14 +146,14 @@ def _person_receive_update_outbox(recent_posts_cache: {}, get_attachment_property_value(new_property_value) if not prop_value_name: continue - if new_property_value['type'] != 'PropertyValue': + if not new_property_value['type'].endswith('PropertyValue'): continue if 'attachment' not in actor_json: continue found = False for attach_idx, _ in enumerate(actor_json['attachment']): - if actor_json['attachment'][attach_idx]['type'] != \ - 'PropertyValue': + attach_type = actor_json['attachment'][attach_idx]['type'] + if not attach_type.endswith('PropertyValue'): continue attach_name = '' if actor_json['attachment'][attach_idx].get('name'): From 471c9d4a7298d203d815bf0f4547b7b46cfe83ba Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Wed, 11 May 2022 18:39:23 +0100 Subject: [PATCH 6/9] Generalize attachment properties on actors --- person.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/person.py b/person.py index 941aa43b5..ad29dee32 100644 --- a/person.py +++ b/person.py @@ -38,6 +38,7 @@ from roles import set_role from roles import set_rolesFromList from roles import get_actor_roles_list from media import process_meta_data +from utils import get_attachment_property_value from utils import get_nickname_from_actor from utils import remove_html from utils import contains_invalid_chars @@ -1789,10 +1790,14 @@ def valid_sending_actor(session, base_dir: str, continue if isinstance(tag['name'], str): bio_str += ' ' + tag['name'] - if tag.get('value'): + prop_value_name, _ = \ + get_attachment_property_value(tag) + if not prop_value_name: continue - if isinstance(tag['value'], str): - bio_str += ' ' + tag['value'] + if tag.get(prop_value_name): + continue + if isinstance(tag[prop_value_name], str): + bio_str += ' ' + tag[prop_value_name] if actor_json.get('name'): bio_str += ' ' + remove_html(actor_json['name']) @@ -1814,19 +1819,20 @@ def valid_sending_actor(session, base_dir: str, for tag in actor_json['attachment']: if not isinstance(tag, dict): continue - if not tag.get('name'): + if not tag.get('name') and not tag.get('schema:name'): continue no_of_tags += 1 - if not tag.get('value'): + prop_value_name, _ = get_attachment_property_value(tag) + if not prop_value_name: tags_without_value += 1 continue - if not isinstance(tag['value'], str): + if not isinstance(tag[prop_value_name], str): tags_without_value += 1 continue - if not tag['value'].strip(): + if not tag[prop_value_name].strip(): tags_without_value += 1 continue - if len(tag['value']) < 2: + if len(tag[prop_value_name]) < 2: tags_without_value += 1 continue if no_of_tags > 0: From ed9854de107eb46e53afdaeacfd494771f8a003d Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Wed, 11 May 2022 19:04:58 +0100 Subject: [PATCH 7/9] Supporting alternative name and value properties in attachments --- pgp.py | 21 +++++++++++++++------ utils.py | 26 +++++++++++++++++++------- webapp_utils.py | 13 +++++++++---- 3 files changed, 43 insertions(+), 17 deletions(-) diff --git a/pgp.py b/pgp.py index cb32e20d7..2a13c2c98 100644 --- a/pgp.py +++ b/pgp.py @@ -238,7 +238,11 @@ def set_pgp_pub_key(actor_json: {}, pgp_pub_key: str) -> None: continue if not property_value['type'].endswith('PropertyValue'): continue - property_value['value'] = pgp_pub_key + prop_value_name, _ = \ + get_attachment_property_value(property_value) + if not prop_value_name: + continue + property_value[prop_value_name] = pgp_pub_key return newpgp_pub_key = { @@ -297,7 +301,11 @@ def set_pgp_fingerprint(actor_json: {}, fingerprint: str) -> None: continue if not property_value['type'].endswith('PropertyValue'): continue - property_value['value'] = fingerprint.strip() + prop_value_name, _ = \ + get_attachment_property_value(property_value) + if not prop_value_name: + continue + property_value[prop_value_name] = fingerprint.strip() return newpgp_fingerprint = { @@ -509,12 +517,13 @@ def _get_pgp_public_key_from_actor(signing_priv_key_pem: str, for tag in actor_json['attachment']: if not isinstance(tag, dict): continue - if not tag.get('value'): + prop_value_name, _ = get_attachment_property_value(tag) + if not prop_value_name: continue - if not isinstance(tag['value'], str): + if not isinstance(tag[prop_value_name], str): continue - if contains_pgp_public_key(tag['value']): - return tag['value'] + if contains_pgp_public_key(tag[prop_value_name]): + return tag[prop_value_name] return None diff --git a/utils.py b/utils.py index 6d852772e..a86d57e33 100644 --- a/utils.py +++ b/utils.py @@ -1106,14 +1106,22 @@ def get_gender_from_bio(base_dir: str, actor: str, person_cache: {}, for tag in tags_list: if not isinstance(tag, dict): continue - if not tag.get('name') or not tag.get('value'): + name_value = None + if tag.get('name'): + name_value = tag['name'] + if tag.get('schema:name'): + name_value = tag['schema:name'] + if not name_value: continue - if tag['name'].lower() == \ + prop_value_name, _ = get_attachment_property_value(tag) + if not prop_value_name: + continue + if name_value.lower() == \ translate['gender'].lower(): - bio_found = tag['value'] + bio_found = name_value break - if tag['name'].lower().startswith(pronoun_str): - bio_found = tag['value'] + if name_value.lower().startswith(pronoun_str): + bio_found = name_value break # the field name could be anything, # just look at the value @@ -1121,9 +1129,13 @@ def get_gender_from_bio(base_dir: str, actor: str, person_cache: {}, for tag in tags_list: if not isinstance(tag, dict): continue - if not tag.get('name') or not tag.get('value'): + if not tag.get('name') and not tag.get('schema:name'): continue - gender = _gender_from_string(translate, tag['value']) + prop_value_name, _ = get_attachment_property_value(tag) + if not prop_value_name: + continue + gender = \ + _gender_from_string(translate, tag[prop_value_name]) if gender: return gender # if not then use the bio diff --git a/webapp_utils.py b/webapp_utils.py index 5cfee26bd..d2141bb46 100644 --- a/webapp_utils.py +++ b/webapp_utils.py @@ -802,11 +802,16 @@ def html_header_with_person_markup(css_filename: str, instance_title: str, ) for attach_json in actor_json['attachment']: if not attach_json.get('name'): + if not attach_json.get('schema:name'): + continue + prop_value_name, _ = get_attachment_property_value(attach_json) + if not prop_value_name: continue - if not attach_json.get('value'): - continue - name = attach_json['name'].lower() - value = attach_json['value'] + if attach_json.get('name'): + name = attach_json['name'].lower() + else: + name = attach_json['schema:name'].lower() + value = attach_json[prop_value_name] for og_tag in og_tags: if name != og_tag: continue From eb9609211fb14072bf8f8cf380db1d122150336f Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Wed, 11 May 2022 19:16:20 +0100 Subject: [PATCH 8/9] Tidying --- utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils.py b/utils.py index a86d57e33..b80523a69 100644 --- a/utils.py +++ b/utils.py @@ -1118,10 +1118,10 @@ def get_gender_from_bio(base_dir: str, actor: str, person_cache: {}, continue if name_value.lower() == \ translate['gender'].lower(): - bio_found = name_value + bio_found = tag[prop_value_name] break if name_value.lower().startswith(pronoun_str): - bio_found = name_value + bio_found = tag[prop_value_name] break # the field name could be anything, # just look at the value From 0e80ddb83a9471f5fba9bfc20029cf67a22c671e Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Wed, 11 May 2022 20:05:21 +0100 Subject: [PATCH 9/9] Tidying --- utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils.py b/utils.py index b80523a69..bc75b1e10 100644 --- a/utils.py +++ b/utils.py @@ -3689,9 +3689,9 @@ def get_attachment_property_value(property_value: {}) -> (str, str): prop_value = property_value['value'] prop_value_name = 'value' elif property_value.get('http://schema.org#value'): - prop_value = property_value['http://schema.org#value'] prop_value_name = 'http://schema.org#value' + prop_value = property_value[prop_value_name] elif property_value.get('https://schema.org#value'): - prop_value = property_value['https://schema.org#value'] prop_value_name = 'https://schema.org#value' + prop_value = property_value[prop_value_name] return prop_value_name, prop_value