XMerge branch 'main' of gitlab.com:bashrc2/epicyon

merge-requests/30/head
Bob Mottram 2022-05-11 23:33:03 +01:00
commit 8fd4ae2610
15 changed files with 603 additions and 239 deletions

View File

@ -8,38 +8,49 @@ __status__ = "Production"
__module_group__ = "Profile Metadata" __module_group__ = "Profile Metadata"
from utils import get_attachment_property_value
def get_briar_address(actor_json: {}) -> str: def get_briar_address(actor_json: {}) -> str:
"""Returns briar address for the given actor """Returns briar address for the given actor
""" """
if not actor_json.get('attachment'): if not actor_json.get('attachment'):
return '' return ''
for property_value in actor_json['attachment']: 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 continue
if not property_value['name'].lower().startswith('briar'): if not name_value.lower().startswith('briar'):
continue continue
if not property_value.get('type'): if not property_value.get('type'):
continue continue
if not property_value.get('value'): prop_value_name, prop_value = \
get_attachment_property_value(property_value)
if not prop_value:
continue continue
if property_value['type'] != 'PropertyValue': if not property_value['type'].endswith('PropertyValue'):
continue continue
property_value['value'] = property_value['value'].strip() property_value[prop_value_name] = prop_value.strip()
if len(property_value['value']) < 50: if len(property_value[prop_value_name]) < 50:
continue continue
if not property_value['value'].startswith('briar://'): if not property_value[prop_value_name].startswith('briar://'):
continue continue
if property_value['value'].lower() != property_value['value']: if property_value[prop_value_name].lower() != \
property_value[prop_value_name]:
continue continue
if '"' in property_value['value']: if '"' in property_value[prop_value_name]:
continue continue
if ' ' in property_value['value']: if ' ' in property_value[prop_value_name]:
continue continue
if ',' in property_value['value']: if ',' in property_value[prop_value_name]:
continue continue
if '.' in property_value['value']: if '.' in property_value[prop_value_name]:
continue continue
return property_value['value'] return property_value[prop_value_name]
return '' return ''
@ -71,11 +82,16 @@ def set_briar_address(actor_json: {}, briar_address: str) -> None:
# remove any existing value # remove any existing value
property_found = None property_found = None
for property_value in actor_json['attachment']: 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 continue
if not property_value.get('type'): if not property_value.get('type'):
continue continue
if not property_value['name'].lower().startswith('briar'): if not name_value.lower().startswith('briar'):
continue continue
property_found = property_value property_found = property_value
break break
@ -85,15 +101,24 @@ def set_briar_address(actor_json: {}, briar_address: str) -> None:
return return
for property_value in actor_json['attachment']: 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 continue
if not property_value.get('type'): if not property_value.get('type'):
continue continue
if not property_value['name'].lower().startswith('briar'): if not name_value.lower().startswith('briar'):
continue continue
if property_value['type'] != 'PropertyValue': if not property_value['type'].endswith('PropertyValue'):
continue 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 return
new_briar_address = { new_briar_address = {

View File

@ -8,6 +8,7 @@ __status__ = "Production"
__module_group__ = "Profile Metadata" __module_group__ = "Profile Metadata"
import re import re
from utils import get_attachment_property_value
def get_cwtch_address(actor_json: {}) -> str: def get_cwtch_address(actor_json: {}) -> str:
@ -16,28 +17,36 @@ def get_cwtch_address(actor_json: {}) -> str:
if not actor_json.get('attachment'): if not actor_json.get('attachment'):
return '' return ''
for property_value in actor_json['attachment']: 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 continue
if not property_value['name'].lower().startswith('cwtch'): if not name_value.lower().startswith('cwtch'):
continue continue
if not property_value.get('type'): if not property_value.get('type'):
continue continue
if not property_value.get('value'): prop_value_name, prop_value = \
get_attachment_property_value(property_value)
if not prop_value:
continue continue
if property_value['type'] != 'PropertyValue': if not property_value['type'].endswith('PropertyValue'):
continue continue
property_value['value'] = property_value['value'].strip() property_value[prop_value_name] = \
if len(property_value['value']) < 2: property_value[prop_value_name].strip()
if len(property_value[prop_value_name]) < 2:
continue continue
if '"' in property_value['value']: if '"' in property_value[prop_value_name]:
continue continue
if ' ' in property_value['value']: if ' ' in property_value[prop_value_name]:
continue continue
if ',' in property_value['value']: if ',' in property_value[prop_value_name]:
continue continue
if '.' in property_value['value']: if '.' in property_value[prop_value_name]:
continue continue
return property_value['value'] return property_value[prop_value_name]
return '' return ''
@ -59,11 +68,16 @@ def set_cwtch_address(actor_json: {}, cwtch_address: str) -> None:
# remove any existing value # remove any existing value
property_found = None property_found = None
for property_value in actor_json['attachment']: 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 continue
if not property_value.get('type'): if not property_value.get('type'):
continue continue
if not property_value['name'].lower().startswith('cwtch'): if not name_value.lower().startswith('cwtch'):
continue continue
property_found = property_value property_found = property_value
break break
@ -73,15 +87,24 @@ def set_cwtch_address(actor_json: {}, cwtch_address: str) -> None:
return return
for property_value in actor_json['attachment']: 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 continue
if not property_value.get('type'): if not property_value.get('type'):
continue continue
if not property_value['name'].lower().startswith('cwtch'): if not name_value.lower().startswith('cwtch'):
continue continue
if property_value['type'] != 'PropertyValue': if not property_value['type'].endswith('PropertyValue'):
continue 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 return
new_cwtch_address = { new_cwtch_address = {

View File

@ -8,6 +8,9 @@ __status__ = "Production"
__module_group__ = "Profile Metadata" __module_group__ = "Profile Metadata"
from utils import get_attachment_property_value
def _get_donation_types() -> []: def _get_donation_types() -> []:
return ('patreon', 'paypal', 'gofundme', 'liberapay', return ('patreon', 'paypal', 'gofundme', 'liberapay',
'kickstarter', 'indiegogo', 'crowdsupply', 'kickstarter', 'indiegogo', 'crowdsupply',
@ -25,19 +28,26 @@ def get_donation_url(actor_json: {}) -> str:
return '' return ''
donation_type = _get_donation_types() donation_type = _get_donation_types()
for property_value in actor_json['attachment']: 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 continue
if property_value['name'].lower() not in donation_type: if name_value.lower() not in donation_type:
continue continue
if not property_value.get('type'): if not property_value.get('type'):
continue continue
if not property_value.get('value'): prop_value_name, prop_value = \
get_attachment_property_value(property_value)
if not prop_value:
continue continue
if property_value['type'] != 'PropertyValue': if not property_value['type'].endswith('PropertyValue'):
continue continue
if '<a href="' not in property_value['value']: if '<a href="' not in property_value[prop_value_name]:
continue continue
donate_url = property_value['value'].split('<a href="')[1] donate_url = property_value[prop_value_name].split('<a href="')[1]
if '"' in donate_url: if '"' in donate_url:
return donate_url.split('"')[0] return donate_url.split('"')[0]
return '' return ''
@ -51,17 +61,24 @@ def get_website(actor_json: {}, translate: {}) -> str:
match_strings = _get_website_strings() match_strings = _get_website_strings()
match_strings.append(translate['Website'].lower()) match_strings.append(translate['Website'].lower())
for property_value in actor_json['attachment']: 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 continue
if property_value['name'].lower() not in match_strings: if name_value.lower() not in match_strings:
continue continue
if not property_value.get('type'): if not property_value.get('type'):
continue continue
if not property_value.get('value'): prop_value_name, _ = \
get_attachment_property_value(property_value)
if not prop_value_name:
continue continue
if property_value['type'] != 'PropertyValue': if not property_value['type'].endswith('PropertyValue'):
continue continue
return property_value['value'] return property_value[prop_value_name]
return '' return ''
@ -92,11 +109,16 @@ def set_donation_url(actor_json: {}, donate_url: str) -> None:
# remove any existing value # remove any existing value
property_found = None property_found = None
for property_value in actor_json['attachment']: 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 continue
if not property_value.get('type'): if not property_value.get('type'):
continue continue
if not property_value['name'].lower() != donate_name: if not name_value.lower() != donate_name:
continue continue
property_found = property_value property_found = property_value
break break
@ -111,15 +133,24 @@ def set_donation_url(actor_json: {}, donate_url: str) -> None:
donate_url + '</a>' donate_url + '</a>'
for property_value in actor_json['attachment']: 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 continue
if not property_value.get('type'): if not property_value.get('type'):
continue continue
if property_value['name'].lower() != donate_name: if name_value.lower() != donate_name:
continue continue
if property_value['type'] != 'PropertyValue': if not property_value['type'].endswith('PropertyValue'):
continue 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 return
new_donate = { new_donate = {

View File

@ -8,23 +8,33 @@ __status__ = "Production"
__module_group__ = "Profile Metadata" __module_group__ = "Profile Metadata"
from utils import get_attachment_property_value
def get_enigma_pub_key(actor_json: {}) -> str: def get_enigma_pub_key(actor_json: {}) -> str:
"""Returns Enigma public key for the given actor """Returns Enigma public key for the given actor
""" """
if not actor_json.get('attachment'): if not actor_json.get('attachment'):
return '' return ''
for property_value in actor_json['attachment']: 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 continue
if not property_value['name'].lower().startswith('enigma'): if not name_value.lower().startswith('enigma'):
continue continue
if not property_value.get('type'): if not property_value.get('type'):
continue continue
if not property_value.get('value'): prop_value_name, _ = \
get_attachment_property_value(property_value)
if not prop_value_name:
continue continue
if property_value['type'] != 'PropertyValue': if not property_value['type'].endswith('PropertyValue'):
continue continue
return property_value['value'] return property_value[prop_value_name]
return '' return ''
@ -41,11 +51,16 @@ def set_enigma_pub_key(actor_json: {}, enigma_pub_key: str) -> None:
# remove any existing value # remove any existing value
property_found = None property_found = None
for property_value in actor_json['attachment']: 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 continue
if not property_value.get('type'): if not property_value.get('type'):
continue continue
if not property_value['name'].lower().startswith('enigma'): if not name_value.lower().startswith('enigma'):
continue continue
property_found = property_value property_found = property_value
break break
@ -55,15 +70,24 @@ def set_enigma_pub_key(actor_json: {}, enigma_pub_key: str) -> None:
return return
for property_value in actor_json['attachment']: 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 continue
if not property_value.get('type'): if not property_value.get('type'):
continue continue
if not property_value['name'].lower().startswith('enigma'): if not name_value.lower().startswith('enigma'):
continue continue
if property_value['type'] != 'PropertyValue': if not property_value['type'].endswith('PropertyValue'):
continue 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 return
new_enigma_pub_key = { new_enigma_pub_key = {

View File

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

View File

@ -8,31 +8,41 @@ __status__ = "Production"
__module_group__ = "Profile Metadata" __module_group__ = "Profile Metadata"
from utils import get_attachment_property_value
def get_matrix_address(actor_json: {}) -> str: def get_matrix_address(actor_json: {}) -> str:
"""Returns matrix address for the given actor """Returns matrix address for the given actor
""" """
if not actor_json.get('attachment'): if not actor_json.get('attachment'):
return '' return ''
for property_value in actor_json['attachment']: 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 continue
if not property_value['name'].lower().startswith('matrix'): if not name_value.lower().startswith('matrix'):
continue continue
if not property_value.get('type'): if not property_value.get('type'):
continue continue
if not property_value.get('value'): prop_value_name, _ = \
get_attachment_property_value(property_value)
if not prop_value_name:
continue continue
if property_value['type'] != 'PropertyValue': if not property_value['type'].endswith('PropertyValue'):
continue continue
if '@' not in property_value['value']: if '@' not in property_value[prop_value_name]:
continue continue
if not property_value['value'].startswith('@'): if not property_value[prop_value_name].startswith('@'):
continue continue
if ':' not in property_value['value']: if ':' not in property_value[prop_value_name]:
continue continue
if '"' in property_value['value']: if '"' in property_value[prop_value_name]:
continue continue
return property_value['value'] return property_value[prop_value_name]
return '' return ''
@ -45,11 +55,16 @@ def set_matrix_address(actor_json: {}, matrix_address: str) -> None:
# remove any existing value # remove any existing value
property_found = None property_found = None
for property_value in actor_json['attachment']: 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 continue
if not property_value.get('type'): if not property_value.get('type'):
continue continue
if not property_value['name'].lower().startswith('matrix'): if not name_value.lower().startswith('matrix'):
continue continue
property_found = property_value property_found = property_value
break break
@ -70,15 +85,24 @@ def set_matrix_address(actor_json: {}, matrix_address: str) -> None:
return return
for property_value in actor_json['attachment']: 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 continue
if not property_value.get('type'): if not property_value.get('type'):
continue continue
if not property_value['name'].lower().startswith('matrix'): if not name_value.lower().startswith('matrix'):
continue continue
if property_value['type'] != 'PropertyValue': if not property_value['type'].endswith('PropertyValue'):
continue 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 return
new_matrix_address = { new_matrix_address = {

View File

@ -15,6 +15,7 @@ from posts import outbox_message_create_wrap
from posts import save_post_to_box from posts import save_post_to_box
from posts import send_to_followers_thread from posts import send_to_followers_thread
from posts import send_to_named_addresses_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 get_account_timezone
from utils import has_object_string_type from utils import has_object_string_type
from utils import get_base_content_from_post from utils import get_base_content_from_post
@ -130,38 +131,51 @@ def _person_receive_update_outbox(recent_posts_cache: {},
# update fields within actor # update fields within actor
if 'attachment' in updated_actor_json: if 'attachment' in updated_actor_json:
for new_property_value in updated_actor_json['attachment']: 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 continue
if new_property_value['name'] not in updatable_attachments: if name_value not in updatable_attachments:
continue continue
if not new_property_value.get('type'): if not new_property_value.get('type'):
continue continue
if not new_property_value.get('value'): prop_value_name, _ = \
get_attachment_property_value(new_property_value)
if not prop_value_name:
continue continue
if new_property_value['type'] != 'PropertyValue': if not new_property_value['type'].endswith('PropertyValue'):
continue continue
if 'attachment' not in actor_json: if 'attachment' not in actor_json:
continue continue
found = False found = False
for attach_idx, _ in enumerate(actor_json['attachment']): for attach_idx, _ in enumerate(actor_json['attachment']):
if actor_json['attachment'][attach_idx]['type'] != \ attach_type = actor_json['attachment'][attach_idx]['type']
'PropertyValue': if not attach_type.endswith('PropertyValue'):
continue continue
if actor_json['attachment'][attach_idx]['name'] != \ attach_name = ''
new_property_value['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 continue
if actor_json['attachment'][attach_idx]['value'] != \ if actor_json['attachment'][attach_idx][prop_value_name] != \
new_property_value['value']: new_property_value[prop_value_name]:
actor_json['attachment'][attach_idx]['value'] = \ actor_json['attachment'][attach_idx][prop_value_name] = \
new_property_value['value'] new_property_value[prop_value_name]
actor_changed = True actor_changed = True
found = True found = True
break break
if not found: if not found:
actor_json['attachment'].append({ actor_json['attachment'].append({
"name": new_property_value['name'], "name": name_value,
"type": "PropertyValue", "type": "PropertyValue",
"value": new_property_value['value'] "value": new_property_value[prop_value_name]
}) })
actor_changed = True actor_changed = True
# save actor to file # save actor to file

View File

@ -38,6 +38,7 @@ from roles import set_role
from roles import set_rolesFromList from roles import set_rolesFromList
from roles import get_actor_roles_list from roles import get_actor_roles_list
from media import process_meta_data from media import process_meta_data
from utils import get_attachment_property_value
from utils import get_nickname_from_actor from utils import get_nickname_from_actor
from utils import remove_html from utils import remove_html
from utils import contains_invalid_chars from utils import contains_invalid_chars
@ -232,7 +233,7 @@ def get_actor_update_json(actor_json: {}) -> {}:
"@id": "as:movedTo", "@id": "as:movedTo",
"@type": "@id" "@type": "@id"
}, },
"schema": "http://schema.org#", "schema": "http://schema.org/",
"PropertyValue": "schema:PropertyValue", "PropertyValue": "schema:PropertyValue",
"value": "schema:value", "value": "schema:value",
"IdentityProof": "toot:IdentityProof", "IdentityProof": "toot:IdentityProof",
@ -338,7 +339,7 @@ def get_default_person_context() -> str:
'messageType': 'toot:messageType', 'messageType': 'toot:messageType',
'movedTo': {'@id': 'as:movedTo', '@type': '@id'}, 'movedTo': {'@id': 'as:movedTo', '@type': '@id'},
'publicKeyBase64': 'toot:publicKeyBase64', 'publicKeyBase64': 'toot:publicKeyBase64',
'schema': 'http://schema.org#', 'schema': 'http://schema.org/',
'suspended': 'toot:suspended', 'suspended': 'toot:suspended',
'toot': 'http://joinmastodon.org/ns#', 'toot': 'http://joinmastodon.org/ns#',
'value': 'schema:value', 'value': 'schema:value',
@ -1789,10 +1790,14 @@ def valid_sending_actor(session, base_dir: str,
continue continue
if isinstance(tag['name'], str): if isinstance(tag['name'], str):
bio_str += ' ' + tag['name'] bio_str += ' ' + tag['name']
if tag.get('value'): prop_value_name, _ = \
get_attachment_property_value(tag)
if not prop_value_name:
continue continue
if isinstance(tag['value'], str): if tag.get(prop_value_name):
bio_str += ' ' + tag['value'] continue
if isinstance(tag[prop_value_name], str):
bio_str += ' ' + tag[prop_value_name]
if actor_json.get('name'): if actor_json.get('name'):
bio_str += ' ' + remove_html(actor_json['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']: for tag in actor_json['attachment']:
if not isinstance(tag, dict): if not isinstance(tag, dict):
continue continue
if not tag.get('name'): if not tag.get('name') and not tag.get('schema:name'):
continue continue
no_of_tags += 1 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 tags_without_value += 1
continue continue
if not isinstance(tag['value'], str): if not isinstance(tag[prop_value_name], str):
tags_without_value += 1 tags_without_value += 1
continue continue
if not tag['value'].strip(): if not tag[prop_value_name].strip():
tags_without_value += 1 tags_without_value += 1
continue continue
if len(tag['value']) < 2: if len(tag[prop_value_name]) < 2:
tags_without_value += 1 tags_without_value += 1
continue continue
if no_of_tags > 0: if no_of_tags > 0:

149
pgp.py
View File

@ -30,27 +30,37 @@ from cwtch import get_cwtch_address
from blog import get_blog_address from blog import get_blog_address
from utils import get_attachment_property_value
def get_email_address(actor_json: {}) -> str: def get_email_address(actor_json: {}) -> str:
"""Returns the email address for the given actor """Returns the email address for the given actor
""" """
if not actor_json.get('attachment'): if not actor_json.get('attachment'):
return '' return ''
for property_value in actor_json['attachment']: 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 continue
if not property_value['name'].lower().startswith('email'): if not name_value.lower().startswith('email'):
continue continue
if not property_value.get('type'): if not property_value.get('type'):
continue continue
if not property_value.get('value'): prop_value_name, _ = \
get_attachment_property_value(property_value)
if not prop_value_name:
continue continue
if property_value['type'] != 'PropertyValue': if not property_value['type'].endswith('PropertyValue'):
continue continue
if '@' not in property_value['value']: if '@' not in property_value[prop_value_name]:
continue continue
if '.' not in property_value['value']: if '.' not in property_value[prop_value_name]:
continue continue
return property_value['value'] return property_value[prop_value_name]
return '' return ''
@ -60,19 +70,26 @@ def get_pgp_pub_key(actor_json: {}) -> str:
if not actor_json.get('attachment'): if not actor_json.get('attachment'):
return '' return ''
for property_value in actor_json['attachment']: 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 continue
if not property_value['name'].lower().startswith('pgp'): if not name_value.lower().startswith('pgp'):
continue continue
if not property_value.get('type'): if not property_value.get('type'):
continue continue
if not property_value.get('value'): prop_value_name, _ = \
get_attachment_property_value(property_value)
if not prop_value_name:
continue continue
if property_value['type'] != 'PropertyValue': if not property_value['type'].endswith('PropertyValue'):
continue continue
if not contains_pgp_public_key(property_value['value']): if not contains_pgp_public_key(property_value[prop_value_name]):
continue continue
return property_value['value'] return property_value[prop_value_name]
return '' return ''
@ -82,19 +99,26 @@ def get_pgp_fingerprint(actor_json: {}) -> str:
if not actor_json.get('attachment'): if not actor_json.get('attachment'):
return '' return ''
for property_value in actor_json['attachment']: 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 continue
if not property_value['name'].lower().startswith('openpgp'): if not name_value.lower().startswith('openpgp'):
continue continue
if not property_value.get('type'): if not property_value.get('type'):
continue continue
if not property_value.get('value'): prop_value_name, _ = \
get_attachment_property_value(property_value)
if not prop_value_name:
continue continue
if property_value['type'] != 'PropertyValue': if not property_value['type'].endswith('PropertyValue'):
continue continue
if len(property_value['value']) < 10: if len(property_value[prop_value_name]) < 10:
continue continue
return property_value['value'] return property_value[prop_value_name]
return '' return ''
@ -117,11 +141,16 @@ def set_email_address(actor_json: {}, email_address: str) -> None:
# remove any existing value # remove any existing value
property_found = None property_found = None
for property_value in actor_json['attachment']: 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 continue
if not property_value.get('type'): if not property_value.get('type'):
continue continue
if not property_value['name'].lower().startswith('email'): if not name_value.lower().startswith('email'):
continue continue
property_found = property_value property_found = property_value
break break
@ -131,15 +160,24 @@ def set_email_address(actor_json: {}, email_address: str) -> None:
return return
for property_value in actor_json['attachment']: 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 continue
if not property_value.get('type'): if not property_value.get('type'):
continue continue
if not property_value['name'].lower().startswith('email'): if not name_value.lower().startswith('email'):
continue continue
if property_value['type'] != 'PropertyValue': if not property_value['type'].endswith('PropertyValue'):
continue 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 return
new_email_address = { new_email_address = {
@ -168,11 +206,16 @@ def set_pgp_pub_key(actor_json: {}, pgp_pub_key: str) -> None:
# remove any existing value # remove any existing value
property_found = None property_found = None
for property_value in actor_json['attachment']: 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 continue
if not property_value.get('type'): if not property_value.get('type'):
continue continue
if not property_value['name'].lower().startswith('pgp'): if not name_value.lower().startswith('pgp'):
continue continue
property_found = property_value property_found = property_value
break break
@ -182,15 +225,24 @@ def set_pgp_pub_key(actor_json: {}, pgp_pub_key: str) -> None:
return return
for property_value in actor_json['attachment']: 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 continue
if not property_value.get('type'): if not property_value.get('type'):
continue continue
if not property_value['name'].lower().startswith('pgp'): if not name_value.lower().startswith('pgp'):
continue continue
if property_value['type'] != 'PropertyValue': if not property_value['type'].endswith('PropertyValue'):
continue 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 return
newpgp_pub_key = { newpgp_pub_key = {
@ -217,11 +269,16 @@ def set_pgp_fingerprint(actor_json: {}, fingerprint: str) -> None:
# remove any existing value # remove any existing value
property_found = None property_found = None
for property_value in actor_json['attachment']: 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 continue
if not property_value.get('type'): if not property_value.get('type'):
continue continue
if not property_value['name'].lower().startswith('openpgp'): if not name_value.lower().startswith('openpgp'):
continue continue
property_found = property_value property_found = property_value
break break
@ -231,15 +288,24 @@ def set_pgp_fingerprint(actor_json: {}, fingerprint: str) -> None:
return return
for property_value in actor_json['attachment']: 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 continue
if not property_value.get('type'): if not property_value.get('type'):
continue continue
if not property_value['name'].lower().startswith('openpgp'): if not name_value.lower().startswith('openpgp'):
continue continue
if property_value['type'] != 'PropertyValue': if not property_value['type'].endswith('PropertyValue'):
continue 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 return
newpgp_fingerprint = { newpgp_fingerprint = {
@ -451,12 +517,13 @@ def _get_pgp_public_key_from_actor(signing_priv_key_pem: str,
for tag in actor_json['attachment']: for tag in actor_json['attachment']:
if not isinstance(tag, dict): if not isinstance(tag, dict):
continue continue
if not tag.get('value'): prop_value_name, _ = get_attachment_property_value(tag)
if not prop_value_name:
continue continue
if not isinstance(tag['value'], str): if not isinstance(tag[prop_value_name], str):
continue continue
if contains_pgp_public_key(tag['value']): if contains_pgp_public_key(tag[prop_value_name]):
return tag['value'] return tag[prop_value_name]
return None return None

59
ssb.py
View File

@ -8,34 +8,45 @@ __status__ = "Production"
__module_group__ = "Profile Metadata" __module_group__ = "Profile Metadata"
from utils import get_attachment_property_value
def get_ssb_address(actor_json: {}) -> str: def get_ssb_address(actor_json: {}) -> str:
"""Returns ssb address for the given actor """Returns ssb address for the given actor
""" """
if not actor_json.get('attachment'): if not actor_json.get('attachment'):
return '' return ''
for property_value in actor_json['attachment']: 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 continue
if not property_value['name'].lower().startswith('ssb'): if not name_value.lower().startswith('ssb'):
continue continue
if not property_value.get('type'): if not property_value.get('type'):
continue continue
if not property_value.get('value'): prop_value_name, _ = \
get_attachment_property_value(property_value)
if not prop_value_name:
continue continue
if property_value['type'] != 'PropertyValue': if not property_value['type'].endswith('PropertyValue'):
continue continue
property_value['value'] = property_value['value'].strip() property_value[prop_value_name] = \
if not property_value['value'].startswith('@'): property_value[prop_value_name].strip()
if not property_value[prop_value_name].startswith('@'):
continue continue
if '=.' not in property_value['value']: if '=.' not in property_value[prop_value_name]:
continue continue
if '"' in property_value['value']: if '"' in property_value[prop_value_name]:
continue continue
if ' ' in property_value['value']: if ' ' in property_value[prop_value_name]:
continue continue
if ',' in property_value['value']: if ',' in property_value[prop_value_name]:
continue continue
return property_value['value'] return property_value[prop_value_name]
return '' return ''
@ -62,11 +73,16 @@ def set_ssb_address(actor_json: {}, ssb_address: str) -> None:
# remove any existing value # remove any existing value
property_found = None property_found = None
for property_value in actor_json['attachment']: 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 continue
if not property_value.get('type'): if not property_value.get('type'):
continue continue
if not property_value['name'].lower().startswith('ssb'): if not name_value.lower().startswith('ssb'):
continue continue
property_found = property_value property_found = property_value
break break
@ -76,15 +92,24 @@ def set_ssb_address(actor_json: {}, ssb_address: str) -> None:
return return
for property_value in actor_json['attachment']: 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 continue
if not property_value.get('type'): if not property_value.get('type'):
continue continue
if not property_value['name'].lower().startswith('ssb'): if not name_value.lower().startswith('ssb'):
continue continue
if property_value['type'] != 'PropertyValue': if not property_value['type'].endswith('PropertyValue'):
continue 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 return
new_ssb_address = { new_ssb_address = {

62
tox.py
View File

@ -8,36 +8,48 @@ __status__ = "Production"
__module_group__ = "Profile Metadata" __module_group__ = "Profile Metadata"
from utils import get_attachment_property_value
def get_tox_address(actor_json: {}) -> str: def get_tox_address(actor_json: {}) -> str:
"""Returns tox address for the given actor """Returns tox address for the given actor
""" """
if not actor_json.get('attachment'): if not actor_json.get('attachment'):
return '' return ''
for property_value in actor_json['attachment']: 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 continue
if not property_value['name'].lower().startswith('tox'): if not name_value.lower().startswith('tox'):
continue continue
if not property_value.get('type'): if not property_value.get('type'):
continue continue
if not property_value.get('value'): prop_value_name, _ = \
get_attachment_property_value(property_value)
if not prop_value_name:
continue continue
if property_value['type'] != 'PropertyValue': if not property_value['type'].endswith('PropertyValue'):
continue continue
property_value['value'] = property_value['value'].strip() property_value[prop_value_name] = \
if len(property_value['value']) != 76: property_value[prop_value_name].strip()
if len(property_value[prop_value_name]) != 76:
continue continue
if property_value['value'].upper() != property_value['value']: if property_value[prop_value_name].upper() != \
property_value[prop_value_name]:
continue continue
if '"' in property_value['value']: if '"' in property_value[prop_value_name]:
continue continue
if ' ' in property_value['value']: if ' ' in property_value[prop_value_name]:
continue continue
if ',' in property_value['value']: if ',' in property_value[prop_value_name]:
continue continue
if '.' in property_value['value']: if '.' in property_value[prop_value_name]:
continue continue
return property_value['value'] return property_value[prop_value_name]
return '' return ''
@ -67,11 +79,16 @@ def set_tox_address(actor_json: {}, tox_address: str) -> None:
# remove any existing value # remove any existing value
property_found = None property_found = None
for property_value in actor_json['attachment']: 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 continue
if not property_value.get('type'): if not property_value.get('type'):
continue continue
if not property_value['name'].lower().startswith('tox'): if not name_value.lower().startswith('tox'):
continue continue
property_found = property_value property_found = property_value
break break
@ -81,15 +98,24 @@ def set_tox_address(actor_json: {}, tox_address: str) -> None:
return return
for property_value in actor_json['attachment']: 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 continue
if not property_value.get('type'): if not property_value.get('type'):
continue continue
if not property_value['name'].lower().startswith('tox'): if not name_value.lower().startswith('tox'):
continue continue
if property_value['type'] != 'PropertyValue': if not property_value['type'].endswith('PropertyValue'):
continue 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 return
new_tox_address = { new_tox_address = {

View File

@ -52,22 +52,29 @@ def get_actor_languages_list(actor_json: {}) -> []:
if not actor_json.get('attachment'): if not actor_json.get('attachment'):
return [] return []
for property_value in actor_json['attachment']: 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 continue
if not property_value['name'].lower().startswith('languages'): if not name_value.lower().startswith('languages'):
continue continue
if not property_value.get('type'): if not property_value.get('type'):
continue continue
if not property_value.get('value'): prop_value_name, _ = \
get_attachment_property_value(property_value)
if not prop_value_name:
continue continue
if property_value['type'] != 'PropertyValue': if not property_value['type'].endswith('PropertyValue'):
continue continue
if isinstance(property_value['value'], list): if isinstance(property_value[prop_value_name], list):
lang_list = property_value['value'] lang_list = property_value[prop_value_name]
lang_list.sort() lang_list.sort()
return lang_list return lang_list
if isinstance(property_value['value'], str): if isinstance(property_value[prop_value_name], str):
lang_str = property_value['value'] lang_str = property_value[prop_value_name]
lang_list_temp = [] lang_list_temp = []
if ',' in lang_str: if ',' in lang_str:
lang_list_temp = lang_str.split(',') lang_list_temp = lang_str.split(',')
@ -1099,14 +1106,22 @@ def get_gender_from_bio(base_dir: str, actor: str, person_cache: {},
for tag in tags_list: for tag in tags_list:
if not isinstance(tag, dict): if not isinstance(tag, dict):
continue 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 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(): translate['gender'].lower():
bio_found = tag['value'] bio_found = tag[prop_value_name]
break break
if tag['name'].lower().startswith(pronoun_str): if name_value.lower().startswith(pronoun_str):
bio_found = tag['value'] bio_found = tag[prop_value_name]
break break
# the field name could be anything, # the field name could be anything,
# just look at the value # just look at the value
@ -1114,9 +1129,13 @@ def get_gender_from_bio(base_dir: str, actor: str, person_cache: {},
for tag in tags_list: for tag in tags_list:
if not isinstance(tag, dict): if not isinstance(tag, dict):
continue continue
if not tag.get('name') or not tag.get('value'): if not tag.get('name') and not tag.get('schema:name'):
continue 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: if gender:
return gender return gender
# if not then use the bio # if not then use the bio
@ -3113,32 +3132,39 @@ def get_actor_property_url(actor_json: {}, property_name: str) -> str:
return '' return ''
property_name = property_name.lower() property_name = property_name.lower()
for property_value in actor_json['attachment']: 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 continue
if not property_value['name'].lower().startswith(property_name): if not name_value.lower().startswith(property_name):
continue continue
if not property_value.get('type'): if not property_value.get('type'):
continue continue
if not property_value.get('value'): prop_value_name, _ = \
get_attachment_property_value(property_value)
if not prop_value_name:
continue continue
if property_value['type'] != 'PropertyValue': if not property_value['type'].endswith('PropertyValue'):
continue continue
property_value['value'] = property_value['value'].strip() property_value['value'] = property_value[prop_value_name].strip()
prefixes = get_protocol_prefixes() prefixes = get_protocol_prefixes()
prefix_found = False prefix_found = False
for prefix in prefixes: for prefix in prefixes:
if property_value['value'].startswith(prefix): if property_value[prop_value_name].startswith(prefix):
prefix_found = True prefix_found = True
break break
if not prefix_found: if not prefix_found:
continue continue
if '.' not in property_value['value']: if '.' not in property_value[prop_value_name]:
continue continue
if ' ' in property_value['value']: if ' ' in property_value[prop_value_name]:
continue continue
if ',' in property_value['value']: if ',' in property_value[prop_value_name]:
continue continue
return property_value['value'] return property_value[prop_value_name]
return '' return ''
@ -3652,3 +3678,20 @@ def disallow_reply(content: str) -> bool:
if diss in content: if diss in content:
return True return True
return False 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_name = 'http://schema.org#value'
prop_value = property_value[prop_value_name]
elif property_value.get('https://schema.org#value'):
prop_value_name = 'https://schema.org#value'
prop_value = property_value[prop_value_name]
return prop_value_name, prop_value

View File

@ -11,6 +11,7 @@ import os
from shutil import copyfile from shutil import copyfile
from collections import OrderedDict from collections import OrderedDict
from session import get_json from session import get_json
from utils import get_attachment_property_value
from utils import is_account_dir from utils import is_account_dir
from utils import remove_html from utils import remove_html
from utils import get_protocol_prefixes from utils import get_protocol_prefixes
@ -183,11 +184,16 @@ def _set_actor_property_url(actor_json: {},
# remove any existing value # remove any existing value
property_found = None property_found = None
for property_value in actor_json['attachment']: 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 continue
if not property_value.get('type'): if not property_value.get('type'):
continue continue
if not property_value['name'].lower().startswith(property_name_lower): if not name_value.lower().startswith(property_name_lower):
continue continue
property_found = property_value property_found = property_value
break break
@ -210,15 +216,24 @@ def _set_actor_property_url(actor_json: {},
return return
for property_value in actor_json['attachment']: 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 continue
if not property_value.get('type'): if not property_value.get('type'):
continue continue
if not property_value['name'].lower().startswith(property_name_lower): if not name_value.lower().startswith(property_name_lower):
continue continue
if property_value['type'] != 'PropertyValue': if not property_value['type'].endswith('PropertyValue'):
continue 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 return
new_address = { new_address = {
@ -787,11 +802,16 @@ def html_header_with_person_markup(css_filename: str, instance_title: str,
) )
for attach_json in actor_json['attachment']: for attach_json in actor_json['attachment']:
if not attach_json.get('name'): 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 continue
if not attach_json.get('value'): if attach_json.get('name'):
continue name = attach_json['name'].lower()
name = attach_json['name'].lower() else:
value = attach_json['value'] name = attach_json['schema:name'].lower()
value = attach_json[prop_value_name]
for og_tag in og_tags: for og_tag in og_tags:
if name != og_tag: if name != og_tag:
continue continue

View File

@ -12,6 +12,7 @@ import urllib.parse
from session import get_json from session import get_json
from cache import store_webfinger_in_cache from cache import store_webfinger_in_cache
from cache import get_webfinger_from_cache from cache import get_webfinger_from_cache
from utils import get_attachment_property_value
from utils import get_full_domain from utils import get_full_domain
from utils import load_json from utils import load_json
from utils import load_json_onionify from utils import load_json_onionify
@ -414,9 +415,14 @@ def _webfinger_updateFromProfile(wf_json: {}, actor_json: {}) -> bool:
aliases_not_found.append(alias) aliases_not_found.append(alias)
for property_value in actor_json['attachment']: 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 continue
property_name = property_value['name'].lower() property_name = name_value.lower()
found = False found = False
for name, alias in webfinger_property_name.items(): for name, alias in webfinger_property_name.items():
if name == property_name: if name == property_name:
@ -428,12 +434,14 @@ def _webfinger_updateFromProfile(wf_json: {}, actor_json: {}) -> bool:
continue continue
if not property_value.get('type'): if not property_value.get('type'):
continue continue
if not property_value.get('value'): prop_value_name, _ = \
get_attachment_property_value(property_value)
if not prop_value_name:
continue continue
if property_value['type'] != 'PropertyValue': if not property_value['type'].endswith('PropertyValue'):
continue continue
new_value = property_value['value'].strip() new_value = property_value[prop_value_name].strip()
if '://' in new_value: if '://' in new_value:
new_value = new_value.split('://')[1] new_value = new_value.split('://')[1]

59
xmpp.py
View File

@ -8,29 +8,38 @@ __status__ = "Production"
__module_group__ = "Profile Metadata" __module_group__ = "Profile Metadata"
from utils import get_attachment_property_value
def get_xmpp_address(actor_json: {}) -> str: def get_xmpp_address(actor_json: {}) -> str:
"""Returns xmpp address for the given actor """Returns xmpp address for the given actor
""" """
if not actor_json.get('attachment'): if not actor_json.get('attachment'):
return '' return ''
for property_value in actor_json['attachment']: 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 continue
name_lower = property_value['name'].lower() if not (name_value.startswith('xmpp') or
if not (name_lower.startswith('xmpp') or name_value.startswith('jabber')):
name_lower.startswith('jabber')):
continue continue
if not property_value.get('type'): if not property_value.get('type'):
continue continue
if not property_value.get('value'): prop_value_name, _ = \
get_attachment_property_value(property_value)
if not prop_value_name:
continue continue
if property_value['type'] != 'PropertyValue': if not property_value['type'].endswith('PropertyValue'):
continue continue
if '@' not in property_value['value']: if '@' not in property_value[prop_value_name]:
continue continue
if '"' in property_value['value']: if '"' in property_value[prop_value_name]:
continue continue
return property_value['value'] return property_value[prop_value_name]
return '' return ''
@ -53,12 +62,17 @@ def set_xmpp_address(actor_json: {}, xmpp_address: str) -> None:
# remove any existing value # remove any existing value
property_found = None property_found = None
for property_value in actor_json['attachment']: 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 continue
if not property_value.get('type'): if not property_value.get('type'):
continue continue
if not (property_value['name'].lower().startswith('xmpp') or if not (name_value.lower().startswith('xmpp') or
property_value['name'].lower().startswith('jabber')): name_value.lower().startswith('jabber')):
continue continue
property_found = property_value property_found = property_value
break break
@ -68,17 +82,26 @@ def set_xmpp_address(actor_json: {}, xmpp_address: str) -> None:
return return
for property_value in actor_json['attachment']: 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 continue
if not property_value.get('type'): if not property_value.get('type'):
continue continue
name_lower = property_value['name'].lower() name_value = name_value.lower()
if not (name_lower.startswith('xmpp') or if not (name_value.startswith('xmpp') or
name_lower.startswith('jabber')): name_value.startswith('jabber')):
continue continue
if property_value['type'] != 'PropertyValue': if not property_value['type'].endswith('PropertyValue'):
continue 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 return
new_xmpp_address = { new_xmpp_address = {