Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_deliver(self):
result = AsyncResult()
env = Envelope('sender@example.com', ['rcpt@example.com'])
env.parse(b'From: sender@example.com\r\n\r\ntest test \x81\r\n')
self.sock.sendall(b'EHLO there\r\n')
self.sock.recv(IsA(int)).AndReturn(b'250-Hello\r\n250 8BITMIME\r\n')
self.sock.sendall(b'MAIL FROM:\r\n')
self.sock.recv(IsA(int)).AndReturn(b'250 Ok\r\n')
self.sock.sendall(b'RCPT TO:\r\n')
self.sock.recv(IsA(int)).AndReturn(b'250 Ok\r\n')
self.sock.sendall(b'DATA\r\n')
self.sock.recv(IsA(int)).AndReturn(b'354 Go ahead\r\n')
self.sock.sendall(b'From: sender@example.com\r\n\r\ntest test \x81\r\n.\r\n')
self.sock.recv(IsA(int)).AndReturn(b'250 Ok\r\n')
self.mox.ReplayAll()
client = SmtpRelayClient(('addr', 0), self.queue, socket_creator=self._socket_creator, ehlo_as='there')
client._connect()
client._ehlo()
def test_zero_max_size(self):
q = queue.Channel()
def sender(evt, q):
q.put('hi')
evt.set('done')
def receiver(evt, q):
x = q.get()
evt.set(x)
e1 = AsyncResult()
e2 = AsyncResult()
p1 = gevent.spawn(sender, e1, q)
gevent.sleep(0.001)
self.assertTrue(not e1.ready())
p2 = gevent.spawn(receiver, e2, q)
self.assertEqual(e2.get(), 'hi')
self.assertEqual(e1.get(), 'done')
with gevent.Timeout(0):
gevent.joinall([p1, p2])
def _await_ack(self, identifier, timeout=5):
"""
Wait for acknowledgement of message
Args:
identifier (str): Identifier of ack
timeout (int): Timeout in seconds
Returns:
:obj:`.Event`: Event
"""
evnt = gevent.event.AsyncResult()
self._pending[identifier] = evnt
return evnt.wait(timeout)
def __init__(self, request):
# requests and responses
self.ioRequest = request
self.ioResult = AsyncResult()
def playback(self, path, block=True):
if not block:
self.call_command('playback', path)
return
async_response = gevent.event.AsyncResult()
expected_event = "CHANNEL_EXECUTE_COMPLETE"
expected_variable = "current_application"
expected_variable_value = "playback"
self.register_expected_event(expected_event, expected_variable,
expected_variable_value, async_response)
self.call_command('playback', path)
event = async_response.get(block=True)
# TODO(italo): Decide what we need to return. Returning whole event right now
return event
def _protocol_send(self, command, args=""):
if self._closing_state:
return Event()
self.trace("_protocol_send %s %s" % (command, args))
# Append command to pool
# and send it to eventsocket
_cmd_uuid = str(uuid1())
_async_res = gevent.event.AsyncResult()
with self._lock:
self._commands_pool.append((_cmd_uuid, _async_res))
self._send("%s %s" % (command, args))
self.trace("_protocol_send %s wait ..." % command)
_uuid, event = _async_res.get()
if _cmd_uuid != _uuid:
raise InternalSyncError("in _protocol_send")
# Casts Event to appropriate event type :
# Casts to ApiResponse, if event is api
if command == 'api':
event = ApiResponse.cast(event)
# Casts to BgapiResponse, if event is bgapi
elif command == "bgapi":
event = BgapiResponse.cast(event)
# Casts to CommandResponse by default
else:
def _handle_error(self, message):
result = self._outstanding.pop(bytes(message.id), None)
if isinstance(result, AsyncResult):
result.set_exception(
VIPError.from_errno(*[bytes(arg) for arg in message.args]))
elif result:
args = [bytes(arg) for arg in message.args]
for result in result:
result.set_exception(VIPError.from_errno(*args))
def addTask(inner_path):
evt = gevent.event.AsyncResult()
gevent.spawn_later(1, lambda: evt.set(True))
return evt
def siteDownload(self, address):
from Site import Site
from Site import SiteManager
SiteManager.site_manager.load()
logging.info("Opening a simple connection server")
global file_server
from File import FileServer
file_server = FileServer("127.0.0.1", 1234)
file_server_thread = gevent.spawn(file_server.start, check_sites=False)
site = Site(address)
on_completed = gevent.event.AsyncResult()
def onComplete(evt):
evt.set(True)
site.onComplete.once(lambda: onComplete(on_completed))
print "Announcing..."
site.announce()
s = time.time()
print "Downloading..."
site.downloadContent("content.json", check_modifications=True)
print "Downloaded in %.3fs" % (time.time()-s)
def start(self) -> None:
log.debug("Alarm task started", node=to_checksum_address(self.rpc_client.address))
self._stop_event = AsyncResult()
super().start()