daily pastebin goal
26%
SHARE
TWEET

Untitled

a guest Jul 7th, 2018 17 in 2 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # emulating the qstate.mesh_info.reply_list
  2.  
  3. # define a reply_list object
  4. class reply_list_object:
  5.     def __init__(self, reply = None):
  6.         self.query_reply = reply
  7.  
  8.  
  9. class Query_Reply:
  10.     ttl = 0
  11.     def __init__(self, addr = None):
  12.         if len(addr):
  13.             self.addr = addr
  14.  
  15. # initialize the reply list
  16. rl = [reply_list_object()]
  17. rl.append(reply_list_object())
  18. rl.append(reply_list_object(Query_Reply('10.0.0.1')))
  19. rl.append(reply_list_object())
  20.  
  21. print("scanning rl list (for debuging)...")
  22. print("-----------------------------------------------------")
  23. for q in rl:
  24.     try:
  25.         addr = q.query_reply.addr
  26.     except NameError:
  27.         addr = None
  28.     except AttributeError:
  29.         addr = None
  30.  
  31.     print("addr = {}".format(addr))
  32.  
  33. print("\n\ngetting the first item with vaid query reply...")
  34. print("-----------------------------------------------------")
  35. q = next((x for x in rl if x.query_reply), None)
  36. try:
  37.     addr = q.query_reply.addr
  38. except NameError:
  39.     addr = None
  40. except AttributeError:
  41.     addr = None
  42.  
  43. print("addr = {}".format(addr))
  44.  
  45. # if a  valid Query_Reply object is passed to the constructor of the reply_list_object,
  46. # then it will be the first to be returned, despite the fact that it contains
  47. # and empty or undef addr attribute. So, if 'rl' is initialized like bellow,
  48. # then 'addr' will be None ...
  49. rl = [reply_list_object()]
  50. rl.append(reply_list_object())
  51. rl.append(reply_list_object(Query_Reply('')))
  52. rl.append(reply_list_object(Query_Reply('10.0.0.1')))
  53. rl.append(reply_list_object())
  54.  
  55. # Note: depending on how 'qstate.mesh_info.reply_list' is defined,
  56. # maybe there is no need for handling both NameError and AttributeError
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top