Best Python code snippet using playwright-python
test_lookup_manager.py
Source:test_lookup_manager.py
...71 eq_(self.lookup.num_parallel_queries, 2)72 nodes = [tc.NODES_LD_IH[157][5],73 tc.NODES_LD_IH[152][6],74 tc.NODES_LD_IH[158][7]]75 self.lookup._on_response(*_gen_nodes_args(76 tc.NODES_LD_IH[157][3],77 nodes))78 eq_(self.lookup._get_announce_candidates(),79 [tc.NODES_LD_IH[157][3],80 ])81 # This response triggers a new query (to 152-6)82 eq_(self.lookup.num_parallel_queries, 2)83 # Ongoing queries to (sorted: oldest first):84 # 155-4, 152-685 # Queued nodes to query (sorted by log_distance to info_hash):86 # 157-5, 158-1, 158-7, 159-087 self.lookup._on_timeout(tc.NODES_LD_IH[155][4])88 eq_(self.lookup.num_parallel_queries, 2)89 # This timeout triggers a new query (to 157-5)90 eq_(self.lookup.num_parallel_queries, 2) 91 # Ongoing queries to (sorted: oldest first):92 # 155-4, 157-5 93 # Queued nodes to query (sorted by log_distance to info_hash):94 # 158-1, 158-7, 159-095 self.lookup._on_timeout(tc.NODES_LD_IH[155][4])96 # This timeout triggers a new query (to 158-1)97 eq_(self.lookup.num_parallel_queries, 2) 98 # Ongoing queries to (sorted: oldest first):99 # 152-6, 158-1100 # Queued nodes to query (sorted by log_distance to info_hash):101 # 158-7, 159-0102 nodes = [tc.NODES_LD_IH[151][8],103 tc.NODES_LD_IH[150][9]]104 self.lookup._on_response(*_gen_nodes_args(105 tc.NODES_LD_IH[152][6],106 nodes))107 eq_(self.lookup._get_announce_candidates(),108 [tc.NODES_LD_IH[152][6],109 tc.NODES_LD_IH[157][3],110 ])111 # This response triggers a new query (to 150-9)112 eq_(self.lookup.num_parallel_queries, 2) 113 # Ongoing queries to (sorted: oldest first):114 # 157-5, 150-9115 # Queued nodes to query (sorted by log_distance to info_hash):116 # 151-8, 158-7, 159-0117 nodes = [tc.NODES_LD_IH[151][10],118 tc.NODES_LD_IH[151][11],119 tc.NODES_LD_IH[156][12],120 tc.NODES_LD_IH[156][13],121 ]122 self.lookup._on_response(*_gen_nodes_args(123 tc.NODES_LD_IH[157][5],124 nodes))125 eq_(self.lookup._get_announce_candidates(),126 [tc.NODES_LD_IH[152][6],127 tc.NODES_LD_IH[157][3],128 tc.NODES_LD_IH[157][5],129 ])130 # This response triggers a new query (to 151-8)131 eq_(self.lookup.num_parallel_queries, 2) 132 # Ongoing queries to (sorted: oldest first):133 # 150-9, 151-8134 # Queued nodes to query (sorted by log_distance to info_hash):135 # 151-10, 151-11, 156-12, 156-13136 # Notice that the lookup queue size limit is 4, therefore137 # 158-7 and 159-0 are removed from the queue138 self.lookup._on_error(None, tc.NODES_LD_IH[151][8])139 # This error triggers a new query (to 151-8)140 eq_(self.lookup.num_parallel_queries, 2)141 # Ongoing queries to (sorted: oldest first):142 # 150-9, 151-10143 # Queued nodes to query (sorted by log_distance to info_hash):144 # 151-11, 156-12, 156-13145 self.lookup._on_timeout(tc.NODES_LD_IH[151][8])146 # This timeout triggers a new query (to 151-11)147 eq_(self.lookup.num_parallel_queries, 2)148 # Ongoing queries to (sorted: oldest first):149 # 151-10, 151-11150 # Queued nodes to query (sorted by log_distance to info_hash):151 # 156-12, 156-13152 nodes = [tc.NODES_LD_IH[144][14],153 tc.NODES_LD_IH[145][15],154 tc.NODES_LD_IH[145][16],155 tc.NODES_LD_IH[145][17],156 ]157 self.lookup._on_response(*_gen_nodes_args(158 tc.NODES_LD_IH[151][10],159 nodes))160 eq_(self.lookup._get_announce_candidates(), [tc.NODES_LD_IH[151][10],161 tc.NODES_LD_IH[152][6],162 tc.NODES_LD_IH[157][3],163 ])164 # This response triggers a new query (to 144-14)165 eq_(self.lookup.num_parallel_queries, 2)166 # Ongoing queries to (sorted: oldest first):167 # 151-11, 144-14168 # Queued nodes to query (sorted by log_distance to info_hash):169 # Notice 156-13 is removed170 # 145-15, 145-16, 145-17, 156-12171 peers = [tc.NO_ADDR]172 ok_(not self.got_peers)173 self.lookup._on_response(*_gen_peers_args(174 tc.NODES_LD_IH[144][14],175 peers))176 eq_(self.lookup._get_announce_candidates(), [tc.NODES_LD_IH[144][14],177 tc.NODES_LD_IH[151][10],178 tc.NODES_LD_IH[152][6],179 ])180 ok_(self.got_peers)181 self.got_peers = False182 # The response with peers halves parallelism to 1.183 # No new query is triggered.184 eq_(self.lookup.num_parallel_queries, 1)185 # Ongoing queries to (sorted: oldest first):186 # 151-11187 # Queued nodes to query (sorted by log_distance to info_hash):188 # 145-15, 145-16, 156-12189 self.lookup._on_timeout(tc.NODES_LD_IH[151][11])190 # This timeout triggers a new query (to 145-15)191 eq_(self.lookup.num_parallel_queries, 1)192 # Ongoing queries to (sorted: oldest first):193 # 145-15194 # Queued nodes to query (sorted by log_distance to info_hash):195 # 145-16, 145-17, 156-12196 peers = [tc.NO_ADDR]197 ok_(not self.got_peers)198 self.lookup._on_response(*_gen_peers_args(199 tc.NODES_LD_IH[145][15],200 peers))201 # This response triggers a new query (to 145-16)202 # The parallelism is not halved (remains 1).203 eq_(self.lookup.num_parallel_queries, 1)204 # Ongoing queries to (sorted: oldest first):205 # 145-16206 # Queued nodes to query (sorted by log_distance to info_hash):207 # 145-17, 156-12208 eq_(self.lookup._get_announce_candidates(), [tc.NODES_LD_IH[144][14],209 tc.NODES_LD_IH[145][15],210 tc.NODES_LD_IH[151][10],211 ])212 ok_(self.got_peers)213 self.got_peers = False214 self.lookup._on_timeout(tc.NODES_LD_IH[145][16])215 # This timeout triggers a new query (to 145-17)216 eq_(self.lookup.num_parallel_queries, 1)217 # Ongoing queries to (sorted: oldest first):218 # 145-17219 # Queued nodes to query (sorted by log_distance to info_hash):220 # 156-12221 self.lookup._on_timeout(tc.NODES_LD_IH[145][17])222 # This timeout triggers a new query (to 156-12)223 return224 eq_(self.lookup.num_parallel_queries, 1)225 # Ongoing queries to (sorted: oldest first):226 # 156-12227 # Queued nodes to query (sorted by log_distance to info_hash):228 # 229 nodes = [tc.NODES_LD_IH[144][18],230 tc.NODES_LD_IH[145][19],231 ]232 self.lookup._on_response(*_gen_nodes_args(233 tc.NODES_LD_IH[156][12],234 nodes))235 eq_(self.lookup._get_announce_candidates(), [tc.NODES_LD_IH[144][14],236 tc.NODES_LD_IH[145][15],237 tc.NODES_LD_IH[151][10],238 ])239 # This response triggers a new query (to 144-18)240 eq_(self.lookup.num_parallel_queries, 1)241 # Ongoing queries to (sorted: oldest first):242 # 144-18243 # Queued nodes to query (sorted by log_distance to info_hash):244 # 145-19245 peers = [tc.NO_ADDR]246 ok_(not self.got_peers)247 self.lookup._on_response(*_gen_peers_args(248 tc.NODES_LD_IH[144][18],249 peers))250 eq_(self.lookup._get_announce_candidates(), [tc.NODES_LD_IH[144][14],251 tc.NODES_LD_IH[144][18],252 tc.NODES_LD_IH[145][15],253 ])254 ok_(self.got_peers)255 self.got_peers = False256 # This timeout triggers a new query (145-19)257 eq_(self.lookup.num_parallel_queries, 0)258 # Ongoing queries to (sorted: oldest first):259 # 145-19260 # Queued nodes to query (sorted by log_distance to info_hash):261 #262 ok_(not self.lookup.is_done)263 self.lookup._on_timeout(tc.NODES_LD_IH[145][19])264 # THE END265 eq_(self.lookup.num_parallel_queries, 0)266 ok_(self.lookup.is_done)267 def test_dont_query_myself(self):268 log.debug('test start')269 self.lookup.start()270 # Ongoing queries to (sorted: oldest first):271 # 155-4, 157-3, 272 # Queued nodes to query (sorted by log_distance to info_hash):273 # 158-1, 159-0274 # Notice 159-2 is kicked out from the queue275 eq_(self.lookup.num_parallel_queries, 2)276 nodes = [Node(tc.CLIENT_ADDR, self.lookup._my_id)]277 self.lookup._on_response(*_gen_nodes_args(278 tc.NODES_LD_IH[157][3],279 nodes))280 eq_(self.lookup._get_announce_candidates(),281 [tc.NODES_LD_IH[157][3],282 ])283 # This response triggers a new query to 158-1 (ignoring myself)284 eq_(self.lookup.num_parallel_queries, 2)285 # Ongoing queries to (sorted: oldest first):286 # 155-4, 158-1287 # Queued nodes to query (sorted by log_distance to info_hash):288 # 159-0289 self.lookup._on_timeout(tc.NODES_LD_IH[155][4])290 # This timeout triggers a new query (to 159-0)291 eq_(self.lookup.num_parallel_queries, 2) 292 self.lookup._on_timeout(tc.NODES_LD_IH[158][1])293 # No more nodes to send queries to294 eq_(self.lookup.num_parallel_queries, 1)295 ok_(not self.lookup.is_done)296 self.lookup._on_timeout(tc.NODES_LD_IH[159][0]) 297 # No more nodes to send queries to298 eq_(self.lookup.num_parallel_queries, 0)299 ok_(self.lookup.is_done)300 301class TestLookupManager:302 def _on_got_peers(self, peers):303 self.got_peers = peers304 305 306 def setup(self):307 self.got_peers = None308 querier_ = querier.QuerierMock(tc.CLIENT_ID)309 routing_m = RoutingManagerMock()310 self.bootstrap_nodes = routing_m.get_closest_rnodes(311 tc.INFO_HASH_ZERO)312 self.lm = lookup_manager.LookupManager(tc.CLIENT_ID,313 querier_,314 routing_m,315 2)316 self.lookup = self.lm.get_peers(tc.INFO_HASH, self._on_got_peers,317 tc.BT_PORT)318 def test_all_nodes_timeout(self):319 for node_ in self.bootstrap_nodes:320 self.lookup._on_timeout(node_)321 ok_(self.lookup.is_done)322 def test_peers(self):323 self.lookup._on_response(*_gen_peers_args(324 self.bootstrap_nodes[0],325 [tc.NO_ADDR]))326 for node_ in self.bootstrap_nodes[1:]:327 self.lookup._on_timeout(node_)328 ok_(self.lookup.is_done)329 def teardown(self):330 self.lm.stop()331 332def _gen_nodes_args(node_, nodes):333 out_msg = message.OutgoingGetPeersResponse(334 node_.id,335 tc.TOKEN,336 nodes2=nodes).encode(tc.TID)337 in_msg = message.IncomingMsg(out_msg)...
rabbitmq.py
Source:rabbitmq.py
...83 def _process_data_events(self):84 """Process Data Events using the Process Thread."""85 print('[AMPQSTORM:_process_data_events] Consuming..')86 self.channel.start_consuming()87 def _on_response(self, message):88 """On Response store the message with the correlation id in a local89 dictionary.90 """91 # TODO: This could be more nuanced, but who has time for that.92 try:93 print('[AMPQSTORM:_on_response] Message Properties: ' + json.dumps(message.properties))94 print('[AMPQSTORM:_on_response] Message Body: ' + message.body)95 if message.correlation_id in self.queue:96 print('[AMPQSTORM:_on_response] Got a response to one of our messages. Updating queue.')97 self.queue[message.correlation_id] = message.body98 elif message.properties['message_type'] == 'Agent':99 print("[AMPQSTORM:_on_response] Got Agent at {0}".format(message.timestamp))100 agent = json.loads(message.body)101 agent['Success'] = True...
PackData.py
Source:PackData.py
1# -*- coding: utf-8 -*2import makeblock.utils3class NeuronPackData:4 TYPE_REQUEST = 05 TYPE_CHANGE = 16 TYPE_PERIOD = 27 def __init__(self,pack=[]):8 self._type = NeuronPackData.TYPE_REQUEST9 self._header = 0xf010 self._idx = 0x011 self._service = 0x012 self._subservice = 0x013 self._data = []14 self._checksum = 0x015 self._footer = 0xf716 self._on_response = ""17 end = len(pack)18 if(end > 0):19 self._header = pack[0]20 self._idx = pack[1]21 self._service = pack[2]22 self._subservice = pack[3]23 self._data = pack[4:end-2]24 if pack[end-2]>0:25 self._checksum = pack[end-2]26 else:27 self._checksum = self.checksum28 self._footer = pack[end-1]29 def to_buffer(self):30 bytes = bytearray()31 bytes.append(self._header)32 bytes.append(self._idx)33 bytes.append(self._service)34 bytes.append(self._subservice)35 for i in range(len(self._data)):36 bytes.append(self._data[i])37 bytes.append(self.checksum)38 bytes.append(self._footer)39 return bytes40 @property41 def checksum(self):42 sum = self._idx+self._service+self._subservice43 for i in self._data:44 sum += i45 sum &= 0x7f46 return sum47 @property48 def service(self):49 return self._service50 @service.setter51 def service(self,value):52 self._service = value53 @property54 def subservice(self):55 return self._subservice56 @subservice.setter57 def subservice(self,value):58 self._subservice = value59 60 @property61 def idx(self):62 return self._idx63 @idx.setter64 def idx(self,value):65 self._idx = value66 67 @property68 def type(self):69 return self._type70 @type.setter71 def type(self,value):72 self._type = value73 @property74 def data(self):75 return self._data76 @data.setter77 def data(self,value):78 self._data = value79 @property80 def on_response(self):81 return self._on_response82 @on_response.setter83 def on_response(self,value):84 self._on_response = value85 86 @staticmethod87 def broadcast():88 pack = NeuronPackData([0xf0,0xff,0x10,0x0,0xf,0xf7])89 return pack90class HalocodePackData():91 TYPE_RUN_WITHOUT_RESPONSE = 0x092 TYPE_RUN_WITH_RESPONSE = 0x193 TYPE_RESET = 0x294 TYPE_SUBSCRIBE = 0x2995 TYPE_SCRIPT = 0x2896 def __init__(self,buf=[]):97 self._type = HalocodePackData.TYPE_SCRIPT98 self._mode = HalocodePackData.TYPE_RUN_WITHOUT_RESPONSE99 self._value_name = ""100 self._header = 0xf3101 self._datalen = 0x0102 self._idx = 0103 self._type = 0x0104 self._data = []105 self._checksum = 0x0106 self._footer = 0xf4107 self._on_response = ""108 self._subscribe_key = 0109 self._subscribe_value = 0110 self._script = ""111 end = len(buf)112 if(end > 7):113 self._header = buf[0]114 self._datalen = buf[2]+buf[3]*256115 self._type = buf[4]116 self._mode = buf[5]117 if self._type==HalocodePackData.TYPE_SCRIPT:118 self._idx = buf[6]+(buf[7]<<8)119 self._data = buf[7:end-2]120 if self._type==HalocodePackData.TYPE_SUBSCRIBE:121 self._data = buf[5:end-2]122 if buf[end-2]>0:123 self._checksum = buf[end-2]124 else:125 self._checksum = self.checksum126 self._footer = buf[end-1]127 def to_buffer(self):128 bytes = bytearray()129 bytes.append(self._header)130 datalen = len(self._data)+4131 bytes.append((((datalen>>8)&0xff)+(datalen&0xff)+0xf3)&0xff)132 bytes.append(datalen&0xff)133 bytes.append((datalen>>8)&0xff)134 bytes.append(self._type)135 bytes.append(self._mode)136 bytes.append(self._idx&0xff)137 bytes.append((self._idx>>8)&0xff)138 for i in range(len(self._data)):139 bytes.append(self._data[i])140 bytes.append(self.checksum)141 bytes.append(self._footer)142 return bytes143 @property144 def checksum(self):145 sum = self._type+self._mode+((self._idx>>8)&0xff)+(self._idx&0xff)146 for i in range(len(self._data)):147 sum += self._data[i]148 return sum&0xff149 @property150 def script(self):151 return self._script152 @script.setter153 def script(self,value):154 self._script = value155 script_data = [ord(c) for c in value]156 datalen = len(script_data)157 self._data = [datalen&0xff,(datalen>>8)&0xff]158 self._data.extend(script_data)159 @property160 def subscribe_key(self):161 return self._subscribe_key162 @subscribe_key.setter163 def subscribe_key(self,value):164 self.script = self.script.format(value)165 self._subscribe_key = value166 @property167 def subscribe_value(self):168 return self._subscribe_value169 @property170 def value_name(self):171 return self._value_name172 @value_name.setter173 def value_name(self,value):174 self._value_name = value175 @subscribe_value.setter176 def subscribe_value(self,value):177 self._subscribe_value = value178 @property179 def type(self):180 return self._type181 @type.setter182 def type(self,value):183 self._type = value184 @property185 def mode(self):186 return self._mode187 @mode.setter188 def mode(self,value):189 self._mode = value190 @property191 def datalen(self):192 return self._datalen193 @datalen.setter194 def datalen(self,value):195 self._datalen = value196 @property197 def idx(self):198 return self._idx199 @idx.setter200 def idx(self,value):201 self._idx = value202 @property203 def data(self):204 return self._data205 @data.setter206 def data(self,value):207 self._data = value208 @property209 def on_response(self):210 return self._on_response211 @on_response.setter212 def on_response(self,value):213 self._on_response = value214 215 @staticmethod216 def broadcast():217 return HalocodePackData([0xf3, 0xf6, 0x03, 0x0, 0x0d, 0x0, 0x01, 0x0e, 0xf4])218class MegaPiPackData():219 ACTION_GET = 1220 ACTION_RUN = 2221 ACTION_RESET = 4222 ACTION_START = 5223 def __init__(self,pack=[]):224 self._headers = [0xff,0x55]225 self._idx = 0x0226 self._action = MegaPiPackData.ACTION_RUN227 self._port = 0228 self._slot = 0229 self._module = 0230 self._data = []231 self._checksum = 0x0232 self._on_response = ""233 self._footer = 0xa234 end = len(pack)235 if(end > 0):236 self._headers = pack[0:2]237 self._idx = pack[2]238 self._data = pack[3:end-2]239 self._footer = pack[end-1]240 def to_buffer(self):241 bytes = bytearray()242 bytes.extend(self._headers)243 bytes.append(0)244 bytes.append(self._idx)245 bytes.append(self._action)246 bytes.append(self._module)247 for i in range(len(self._data)):248 bytes.append(self._data[i])249 bytes.append(self._footer)250 bytes[2] = len(bytes)-3251 return bytes252 @property253 def checksum(self):254 sum = self._idx+self._action+self._module255 for i in range(len(self._data)):256 sum += self._data[i]257 sum &= 0x7f258 return sum259 @property260 def module(self):261 return self._module262 @module.setter263 def module(self,value):264 self._module = value265 @property266 def idx(self):267 return self._idx268 @idx.setter269 def idx(self,value):270 self._idx = value271 272 @property273 def port(self):274 return self._port275 @port.setter276 def port(self,value):277 self._port = value278 @property279 def slot(self):280 return self._slot281 @slot.setter282 def slot(self,value):283 self._slot = value284 285 @property286 def action(self):287 return self._action288 @action.setter289 def action(self,value):290 self._action = value291 @property292 def data(self):293 return self._data294 @data.setter295 def data(self,value):296 self._data = value297 @property298 def on_response(self):299 return self._on_response300 @on_response.setter301 def on_response(self,value):302 self._on_response = value...
features_nb.py
Source:features_nb.py
...18(Registration, Privacy Lists, ...)19"""20from .protocol import NS_REGISTER, NS_PRIVACY, NS_DATA, Iq, isResultNode, Node21def _on_default_response(disp, iq, cb):22 def _on_response(resp):23 if isResultNode(resp):24 if cb:25 cb(True)26 elif cb:27 cb(False)28 disp.SendAndCallForResponse(iq, _on_response)29###############################################################################30### Registration31###############################################################################32REGISTER_DATA_RECEIVED = 'REGISTER DATA RECEIVED'33def getRegInfo(disp, host, info={}, sync=True):34 """35 Get registration form from remote host. Info dict can be prefilled36 :param disp: plugged dispatcher instance37 :param info: dict, like {'username':'joey'}.38 See JEP-0077 for details.39 """40 iq=Iq('get', NS_REGISTER, to=host)41 for i in info.keys():42 iq.setTagData(i, info[i])43 if sync:44 disp.SendAndCallForResponse(iq, lambda resp:45 _ReceivedRegInfo(disp.Dispatcher, resp, host))46 else:47 disp.SendAndCallForResponse(iq, _ReceivedRegInfo, {'agent': host })48def _ReceivedRegInfo(con, resp, agent):49 Iq('get', NS_REGISTER, to=agent)50 if not isResultNode(resp):51 error_msg = resp.getErrorMsg()52 con.Event(NS_REGISTER, REGISTER_DATA_RECEIVED, (agent, None, False, error_msg, ''))53 return54 tag=resp.getTag('query', namespace=NS_REGISTER)55 if not tag:56 error_msg = resp.getErrorMsg()57 con.Event(NS_REGISTER, REGISTER_DATA_RECEIVED, (agent, None, False, error_msg, ''))58 return59 df=tag.getTag('x', namespace=NS_DATA)60 if df:61 con.Event(NS_REGISTER, REGISTER_DATA_RECEIVED, (agent, df, True, '',62 tag))63 return64 df={}65 for i in resp.getQueryPayload():66 if not isinstance(i, Node):67 continue68 df[i.getName()] = i.getData()69 con.Event(NS_REGISTER, REGISTER_DATA_RECEIVED, (agent, df, False, '', ''))70def register(disp, host, info, cb, args=None):71 """72 Perform registration on remote server with provided info73 If registration fails you can get additional info from the dispatcher's74 owner attributes lastErrNode, lastErr and lastErrCode.75 """76 iq=Iq('set', NS_REGISTER, to=host)77 if not isinstance(info, dict):78 info=info.asDict()79 for i in info.keys():80 iq.setTag('query').setTagData(i, info[i])81 disp.SendAndCallForResponse(iq, cb, args)82def unregister(disp, host, cb):83 """84 Unregisters with host (permanently removes account). Returns true on success85 """86 iq = Iq('set', NS_REGISTER, to=host, payload=[Node('remove')])87 _on_default_response(disp, iq, cb)88def changePasswordTo(disp, newpassword, host=None, cb = None):89 """90 Changes password on specified or current (if not specified) server. Returns91 true on success.92 """93 if not host:94 host = disp._owner.Server95 iq = Iq('set', NS_REGISTER, to=host, payload=[Node('username',96 payload=[disp._owner.Server]), Node('password', payload=[newpassword])])97 _on_default_response(disp, iq, cb)98###############################################################################99### Privacy List100###############################################################################101PL_TYPE_JID = 'jid'102PL_TYPE_GROUP = 'group'103PL_TYPE_SUBC = 'subscription'104PL_ACT_ALLOW = 'allow'105PL_ACT_DENY = 'deny'106PRIVACY_LISTS_RECEIVED = 'PRIVACY LISTS RECEIVED'107PRIVACY_LIST_RECEIVED = 'PRIVACY LIST RECEIVED'108PRIVACY_LISTS_ACTIVE_DEFAULT = 'PRIVACY LISTS ACTIVE DEFAULT'109def getPrivacyLists(disp):110 """111 Request privacy lists from connected server. Returns dictionary of existing112 lists on success.113 """114 iq = Iq('get', NS_PRIVACY)115 def _on_response(resp):116 dict_ = {'lists': []}117 if not isResultNode(resp):118 disp.Event(NS_PRIVACY, PRIVACY_LISTS_RECEIVED, False)119 return120 for list_ in resp.getQueryPayload():121 if list_.getName()=='list':122 dict_['lists'].append(list_.getAttr('name'))123 else:124 dict_[list_.getName()]=list_.getAttr('name')125 disp.Event(NS_PRIVACY, PRIVACY_LISTS_RECEIVED, dict_)126 disp.SendAndCallForResponse(iq, _on_response)127def getActiveAndDefaultPrivacyLists(disp):128 iq = Iq('get', NS_PRIVACY)129 def _on_response(resp):130 dict_ = {'active': '', 'default': ''}131 if not isResultNode(resp):132 disp.Event(NS_PRIVACY, PRIVACY_LISTS_ACTIVE_DEFAULT, False)133 return134 for list_ in resp.getQueryPayload():135 if list_.getName() == 'active':136 dict_['active'] = list_.getAttr('name')137 elif list_.getName() == 'default':138 dict_['default'] = list_.getAttr('name')139 disp.Event(NS_PRIVACY, PRIVACY_LISTS_ACTIVE_DEFAULT, dict_)140 disp.SendAndCallForResponse(iq, _on_response)141def getPrivacyList(disp, listname):142 """143 Request specific privacy list listname. Returns list of XML nodes (rules)144 taken from the server responce.145 """146 def _on_response(resp):147 if not isResultNode(resp):148 disp.Event(NS_PRIVACY, PRIVACY_LIST_RECEIVED, False)149 return150 disp.Event(NS_PRIVACY, PRIVACY_LIST_RECEIVED, resp)151 iq = Iq('get', NS_PRIVACY, payload=[Node('list', {'name': listname})])152 disp.SendAndCallForResponse(iq, _on_response)153def setActivePrivacyList(disp, listname=None, typ='active', cb=None):154 """155 Switch privacy list 'listname' to specified type. By default the type is156 'active'. Returns true on success.157 """158 if listname:159 attrs={'name':listname}160 else:...
LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.
Get 100 minutes of automation test minutes FREE!!