CSS : Modifications consequent to XHTML modifications;

Python : Modifications consequent to XHTML modifications;
TOML   : Various of modifications;
XHTML  : Uniform templates.
This commit is contained in:
Schimon Jehudah, Adv. 2024-11-05 10:51:28 +02:00
parent 82fb55ca1c
commit cbcf3b58d0
8 changed files with 512 additions and 289 deletions

89
fasi.py
View file

@ -109,7 +109,6 @@ class HttpInstance:
exception = jid_vcard = messages_10 = note = node_title = \
node_note = number_of_pages = page_number = previous = \
selection = services_sorted = subject = None
node_name = 'urn:xmpp:microblog:0'
link_href = 'xmpp:{}?join'.format(jid_bare)
link_text = 'Join'
xmpp_uri = '{}'.format(jid_bare)
@ -119,7 +118,7 @@ class HttpInstance:
jid_details = Data.open_file_toml(filename)
else:
jid_details = await FileUtilities.cache_jid_data(
jabber_id, password, jid_bare, node_name, alias=alias)
jabber_id, password, jid_bare, alias=alias)
count = jid_details['count']
items = jid_details['items']
@ -157,7 +156,7 @@ class HttpInstance:
if jid_kind:
# Action and instance type
action, instance = XmppUtilities.set_action_instance_type(jid_kind, node_name)
action, instance = XmppUtilities.set_action_instance_type(jid_kind)
else: # jid_info['error']
action = 'Contact'
instance = view_href = ''
@ -166,10 +165,10 @@ class HttpInstance:
# Query URI links
print('Query URI links')
links = XmppUtilities.get_query_uri_links(jid_bare, jid_kind, node_name)
link_href = XmppUtilities.get_link_href(jid_bare, jid_kind, node_name)
view_href = XmppUtilities.get_view_href(jid_bare, jid_kind, node_name)
xmpp_uri = XmppUtilities.get_xmpp_uri(jid_bare, jid_kind, node_name)
links = XmppUtilities.get_query_uri_links(jid_bare, jid_kind)
link_href = XmppUtilities.get_link_href(jid_bare, jid_kind)
view_href = XmppUtilities.get_view_href(jid_bare, jid_kind)
xmpp_uri = XmppUtilities.get_xmpp_uri(jid_bare, jid_kind)
# Graphic files
filename, filepath, filetype, selection = FileUtilities.handle_photo(jid_bare, jid_vcard, link_href)
@ -202,7 +201,6 @@ class HttpInstance:
'messages' : messages_10,
'node_title' : node_title,
'node_note' : node_note,
'node_name' : node_name,
'number_of_pages' : number_of_pages,
'page_number' : page_number,
'previous' : previous,
@ -241,7 +239,7 @@ class HttpInstance:
directory = 'xep_0060/{}/{}/'.format(jid_bare, node_name_vcard4)
filename = directory + item_id_vcard4 + '.xml'
if os.path.exists(filename) and os.path.getsize(filename) > 0:
jid_details = Data.open_file_xml(filename)
xml_data = Data.open_file_xml(filename)
else:
await FileUtilities.cache_vcard_data(
jabber_id, password, jid_bare, node_name_vcard4, item_id_vcard4)
@ -255,13 +253,30 @@ class HttpInstance:
# Action and instance type
action = 'Profile'
filename = 'details/{}.toml'.format(jid_bare)
if os.path.exists(filename) and os.path.getsize(filename) > 0:
jid_details = Data.open_file_toml(filename)
else:
jid_details = await FileUtilities.cache_jid_data(
jabber_id, password, jid_bare, alias=alias)
# Set node name to 'urn:xmpp:microblog:0'
jid_kind = jid_details['kind']
nodes = jid_details['nodes']
if (jid_kind not in ('conference', 'mix', 'muc') and
'@' in jid_bare and
'urn:xmpp:microblog:0' in nodes):
node_name = 'urn:xmpp:microblog:0'
# Query URI links
print('Query URI links')
jid_kind = 'account'
link_href = XmppUtilities.get_link_href(jid_bare, jid_kind)
xmpp_uri = XmppUtilities.get_xmpp_uri(jid_bare, jid_kind, node_name_vcard4)
links = XmppUtilities.get_query_uri_links(jid_bare, jid_kind, node_name)
# Graphic files
#filename, filepath, filetype, selection = FileUtilities.handle_photo(jid_bare, jid_vcard, link_href)
filename, filepath, filetype, selection = FileUtilities.handle_photo(jid_bare, jid_vcard, link_href)
#except Exception as e:
else:
@ -297,11 +312,12 @@ class HttpInstance:
'chat_client' : chat_client,
'entries' : entries,
'exception' : exception,
#'filename' : filename,
'filename' : filename,
'jid_bare' : jid,
'jid_note' : note,
#'jid_title' : title,
#'node_title' : node_title,
'links' : links,
'node_name' : node_name_vcard4,
'number_of_pages' : number_of_pages,
'page_number' : page_number,
@ -658,7 +674,7 @@ class HttpInstance:
'type' : jid_details['image_type']}
messages = jid_details['messages']
#note = nodes[node_name]['title'] if node_name in nodes else jid_details['note']
note = jid_details['note']
#note = jid_details['note']
# vCard4
node_name_vcard4 = 'urn:xmpp:vcard4'
@ -673,7 +689,7 @@ class HttpInstance:
vcard_info = Syndication.extract_vcard4_items(child_element)
title = vcard_info['fn']
alias = vcard_info['alias']
note = vcard_info['note']
#note = vcard_info['note']
else:
await FileUtilities.cache_vcard_data(
jabber_id, password, jid_bare, node_name_vcard4, item_id_vcard4)
@ -690,12 +706,14 @@ class HttpInstance:
await FileUtilities.cache_node_data(
jabber_id, password, jid_bare, node_name)
# Node items
entries = []
node_items = os.listdir(directory)
if 'urn:xmpp:avatar:metadata.xml' in node_items:
node_items.remove('urn:xmpp:avatar:metadata.xml')
count_item = len(node_items)
# JID or node items
if jid_kind in ('mix', 'muc', 'conference', 'server'):
count_item = jid_details['count']
elif jid_kind in ('account', 'pubsub'):
node_items = os.listdir(directory)
if 'urn:xmpp:avatar:metadata.xml' in node_items:
node_items.remove('urn:xmpp:avatar:metadata.xml')
count_item = len(node_items)
# if ('@' in jid_bare and
# 'urn:xmpp:microblog:0' not in nodes and
@ -747,8 +765,8 @@ class HttpInstance:
jid_vcard = jid_kind = links = message = selection = url = \
vcard4 = None
note_500 = note[:500]
note = note_500 + '' if note_500 < note else note_500
#note_500 = note[:500]
#note = note_500 + ' …' if note_500 < note else note_500
# NOTE Handling of variables "title" and "note" in case of '/j/{jid}/{node_name}' is confusing.
# TODO Add new keys that are of 'node' and be utilized for nodes, instead of reusing a variable for several roles.
@ -1555,24 +1573,17 @@ class Syndication:
else:
url = ''
extra_resources = {
'code' : [],
'gallery' : [],
'journal' : [],
'movim' : [],
'peertube' : [],
}
for res in extra_resources:
#for element in xml_data.findall(namespace + 'group[contains(@name, "{}")]'.format(res)):
#for element in xml_data.findall(namespace + 'group[strats-with(@name, "{}")]'.format(res)):
matching_elements = [group for group in xml_data.findall(namespace + "group") if res in group.get('name', '')]
for element in matching_elements:
for i in element.find(namespace + 'x-ablabel'):
txt = i.text
for i in element.find(namespace + 'url'):
uri = i.text
extra_resources[res].append({'label' : txt, 'uri' : uri})
vcard[res] = extra_resources[res]
vcard['extras'] = {}
for element in xml_data.findall(namespace + "group"):
category = '?'
for i in element.find(namespace + 'x-ablabel'):
txt = i.text
for i in element.find(namespace + 'url'):
uri = i.text
for i in element.find(namespace + 'url/' + namespace + 'parameters/' + namespace + 'type'):
category = i.text
if not category in vcard['extras']: vcard['extras'][category] = []
vcard['extras'][category].append({'label' : txt, 'uri' : uri})
vcard['alias'] = alias
vcard['email'] = email