From cc1061ecf119d5fb9b6764618080637b7d617998 Mon Sep 17 00:00:00 2001
From: "Schimon Jehudah, Adv." <sjehuda@yandex.com>
Date: Tue, 15 Oct 2024 20:37:46 +0300
Subject: [PATCH] Python : Fix an error upon failiure to achieve items of a
 Jabber ID (Thanks. ThUnD3r|Gr33n)

---
 fasi.py | 39 ++++++++++++++++++++-------------------
 1 file changed, 20 insertions(+), 19 deletions(-)

diff --git a/fasi.py b/fasi.py
index e8b2e8d..c0d1d8e 100644
--- a/fasi.py
+++ b/fasi.py
@@ -628,7 +628,7 @@ class FileUtilities:
 
     async def cache_jid_data(jabber_id, password, jid_bare, node_name=None, item_id=None, alias=None):
 
-        count = title = ''
+        count = iq_disco_items_list = iq_disco_items_items_list = title = ''
         jid_vcard = {
             'name' : '',
             'note' : '',
@@ -675,23 +675,24 @@ class FileUtilities:
 
         # TODO /d/pubsub.nicoco.fr/blog/urn-uuid-53e43061-1962-3112-bb8a-1473dca61719
         jid_items = await XmppXep0030.get_jid_items(xmpp_instance, jid_bare)
-        iq = jid_items['iq']
-        iq_disco_items = iq['disco_items']
-        iq_disco_items_items = iq_disco_items['items']
-        #iq_disco_items_set = {''}
-        iq_disco_items_list = []
-        iq_disco_items_items_list = []
-        for item in iq_disco_items_items:
-            if jid_kind == 'muc':
-                #iq_disco_items_set.update([item[2]])
-                iq_disco_items_list.append(item[2])
-            else:
-                #iq_disco_items_set.update([item[1]])
-                iq_disco_items_list.append(item[1])
-            iq_disco_items_items_list.append(
-                [item[0] or '', item[1] or '', item[2] or ''])
-        #count = len(iq_disco_items_set)
-        count = len(iq_disco_items_list)
+        if isinstance(jid_items['iq'], stanza.iq.Iq):
+            iq = jid_items['iq']
+            iq_disco_items = iq['disco_items']
+            iq_disco_items_items = iq_disco_items['items']
+            #iq_disco_items_set = {''}
+            iq_disco_items_list = []
+            iq_disco_items_items_list = []
+            for item in iq_disco_items_items:
+                if jid_kind == 'muc':
+                    #iq_disco_items_set.update([item[2]])
+                    iq_disco_items_list.append(item[2])
+                else:
+                    #iq_disco_items_set.update([item[1]])
+                    iq_disco_items_list.append(item[1])
+                iq_disco_items_items_list.append(
+                    [item[0] or '', item[1] or '', item[2] or ''])
+            #count = len(iq_disco_items_set)
+            count = len(iq_disco_items_list)
 
         # Title
         print('Title')
@@ -774,7 +775,7 @@ class FileUtilities:
         print('Node items')
         nodes = {}
         #if node_name and node_name in iq_disco_items_set:
-        if node_name and node_name in iq_disco_items_list:
+        if iq_disco_items_list and node_name and node_name in iq_disco_items_list:
             action = 'Browse'
             node_item_ids = await XmppXep0060.get_node_item_ids(xmpp_instance, jid_bare, node_name)
             if isinstance(node_item_ids['iq'], stanza.iq.Iq):