How to use encoded_response method in localstack

Best Python code snippet using localstack_python

mock_tutk_library.py

Source:mock_tutk_library.py Github

copy

Full Screen

1# type: ignore2import ctypes3import json4import random5import string6import time7from wyzecam.tutk import tutk, tutk_protocol8RESPONDED = 29RECIEVED = 110def allow_retval(func):11 func.retval = None12 def wrapper(*args, **kwargs):13 if func.retval is not None:14 return func.retval15 return func(*args, **kwargs)16 def get_retval():17 return func.retval18 def set_retval(val):19 func.retval = val20 wrapper.get_retval = get_retval21 wrapper.set_retval = set_retval22 return wrapper23class MockTutkLibrary:24 """A mock tutk_platform_lib, for testing"""25 def __init__(self):26 self.got_resolving_bit_doorbell = None27 self.client_stop_called = False28 self.deinitialize_called = False29 self.session_closed_called = False30 self.got_hello = None31 self.got_auth = None32 self.got_resolving_bit = None33 def avRecvFrameData2(34 self,35 frame_data_ptr,36 frame_data_max_ptr,37 frame_data_actual_len_ptr,38 frame_data_expected_len_ptr,39 frame_info_ptr,40 frame_info_max_len,41 frame_info_actual_len_ptr,42 frame_index_ptr,43 ):44 pass45 def avRecvIOCtrl(46 self,47 av_chan_id,48 pn_io_ctrl_type_ptr,49 ctl_data,50 ctl_data_len,51 timeout_ms,52 ):53 if isinstance(timeout_ms, ctypes.c_int):54 timeout_ms = timeout_ms.value55 if self.got_hello == RECIEVED:56 encoded_response = self.respond_10000_hello()57 ctl_data[: len(encoded_response)] = encoded_response58 ctl_data_len.value = len(encoded_response)59 self.got_hello = RESPONDED60 return len(encoded_response)61 elif self.got_auth == RECIEVED:62 encoded_response = self.respond_10002_auth()63 ctl_data[: len(encoded_response)] = encoded_response64 ctl_data_len.value = len(encoded_response)65 self.got_auth = RESPONDED66 return len(encoded_response)67 elif self.got_resolving_bit == RECIEVED:68 encoded_response = self.respond_10056_resolving_bit()69 ctl_data[: len(encoded_response)] = encoded_response70 ctl_data_len.value = len(encoded_response)71 self.got_resolving_bit = RESPONDED72 return len(encoded_response)73 elif self.got_resolving_bit_doorbell == RECIEVED:74 encoded_response = self.respond_10052_resolving_bit_doorbell()75 ctl_data[: len(encoded_response)] = encoded_response76 ctl_data_len.value = len(encoded_response)77 self.got_resolving_bit = RESPONDED78 return len(encoded_response)79 else:80 time.sleep(timeout_ms / 10_000) # 10x faster than usual81 return tutk.AV_ER_TIMEOUT82 def respond_10056_resolving_bit(self):83 response = bytes(1)84 encoded_response = tutk_protocol.encode(10057, len(response), response)85 return encoded_response86 def respond_10052_resolving_bit_doorbell(self):87 response = bytes(1)88 encoded_response = tutk_protocol.encode(10053, len(response), response)89 return encoded_response90 def respond_10002_auth(self):91 response = json.dumps({"connectionRes": "1", "cameraInfo": {}}).encode(92 "ascii"93 )94 encoded_response = tutk_protocol.encode(10003, len(response), response)95 return encoded_response96 def respond_10000_hello(self):97 camera_status = 398 challenge_bytes = "".join(99 random.choice(string.ascii_letters) for _ in range(16)100 ).encode("ascii")101 response = bytes([camera_status]) + challenge_bytes102 encoded_response = tutk_protocol.encode(10001, len(response), response)103 return encoded_response104 def avClientSetMaxBufSize(self, size):105 pass106 def avClientStop(self, av_chan_id):107 self.client_stop_called = True108 def avSendIOCtrl(self, av_chan_id, ctrl_type, cdata, length):109 data = ctypes.cast(cdata, ctypes.POINTER(ctypes.c_char))[:length]110 print(data)111 header, data = tutk_protocol.decode(data)112 if header.code == 10000:113 self.got_hello = RECIEVED114 elif header.code == 10002:115 self.got_auth = RECIEVED116 elif header.code == 10056:117 self.got_resolving_bit = RECIEVED118 elif header.code == 10052:119 self.got_resolving_bit_doorbell = RECIEVED120 else:121 raise ValueError("Unexpected command sent!")122 print(header, data)123 def avClientStart(124 self,125 session_id,126 username,127 password,128 n_timeout,129 user_defined_service_type_ptr,130 chan_id,131 ):132 return 0133 def avInitialize(self, max_num_channels):134 return 0135 def avDeInitialize(self):136 self.deinitialize_called = True137 def IOTC_Session_Check(self, session_id, sess_info_ptr):138 return 0139 def IOTC_Session_Close(self, session_id):140 self.session_closed_called = True141 def IOTC_Connect_ByUID(self, p2p_id):142 return 0143 @allow_retval144 def IOTC_Connect_ByUID_Parallel(self, p2p_id, session_id):145 return session_id146 def IOTC_Set_Log_Path(self, path, max_size):147 pass148 def IOTC_Get_Version(self, version_ptr: ctypes.POINTER):149 version_ptr.contents.value = 0xDEADBEEF150 def IOTC_Initialize2(self, udp_port):151 return 0152 def IOTC_DeInitialize(self):153 pass154 def IOTC_Get_SessionID(self):...

Full Screen

Full Screen

utils.py

Source:utils.py Github

copy

Full Screen

1"""Утилиты"""2import json3from .variables import MAX_PACKAGE_LENGTH, ENCODING4def get_message(client):5 '''6 Утилита приёма и декодирования сообщения7 принимает байты выдаёт словарь, если приняточто-то другое отдаёт ошибку значения8 :param client:9 :return:10 '''11 encoded_response = client.recv(MAX_PACKAGE_LENGTH)12 if isinstance(encoded_response, bytes):13 json_response = encoded_response.decode(ENCODING)14 response = json.loads(json_response)15 if isinstance(response, dict):16 return response17 raise ValueError18 raise ValueError19def send_message(sock, message):20 '''21 Утилита кодирования и отправки сообщения22 принимает словарь и отправляет его23 :param sock:24 :param message:25 :return:26 '''27 js_message = json.dumps(message)28 encoded_message = js_message.encode(ENCODING)...

Full Screen

Full Screen

messages.py

Source:messages.py Github

copy

Full Screen

1import json2import sys3from errors import IncorrectDataRecivedError, NonDictInputError4from variables import MAX_PACKAGE_LENGTH, ENCODING5sys.path.append('/')6def get_message(client):7 encoded_response = client.recv(MAX_PACKAGE_LENGTH)8 if isinstance(encoded_response, bytes):9 json_response = encoded_response.decode(ENCODING)10 response = json.loads(json_response)11 if isinstance(response, dict):12 return response13 else:14 raise IncorrectDataRecivedError15 else:16 raise IncorrectDataRecivedError17def send_message(sock, message):18 if not isinstance(message, dict):19 raise NonDictInputError20 js_message = json.dumps(message)21 encoded_message = js_message.encode(ENCODING)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful