How to use recv method in Airtest

Best Python code snippet using Airtest

zmq.py

Source:zmq.py Github

copy

Full Screen

...123#124# Events are read from the socket's event pipe only on the thread that125# the 0mq context is associated with, which is the native thread the126# greenthreads are running on, and the only operations that cause the127# events to be read and processed are send(), recv() and128# getsockopt(zmq.EVENTS). This means that after doing any of these129# three operations, the ability of the socket to send or receive a130# message without blocking may have changed, but after the events are131# read the FD is no longer readable so the hub may not signal our132# listener.133#134# If we understand that after calling send() a message might be ready135# to be received and that after calling recv() a message might be able136# to be sent, what should we do next? There are two approaches:137#138# 1. Always wake the other thread if there is one waiting. This139# wakeup may be spurious because the socket might not actually be140# ready for a send() or recv(). However, if a thread is in a141# tight-loop successfully calling send() or recv() then the wakeups142# are naturally batched and there's very little cost added to each143# send/recv call.144#145# or146#147# 2. Call getsockopt(zmq.EVENTS) and explicitly check if the other148# thread should be woken up. This avoids spurious wake-ups but may149# add overhead because getsockopt will cause all events to be150# processed, whereas send and recv throttle processing151# events. Admittedly, all of the events will need to be processed152# eventually, but it is likely faster to batch the processing.153#154# Which approach is better? I have no idea.155#156# TODO:157# - Support MessageTrackers and make MessageTracker.wait green158_Socket = __zmq__.Socket159_Socket_recv = _Socket.recv160_Socket_send = _Socket.send161_Socket_send_multipart = _Socket.send_multipart162_Socket_recv_multipart = _Socket.recv_multipart163_Socket_send_string = _Socket.send_string164_Socket_recv_string = _Socket.recv_string165_Socket_send_pyobj = _Socket.send_pyobj166_Socket_recv_pyobj = _Socket.recv_pyobj167_Socket_send_json = _Socket.send_json168_Socket_recv_json = _Socket.recv_json169_Socket_getsockopt = _Socket.getsockopt170class Socket(_Socket):171 """Green version of :class:`zmq.core.socket.Socket172 The following three methods are always overridden:173 * send174 * recv175 * getsockopt176 To ensure that the ``zmq.NOBLOCK`` flag is set and that sending or receiving177 is deferred to the hub (using :func:`eventlet.hubs.trampoline`) if a178 ``zmq.EAGAIN`` (retry) error is raised179 For some socket types, the following methods are also overridden:180 * send_multipart181 * recv_multipart182 """183 def __init__(self, context, socket_type):184 super(Socket, self).__init__(context, socket_type)185 self.__dict__['_eventlet_send_event'] = _BlockedThread()186 self.__dict__['_eventlet_recv_event'] = _BlockedThread()187 self.__dict__['_eventlet_send_lock'] = _QueueLock()188 self.__dict__['_eventlet_recv_lock'] = _QueueLock()189 def event(fd):190 # Some events arrived at the zmq socket. This may mean191 # there's a message that can be read or there's space for192 # a message to be written.193 send_wake = self._eventlet_send_event.wake()194 recv_wake = self._eventlet_recv_event.wake()195 if not send_wake and not recv_wake:196 # if no waiting send or recv thread was woken up, then197 # force the zmq socket's events to be processed to198 # avoid repeated wakeups199 _Socket_getsockopt(self, EVENTS)200 hub = eventlet.hubs.get_hub()201 self.__dict__['_eventlet_listener'] = hub.add(hub.READ,202 self.getsockopt(FD),203 event,204 lambda _: None,205 lambda: None)206 self.__dict__['_eventlet_clock'] = hub.clock207 @_wraps(_Socket.close)208 def close(self, linger=None):209 super(Socket, self).close(linger)210 if self._eventlet_listener is not None:211 eventlet.hubs.get_hub().remove(self._eventlet_listener)212 self.__dict__['_eventlet_listener'] = None213 # wake any blocked threads214 self._eventlet_send_event.wake()215 self._eventlet_recv_event.wake()216 @_wraps(_Socket.getsockopt)217 def getsockopt(self, option):218 result = _Socket_getsockopt(self, option)219 if option == EVENTS:220 # Getting the events causes the zmq socket to process221 # events which may mean a msg can be sent or received. If222 # there is a greenthread blocked and waiting for events,223 # it will miss the edge-triggered read event, so wake it224 # up.225 if (result & POLLOUT):226 self._eventlet_send_event.wake()227 if (result & POLLIN):228 self._eventlet_recv_event.wake()229 return result230 @_wraps(_Socket.send)231 def send(self, msg, flags=0, copy=True, track=False):232 """A send method that's safe to use when multiple greenthreads233 are calling send, send_multipart, recv and recv_multipart on234 the same socket.235 """236 if flags & NOBLOCK:237 result = _Socket_send(self, msg, flags, copy, track)238 # Instead of calling both wake methods, could call239 # self.getsockopt(EVENTS) which would trigger wakeups if240 # needed.241 self._eventlet_send_event.wake()242 self._eventlet_recv_event.wake()243 return result244 # TODO: pyzmq will copy the message buffer and create Message245 # objects under some circumstances. We could do that work here246 # once to avoid doing it every time the send is retried.247 flags |= NOBLOCK248 with self._eventlet_send_lock:249 while True:250 try:251 return _Socket_send(self, msg, flags, copy, track)252 except ZMQError as e:253 if e.errno == EAGAIN:254 self._eventlet_send_event.block()255 else:256 raise257 finally:258 # The call to send processes 0mq events and may259 # make the socket ready to recv. Wake the next260 # receiver. (Could check EVENTS for POLLIN here)261 self._eventlet_recv_event.wake()262 @_wraps(_Socket.send_multipart)263 def send_multipart(self, msg_parts, flags=0, copy=True, track=False):264 """A send_multipart method that's safe to use when multiple265 greenthreads are calling send, send_multipart, recv and266 recv_multipart on the same socket.267 """268 if flags & NOBLOCK:269 return _Socket_send_multipart(self, msg_parts, flags, copy, track)270 # acquire lock here so the subsequent calls to send for the271 # message parts after the first don't block272 with self._eventlet_send_lock:273 return _Socket_send_multipart(self, msg_parts, flags, copy, track)274 @_wraps(_Socket.send_string)275 def send_string(self, u, flags=0, copy=True, encoding='utf-8'):276 """A send_string method that's safe to use when multiple277 greenthreads are calling send, send_string, recv and278 recv_string on the same socket.279 """280 if flags & NOBLOCK:281 return _Socket_send_string(self, u, flags, copy, encoding)282 # acquire lock here so the subsequent calls to send for the283 # message parts after the first don't block284 with self._eventlet_send_lock:285 return _Socket_send_string(self, u, flags, copy, encoding)286 @_wraps(_Socket.send_pyobj)287 def send_pyobj(self, obj, flags=0, protocol=2):288 """A send_pyobj method that's safe to use when multiple289 greenthreads are calling send, send_pyobj, recv and290 recv_pyobj on the same socket.291 """292 if flags & NOBLOCK:293 return _Socket_send_pyobj(self, obj, flags, protocol)294 # acquire lock here so the subsequent calls to send for the295 # message parts after the first don't block296 with self._eventlet_send_lock:297 return _Socket_send_pyobj(self, obj, flags, protocol)298 @_wraps(_Socket.send_json)299 def send_json(self, obj, flags=0, **kwargs):300 """A send_json method that's safe to use when multiple301 greenthreads are calling send, send_json, recv and302 recv_json on the same socket.303 """304 if flags & NOBLOCK:305 return _Socket_send_json(self, obj, flags, **kwargs)306 # acquire lock here so the subsequent calls to send for the307 # message parts after the first don't block308 with self._eventlet_send_lock:309 return _Socket_send_json(self, obj, flags, **kwargs)310 @_wraps(_Socket.recv)311 def recv(self, flags=0, copy=True, track=False):312 """A recv method that's safe to use when multiple greenthreads313 are calling send, send_multipart, recv and recv_multipart on314 the same socket.315 """316 if flags & NOBLOCK:317 msg = _Socket_recv(self, flags, copy, track)318 # Instead of calling both wake methods, could call319 # self.getsockopt(EVENTS) which would trigger wakeups if320 # needed.321 self._eventlet_send_event.wake()322 self._eventlet_recv_event.wake()323 return msg324 deadline = None325 if hasattr(__zmq__, 'RCVTIMEO'):326 sock_timeout = self.getsockopt(__zmq__.RCVTIMEO)327 if sock_timeout == -1:328 pass329 elif sock_timeout > 0:330 deadline = self._eventlet_clock() + sock_timeout / 1000.0331 else:332 raise ValueError(sock_timeout)333 flags |= NOBLOCK334 with self._eventlet_recv_lock:335 while True:336 try:337 return _Socket_recv(self, flags, copy, track)338 except ZMQError as e:339 if e.errno == EAGAIN:340 # zmq in its wisdom decided to reuse EAGAIN for timeouts341 if deadline is not None and self._eventlet_clock() > deadline:342 e.is_timeout = True343 raise344 self._eventlet_recv_event.block(deadline=deadline)345 else:346 raise347 finally:348 # The call to recv processes 0mq events and may349 # make the socket ready to send. Wake the next350 # receiver. (Could check EVENTS for POLLOUT here)351 self._eventlet_send_event.wake()...

Full Screen

Full Screen

synchronousFSM.py

Source:synchronousFSM.py Github

copy

Full Screen

1# pma.py --maxTransitions 100 synchronous msocket2# 77 states, 100 transitions, 1 accepting states, 0 unsafe states, 0 finished and 0 deadend states3# actions here are just labels, but must be symbols with __name__ attribute4def send_return(): pass5def send_call(): pass6def recv_call(): pass7def recv_return(): pass8# states, key of each state here is its number in graph etc. below9states = {10 0 : {'synchronous': 0, 'msocket': {'send_arg': '', 'recv_arg': 0, 'buffers': ''}},11 1 : {'synchronous': 1, 'msocket': {'send_arg': 'a', 'recv_arg': 0, 'buffers': ''}},12 2 : {'synchronous': 1, 'msocket': {'send_arg': 'bb', 'recv_arg': 0, 'buffers': ''}},13 3 : {'synchronous': 2, 'msocket': {'send_arg': '', 'recv_arg': 0, 'buffers': 'a'}},14 4 : {'synchronous': 2, 'msocket': {'send_arg': '', 'recv_arg': 0, 'buffers': 'bb'}},15 5 : {'synchronous': 2, 'msocket': {'send_arg': '', 'recv_arg': 0, 'buffers': 'b'}},16 6 : {'synchronous': 3, 'msocket': {'send_arg': '', 'recv_arg': 4, 'buffers': 'a'}},17 7 : {'synchronous': 3, 'msocket': {'send_arg': '', 'recv_arg': 4, 'buffers': 'bb'}},18 8 : {'synchronous': 3, 'msocket': {'send_arg': '', 'recv_arg': 4, 'buffers': 'b'}},19 9 : {'synchronous': 0, 'msocket': {'send_arg': '', 'recv_arg': 0, 'buffers': 'b'}},20 10 : {'synchronous': 1, 'msocket': {'send_arg': 'a', 'recv_arg': 0, 'buffers': 'b'}},21 11 : {'synchronous': 1, 'msocket': {'send_arg': 'bb', 'recv_arg': 0, 'buffers': 'b'}},22 12 : {'synchronous': 2, 'msocket': {'send_arg': '', 'recv_arg': 0, 'buffers': 'ba'}},23 13 : {'synchronous': 2, 'msocket': {'send_arg': '', 'recv_arg': 0, 'buffers': 'bbb'}},24 14 : {'synchronous': 3, 'msocket': {'send_arg': '', 'recv_arg': 4, 'buffers': 'ba'}},25 15 : {'synchronous': 3, 'msocket': {'send_arg': '', 'recv_arg': 4, 'buffers': 'bbb'}},26 16 : {'synchronous': 0, 'msocket': {'send_arg': '', 'recv_arg': 0, 'buffers': 'a'}},27 17 : {'synchronous': 0, 'msocket': {'send_arg': '', 'recv_arg': 0, 'buffers': 'bb'}},28 18 : {'synchronous': 1, 'msocket': {'send_arg': 'a', 'recv_arg': 0, 'buffers': 'a'}},29 19 : {'synchronous': 1, 'msocket': {'send_arg': 'bb', 'recv_arg': 0, 'buffers': 'a'}},30 20 : {'synchronous': 1, 'msocket': {'send_arg': 'a', 'recv_arg': 0, 'buffers': 'bb'}},31 21 : {'synchronous': 1, 'msocket': {'send_arg': 'bb', 'recv_arg': 0, 'buffers': 'bb'}},32 22 : {'synchronous': 2, 'msocket': {'send_arg': '', 'recv_arg': 0, 'buffers': 'aa'}},33 23 : {'synchronous': 2, 'msocket': {'send_arg': '', 'recv_arg': 0, 'buffers': 'abb'}},34 24 : {'synchronous': 2, 'msocket': {'send_arg': '', 'recv_arg': 0, 'buffers': 'ab'}},35 25 : {'synchronous': 2, 'msocket': {'send_arg': '', 'recv_arg': 0, 'buffers': 'bba'}},36 26 : {'synchronous': 2, 'msocket': {'send_arg': '', 'recv_arg': 0, 'buffers': 'bbbb'}},37 27 : {'synchronous': 3, 'msocket': {'send_arg': '', 'recv_arg': 4, 'buffers': 'aa'}},38 28 : {'synchronous': 3, 'msocket': {'send_arg': '', 'recv_arg': 4, 'buffers': 'abb'}},39 29 : {'synchronous': 3, 'msocket': {'send_arg': '', 'recv_arg': 4, 'buffers': 'ab'}},40 30 : {'synchronous': 3, 'msocket': {'send_arg': '', 'recv_arg': 4, 'buffers': 'bba'}},41 31 : {'synchronous': 3, 'msocket': {'send_arg': '', 'recv_arg': 4, 'buffers': 'bbbb'}},42 32 : {'synchronous': 0, 'msocket': {'send_arg': '', 'recv_arg': 0, 'buffers': 'ba'}},43 33 : {'synchronous': 0, 'msocket': {'send_arg': '', 'recv_arg': 0, 'buffers': 'bbb'}},44 34 : {'synchronous': 1, 'msocket': {'send_arg': 'a', 'recv_arg': 0, 'buffers': 'ba'}},45 35 : {'synchronous': 1, 'msocket': {'send_arg': 'bb', 'recv_arg': 0, 'buffers': 'ba'}},46 36 : {'synchronous': 1, 'msocket': {'send_arg': 'a', 'recv_arg': 0, 'buffers': 'bbb'}},47 37 : {'synchronous': 1, 'msocket': {'send_arg': 'bb', 'recv_arg': 0, 'buffers': 'bbb'}},48 38 : {'synchronous': 2, 'msocket': {'send_arg': '', 'recv_arg': 0, 'buffers': 'baa'}},49 39 : {'synchronous': 2, 'msocket': {'send_arg': '', 'recv_arg': 0, 'buffers': 'babb'}},50 40 : {'synchronous': 2, 'msocket': {'send_arg': '', 'recv_arg': 0, 'buffers': 'bab'}},51 41 : {'synchronous': 2, 'msocket': {'send_arg': '', 'recv_arg': 0, 'buffers': 'bbba'}},52 42 : {'synchronous': 2, 'msocket': {'send_arg': '', 'recv_arg': 0, 'buffers': 'bbbbb'}},53 43 : {'synchronous': 3, 'msocket': {'send_arg': '', 'recv_arg': 4, 'buffers': 'baa'}},54 44 : {'synchronous': 3, 'msocket': {'send_arg': '', 'recv_arg': 4, 'buffers': 'babb'}},55 45 : {'synchronous': 3, 'msocket': {'send_arg': '', 'recv_arg': 4, 'buffers': 'bab'}},56 46 : {'synchronous': 3, 'msocket': {'send_arg': '', 'recv_arg': 4, 'buffers': 'bbba'}},57 47 : {'synchronous': 3, 'msocket': {'send_arg': '', 'recv_arg': 4, 'buffers': 'bbbbb'}},58 48 : {'synchronous': 0, 'msocket': {'send_arg': '', 'recv_arg': 0, 'buffers': 'aa'}},59 49 : {'synchronous': 0, 'msocket': {'send_arg': '', 'recv_arg': 0, 'buffers': 'abb'}},60 50 : {'synchronous': 0, 'msocket': {'send_arg': '', 'recv_arg': 0, 'buffers': 'ab'}},61 51 : {'synchronous': 0, 'msocket': {'send_arg': '', 'recv_arg': 0, 'buffers': 'bba'}},62 52 : {'synchronous': 0, 'msocket': {'send_arg': '', 'recv_arg': 0, 'buffers': 'bbbb'}},63 53 : {'synchronous': 1, 'msocket': {'send_arg': 'a', 'recv_arg': 0, 'buffers': 'aa'}},64 54 : {'synchronous': 1, 'msocket': {'send_arg': 'bb', 'recv_arg': 0, 'buffers': 'aa'}},65 55 : {'synchronous': 1, 'msocket': {'send_arg': 'a', 'recv_arg': 0, 'buffers': 'abb'}},66 56 : {'synchronous': 1, 'msocket': {'send_arg': 'bb', 'recv_arg': 0, 'buffers': 'abb'}},67 57 : {'synchronous': 1, 'msocket': {'send_arg': 'a', 'recv_arg': 0, 'buffers': 'ab'}},68 58 : {'synchronous': 1, 'msocket': {'send_arg': 'bb', 'recv_arg': 0, 'buffers': 'ab'}},69 59 : {'synchronous': 1, 'msocket': {'send_arg': 'a', 'recv_arg': 0, 'buffers': 'bba'}},70 60 : {'synchronous': 1, 'msocket': {'send_arg': 'bb', 'recv_arg': 0, 'buffers': 'bba'}},71 61 : {'synchronous': 1, 'msocket': {'send_arg': 'a', 'recv_arg': 0, 'buffers': 'bbbb'}},72 62 : {'synchronous': 1, 'msocket': {'send_arg': 'bb', 'recv_arg': 0, 'buffers': 'bbbb'}},73 63 : {'synchronous': 2, 'msocket': {'send_arg': '', 'recv_arg': 0, 'buffers': 'aaa'}},74 64 : {'synchronous': 2, 'msocket': {'send_arg': '', 'recv_arg': 0, 'buffers': 'aabb'}},75 65 : {'synchronous': 2, 'msocket': {'send_arg': '', 'recv_arg': 0, 'buffers': 'aab'}},76 66 : {'synchronous': 2, 'msocket': {'send_arg': '', 'recv_arg': 0, 'buffers': 'abba'}},77 67 : {'synchronous': 2, 'msocket': {'send_arg': '', 'recv_arg': 0, 'buffers': 'abbbb'}},78 68 : {'synchronous': 2, 'msocket': {'send_arg': '', 'recv_arg': 0, 'buffers': 'abbb'}},79 69 : {'synchronous': 2, 'msocket': {'send_arg': '', 'recv_arg': 0, 'buffers': 'aba'}},80 70 : {'synchronous': 2, 'msocket': {'send_arg': '', 'recv_arg': 0, 'buffers': 'bbaa'}},81 71 : {'synchronous': 2, 'msocket': {'send_arg': '', 'recv_arg': 0, 'buffers': 'bbabb'}},82 72 : {'synchronous': 2, 'msocket': {'send_arg': '', 'recv_arg': 0, 'buffers': 'bbab'}},83 73 : {'synchronous': 2, 'msocket': {'send_arg': '', 'recv_arg': 0, 'buffers': 'bbbba'}},84 74 : {'synchronous': 2, 'msocket': {'send_arg': '', 'recv_arg': 0, 'buffers': 'bbbbbb'}},85 75 : {'synchronous': 3, 'msocket': {'send_arg': '', 'recv_arg': 4, 'buffers': 'aaa'}},86 76 : {'synchronous': 3, 'msocket': {'send_arg': '', 'recv_arg': 4, 'buffers': 'aabb'}},87}88# initial state, accepting states, unsafe states, frontier states, deadend states89initial = 090accepting = [0]91unsafe = []92frontier = [65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76]93finished = []94deadend = []95runstarts = [0]96# finite state machine, list of tuples: (current, (action, args, result), next)97graph = (98 (0, (send_call, ('a',), None), 1),99 (0, (send_call, ('bb',), None), 2),100 (1, (send_return, (1,), None), 3),101 (2, (send_return, (2,), None), 4),102 (2, (send_return, (1,), None), 5),103 (3, (recv_call, (4,), None), 6),104 (4, (recv_call, (4,), None), 7),105 (5, (recv_call, (4,), None), 8),106 (6, (recv_return, ('a',), None), 0),107 (7, (recv_return, ('bb',), None), 0),108 (7, (recv_return, ('b',), None), 9),109 (8, (recv_return, ('b',), None), 0),110 (9, (send_call, ('a',), None), 10),111 (9, (send_call, ('bb',), None), 11),112 (10, (send_return, (1,), None), 12),113 (11, (send_return, (2,), None), 13),114 (11, (send_return, (1,), None), 4),115 (12, (recv_call, (4,), None), 14),116 (13, (recv_call, (4,), None), 15),117 (14, (recv_return, ('ba',), None), 0),118 (14, (recv_return, ('b',), None), 16),119 (15, (recv_return, ('bb',), None), 9),120 (15, (recv_return, ('b',), None), 17),121 (16, (send_call, ('a',), None), 18),122 (16, (send_call, ('bb',), None), 19),123 (17, (send_call, ('a',), None), 20),124 (17, (send_call, ('bb',), None), 21),125 (18, (send_return, (1,), None), 22),126 (19, (send_return, (2,), None), 23),127 (19, (send_return, (1,), None), 24),128 (20, (send_return, (1,), None), 25),129 (21, (send_return, (2,), None), 26),130 (21, (send_return, (1,), None), 13),131 (22, (recv_call, (4,), None), 27),132 (23, (recv_call, (4,), None), 28),133 (24, (recv_call, (4,), None), 29),134 (25, (recv_call, (4,), None), 30),135 (26, (recv_call, (4,), None), 31),136 (27, (recv_return, ('aa',), None), 0),137 (27, (recv_return, ('a',), None), 16),138 (28, (recv_return, ('a',), None), 17),139 (28, (recv_return, ('ab',), None), 9),140 (29, (recv_return, ('a',), None), 9),141 (29, (recv_return, ('ab',), None), 0),142 (30, (recv_return, ('bb',), None), 16),143 (30, (recv_return, ('b',), None), 32),144 (31, (recv_return, ('bb',), None), 17),145 (31, (recv_return, ('b',), None), 33),146 (32, (send_call, ('a',), None), 34),147 (32, (send_call, ('bb',), None), 35),148 (33, (send_call, ('a',), None), 36),149 (33, (send_call, ('bb',), None), 37),150 (34, (send_return, (1,), None), 38),151 (35, (send_return, (2,), None), 39),152 (35, (send_return, (1,), None), 40),153 (36, (send_return, (1,), None), 41),154 (37, (send_return, (2,), None), 42),155 (37, (send_return, (1,), None), 26),156 (38, (recv_call, (4,), None), 43),157 (39, (recv_call, (4,), None), 44),158 (40, (recv_call, (4,), None), 45),159 (41, (recv_call, (4,), None), 46),160 (42, (recv_call, (4,), None), 47),161 (43, (recv_return, ('ba',), None), 16),162 (43, (recv_return, ('b',), None), 48),163 (44, (recv_return, ('ba',), None), 17),164 (44, (recv_return, ('b',), None), 49),165 (45, (recv_return, ('ba',), None), 9),166 (45, (recv_return, ('b',), None), 50),167 (46, (recv_return, ('bb',), None), 32),168 (46, (recv_return, ('b',), None), 51),169 (47, (recv_return, ('bb',), None), 33),170 (47, (recv_return, ('b',), None), 52),171 (48, (send_call, ('a',), None), 53),172 (48, (send_call, ('bb',), None), 54),173 (49, (send_call, ('a',), None), 55),174 (49, (send_call, ('bb',), None), 56),175 (50, (send_call, ('a',), None), 57),176 (50, (send_call, ('bb',), None), 58),177 (51, (send_call, ('a',), None), 59),178 (51, (send_call, ('bb',), None), 60),179 (52, (send_call, ('a',), None), 61),180 (52, (send_call, ('bb',), None), 62),181 (53, (send_return, (1,), None), 63),182 (54, (send_return, (2,), None), 64),183 (54, (send_return, (1,), None), 65),184 (55, (send_return, (1,), None), 66),185 (56, (send_return, (2,), None), 67),186 (56, (send_return, (1,), None), 68),187 (57, (send_return, (1,), None), 69),188 (58, (send_return, (2,), None), 68),189 (58, (send_return, (1,), None), 23),190 (59, (send_return, (1,), None), 70),191 (60, (send_return, (2,), None), 71),192 (60, (send_return, (1,), None), 72),193 (61, (send_return, (1,), None), 73),194 (62, (send_return, (2,), None), 74),195 (62, (send_return, (1,), None), 42),196 (63, (recv_call, (4,), None), 75),197 (64, (recv_call, (4,), None), 76),...

Full Screen

Full Screen

msocketFSM.py

Source:msocketFSM.py Github

copy

Full Screen

1# pma.py --maxTransitions 100 msocket2# 59 states, 100 transitions, 1 accepting states, 0 unsafe states, 0 finished and 0 deadend states3# actions here are just labels, but must be symbols with __name__ attribute4def send_call(): pass5def send_return(): pass6def recv_call(): pass7def recv_return(): pass8# states, key of each state here is its number in graph etc. below9states = {10 0 : {'msocket': {'send_arg': '', 'recv_arg': 0, 'buffers': ''}},11 1 : {'msocket': {'send_arg': 'a', 'recv_arg': 0, 'buffers': ''}},12 2 : {'msocket': {'send_arg': '', 'recv_arg': 4, 'buffers': ''}},13 3 : {'msocket': {'send_arg': 'bb', 'recv_arg': 0, 'buffers': ''}},14 4 : {'msocket': {'send_arg': 'a', 'recv_arg': 4, 'buffers': ''}},15 5 : {'msocket': {'send_arg': '', 'recv_arg': 0, 'buffers': 'a'}},16 6 : {'msocket': {'send_arg': 'bb', 'recv_arg': 4, 'buffers': ''}},17 7 : {'msocket': {'send_arg': '', 'recv_arg': 0, 'buffers': 'b'}},18 8 : {'msocket': {'send_arg': '', 'recv_arg': 0, 'buffers': 'bb'}},19 9 : {'msocket': {'send_arg': '', 'recv_arg': 4, 'buffers': 'a'}},20 10 : {'msocket': {'send_arg': 'a', 'recv_arg': 0, 'buffers': 'a'}},21 11 : {'msocket': {'send_arg': 'bb', 'recv_arg': 0, 'buffers': 'a'}},22 12 : {'msocket': {'send_arg': '', 'recv_arg': 4, 'buffers': 'bb'}},23 13 : {'msocket': {'send_arg': '', 'recv_arg': 4, 'buffers': 'b'}},24 14 : {'msocket': {'send_arg': 'a', 'recv_arg': 0, 'buffers': 'b'}},25 15 : {'msocket': {'send_arg': 'bb', 'recv_arg': 0, 'buffers': 'b'}},26 16 : {'msocket': {'send_arg': 'a', 'recv_arg': 0, 'buffers': 'bb'}},27 17 : {'msocket': {'send_arg': 'bb', 'recv_arg': 0, 'buffers': 'bb'}},28 18 : {'msocket': {'send_arg': 'a', 'recv_arg': 4, 'buffers': 'a'}},29 19 : {'msocket': {'send_arg': 'bb', 'recv_arg': 4, 'buffers': 'a'}},30 20 : {'msocket': {'send_arg': '', 'recv_arg': 0, 'buffers': 'aa'}},31 21 : {'msocket': {'send_arg': '', 'recv_arg': 0, 'buffers': 'ab'}},32 22 : {'msocket': {'send_arg': '', 'recv_arg': 0, 'buffers': 'abb'}},33 23 : {'msocket': {'send_arg': 'a', 'recv_arg': 4, 'buffers': 'bb'}},34 24 : {'msocket': {'send_arg': 'bb', 'recv_arg': 4, 'buffers': 'bb'}},35 25 : {'msocket': {'send_arg': 'a', 'recv_arg': 4, 'buffers': 'b'}},36 26 : {'msocket': {'send_arg': 'bb', 'recv_arg': 4, 'buffers': 'b'}},37 27 : {'msocket': {'send_arg': '', 'recv_arg': 0, 'buffers': 'ba'}},38 28 : {'msocket': {'send_arg': '', 'recv_arg': 0, 'buffers': 'bbb'}},39 29 : {'msocket': {'send_arg': '', 'recv_arg': 0, 'buffers': 'bba'}},40 30 : {'msocket': {'send_arg': '', 'recv_arg': 0, 'buffers': 'bbbb'}},41 31 : {'msocket': {'send_arg': '', 'recv_arg': 4, 'buffers': 'aa'}},42 32 : {'msocket': {'send_arg': '', 'recv_arg': 4, 'buffers': 'ab'}},43 33 : {'msocket': {'send_arg': '', 'recv_arg': 4, 'buffers': 'abb'}},44 34 : {'msocket': {'send_arg': 'a', 'recv_arg': 0, 'buffers': 'aa'}},45 35 : {'msocket': {'send_arg': 'bb', 'recv_arg': 0, 'buffers': 'aa'}},46 36 : {'msocket': {'send_arg': 'a', 'recv_arg': 0, 'buffers': 'ab'}},47 37 : {'msocket': {'send_arg': 'bb', 'recv_arg': 0, 'buffers': 'ab'}},48 38 : {'msocket': {'send_arg': 'a', 'recv_arg': 0, 'buffers': 'abb'}},49 39 : {'msocket': {'send_arg': 'bb', 'recv_arg': 0, 'buffers': 'abb'}},50 40 : {'msocket': {'send_arg': '', 'recv_arg': 4, 'buffers': 'bba'}},51 41 : {'msocket': {'send_arg': '', 'recv_arg': 4, 'buffers': 'bbbb'}},52 42 : {'msocket': {'send_arg': '', 'recv_arg': 4, 'buffers': 'bbb'}},53 43 : {'msocket': {'send_arg': '', 'recv_arg': 4, 'buffers': 'ba'}},54 44 : {'msocket': {'send_arg': 'a', 'recv_arg': 0, 'buffers': 'ba'}},55 45 : {'msocket': {'send_arg': 'bb', 'recv_arg': 0, 'buffers': 'ba'}},56 46 : {'msocket': {'send_arg': 'a', 'recv_arg': 0, 'buffers': 'bbb'}},57 47 : {'msocket': {'send_arg': 'bb', 'recv_arg': 0, 'buffers': 'bbb'}},58 48 : {'msocket': {'send_arg': 'a', 'recv_arg': 0, 'buffers': 'bba'}},59 49 : {'msocket': {'send_arg': 'bb', 'recv_arg': 0, 'buffers': 'bba'}},60 50 : {'msocket': {'send_arg': 'a', 'recv_arg': 0, 'buffers': 'bbbb'}},61 51 : {'msocket': {'send_arg': 'bb', 'recv_arg': 0, 'buffers': 'bbbb'}},62 52 : {'msocket': {'send_arg': 'a', 'recv_arg': 4, 'buffers': 'aa'}},63 53 : {'msocket': {'send_arg': 'bb', 'recv_arg': 4, 'buffers': 'aa'}},64 54 : {'msocket': {'send_arg': 'a', 'recv_arg': 4, 'buffers': 'ab'}},65 55 : {'msocket': {'send_arg': 'bb', 'recv_arg': 4, 'buffers': 'ab'}},66 56 : {'msocket': {'send_arg': 'a', 'recv_arg': 4, 'buffers': 'abb'}},67 57 : {'msocket': {'send_arg': 'bb', 'recv_arg': 4, 'buffers': 'abb'}},68 58 : {'msocket': {'send_arg': '', 'recv_arg': 0, 'buffers': 'aaa'}},69}70# initial state, accepting states, unsafe states, frontier states, deadend states71initial = 072accepting = [0]73unsafe = []74frontier = [35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58]75finished = []76deadend = []77runstarts = [0]78# finite state machine, list of tuples: (current, (action, args, result), next)79graph = (80 (0, (send_call, ('a',), None), 1),81 (0, (recv_call, (4,), None), 2),82 (0, (send_call, ('bb',), None), 3),83 (1, (recv_call, (4,), None), 4),84 (1, (send_return, (1,), None), 5),85 (2, (send_call, ('a',), None), 4),86 (2, (send_call, ('bb',), None), 6),87 (3, (recv_call, (4,), None), 6),88 (3, (send_return, (1,), None), 7),89 (3, (send_return, (2,), None), 8),90 (4, (send_return, (1,), None), 9),91 (5, (send_call, ('a',), None), 10),92 (5, (recv_call, (4,), None), 9),93 (5, (send_call, ('bb',), None), 11),94 (6, (send_return, (2,), None), 12),95 (6, (send_return, (1,), None), 13),96 (7, (send_call, ('a',), None), 14),97 (7, (recv_call, (4,), None), 13),98 (7, (send_call, ('bb',), None), 15),99 (8, (send_call, ('a',), None), 16),100 (8, (recv_call, (4,), None), 12),101 (8, (send_call, ('bb',), None), 17),102 (9, (send_call, ('a',), None), 18),103 (9, (recv_return, ('a',), None), 0),104 (9, (send_call, ('bb',), None), 19),105 (10, (recv_call, (4,), None), 18),106 (10, (send_return, (1,), None), 20),107 (11, (recv_call, (4,), None), 19),108 (11, (send_return, (1,), None), 21),109 (11, (send_return, (2,), None), 22),110 (12, (send_call, ('a',), None), 23),111 (12, (recv_return, ('bb',), None), 0),112 (12, (recv_return, ('b',), None), 7),113 (12, (send_call, ('bb',), None), 24),114 (13, (send_call, ('a',), None), 25),115 (13, (recv_return, ('b',), None), 0),116 (13, (send_call, ('bb',), None), 26),117 (14, (recv_call, (4,), None), 25),118 (14, (send_return, (1,), None), 27),119 (15, (recv_call, (4,), None), 26),120 (15, (send_return, (1,), None), 8),121 (15, (send_return, (2,), None), 28),122 (16, (recv_call, (4,), None), 23),123 (16, (send_return, (1,), None), 29),124 (17, (recv_call, (4,), None), 24),125 (17, (send_return, (1,), None), 28),126 (17, (send_return, (2,), None), 30),127 (18, (recv_return, ('a',), None), 1),128 (18, (send_return, (1,), None), 31),129 (19, (recv_return, ('a',), None), 3),130 (19, (send_return, (1,), None), 32),131 (19, (send_return, (2,), None), 33),132 (20, (send_call, ('a',), None), 34),133 (20, (recv_call, (4,), None), 31),134 (20, (send_call, ('bb',), None), 35),135 (21, (send_call, ('a',), None), 36),136 (21, (recv_call, (4,), None), 32),137 (21, (send_call, ('bb',), None), 37),138 (22, (send_call, ('a',), None), 38),139 (22, (recv_call, (4,), None), 33),140 (22, (send_call, ('bb',), None), 39),141 (23, (recv_return, ('bb',), None), 1),142 (23, (recv_return, ('b',), None), 14),143 (23, (send_return, (1,), None), 40),144 (24, (send_return, (2,), None), 41),145 (24, (recv_return, ('bb',), None), 3),146 (24, (recv_return, ('b',), None), 15),147 (24, (send_return, (1,), None), 42),148 (25, (recv_return, ('b',), None), 1),149 (25, (send_return, (1,), None), 43),150 (26, (send_return, (2,), None), 42),151 (26, (recv_return, ('b',), None), 3),152 (26, (send_return, (1,), None), 12),153 (27, (send_call, ('a',), None), 44),154 (27, (recv_call, (4,), None), 43),155 (27, (send_call, ('bb',), None), 45),156 (28, (send_call, ('a',), None), 46),157 (28, (recv_call, (4,), None), 42),158 (28, (send_call, ('bb',), None), 47),159 (29, (send_call, ('a',), None), 48),160 (29, (recv_call, (4,), None), 40),161 (29, (send_call, ('bb',), None), 49),162 (30, (send_call, ('a',), None), 50),163 (30, (recv_call, (4,), None), 41),164 (30, (send_call, ('bb',), None), 51),165 (31, (send_call, ('a',), None), 52),166 (31, (recv_return, ('a',), None), 5),167 (31, (recv_return, ('aa',), None), 0),168 (31, (send_call, ('bb',), None), 53),169 (32, (send_call, ('a',), None), 54),170 (32, (recv_return, ('a',), None), 7),171 (32, (recv_return, ('ab',), None), 0),172 (32, (send_call, ('bb',), None), 55),173 (33, (send_call, ('a',), None), 56),174 (33, (recv_return, ('a',), None), 8),175 (33, (recv_return, ('ab',), None), 7),176 (33, (send_call, ('bb',), None), 57),177 (34, (recv_call, (4,), None), 52),178 (34, (send_return, (1,), None), 58),179 (35, (recv_call, (4,), None), 53),...

Full Screen

Full Screen

SMTPClient.py

Source:SMTPClient.py Github

copy

Full Screen

...20# Create socket called clientSocket and establish a TCP connection with mail server21clientSocket = socket(AF_INET, SOCK_STREAM)22clientSocket.connect(mailserver)23#Get response and print24recv = clientSocket.recv(1024).decode()25print(recv)26if recv[:3] != '220':27 print('220 reply not received from server.')28# Send HELO command and print server response.29heloCommand = 'HELO Alice\r\n'30clientSocket.send(heloCommand.encode())31recv1 = clientSocket.recv(1024).decode()32print(recv1)33if recv1[:3] != '250':34 print('250 reply not received from server.')35#Send STARTTLS command36command = 'STARTTLS\r\n'37clientSocket.send(command.encode())38#Get response and print39recv = clientSocket.recv(1024).decode()40print(recv)41if recv[:3] != '220':42 print('220 reply not received from server.')43#Wrap socket for security44Socket = ssl.wrap_socket(clientSocket)45#Send Auth Login command46Socket.sendall('AUTH LOGIN\r\n'.encode())47recv = Socket.recv(1024).decode()48print(recv)49if (recv[:3] != '334'):50 print('334 reply not received from server')51#Send username52Socket.sendall((username + '\r\n').encode())53recv = Socket.recv(1024).decode()54print(recv)55if (recv[:3] != '334'):56 print('334 reply not received from server')57#Send password58Socket.sendall((password + '\r\n').encode())59recv = Socket.recv(1024).decode()60print(recv)61if (recv[:3] != '235'):62 print('235 reply not received from server')63# Send Mail From command and print server response.64Socket.sendall(('MAIL FROM: <' + mailFrom + '>\r\n').encode())65recv = Socket.recv(1024).decode()66print(recv)67if (recv[:3] != '250'):68 print('250 reply not received from server')69# Send Rcpt To command and print server response.70Socket.sendall(('RCPT TO: <' + rcptTo + '>\r\n').encode())71recv = Socket.recv(1024).decode()72print(recv)73if (recv[:3] != '250'):74 print('250 reply not received from server')75# Send DATA command and print server response.76Socket.send('DATA\r\n'.encode())77recv = Socket.recv(1024).decode()78print(recv)79if (recv[:3] != '354'):80 print('354 reply not received from server')81# Send message data.82message = 'Mail from:' + mailFrom + '\r\n'83message += 'Recipient To:' + rcptTo + '\r\n'84message += 'Subject:' + subject + '\r\n'85message += 'Text type:' + textT + '\t\n'86message += '\r\n' + msg87Socket.sendall(message.encode())88# Message ends with a single period.89Socket.sendall(endmsg.encode())90recv = Socket.recv(1024).decode()91print(recv)92if (recv[:3] != '250'):93 print('250 reply not received from server')94# Send QUIT command and get server response.95Socket.sendall('QUIT\r\n'.encode())96# Close connection...

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 Airtest 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