本文整理汇总了Python中slimta.smtp.io.IO类的典型用法代码示例。如果您正苦于以下问题:Python IO类的具体用法?Python IO怎么用?Python IO使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IO类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_recv_utf8
def test_recv_utf8(self):
self.sock.recv(IsA(int)).AndReturn(b'250 \xc3\xbf\r\n')
self.mox.ReplayAll()
io = IO(self.sock)
code, message = io.recv_reply()
self.assertEqual('250', code)
self.assertEqual(u'\xff', message)
示例2: test_recv_command_arg
def test_recv_command_arg(self):
self.sock.recv(IsA(int)).AndReturn(b'cmd arg \r\n')
self.mox.ReplayAll()
io = IO(self.sock)
command, arg = io.recv_command()
self.assertEqual(b'CMD', command)
self.assertEqual(b'arg', arg)
示例3: test_recv_command_nonutf8
def test_recv_command_nonutf8(self):
self.sock.recv(IsA(int)).AndReturn(b'cmd\xffr\n')
self.mox.ReplayAll()
io = IO(self.sock)
command, arg = io.recv_command()
self.assertEqual(None, command)
self.assertEqual(None, arg)
示例4: test_recv_reply_multiline
def test_recv_reply_multiline(self):
self.sock.recv(IsA(int)).AndReturn(b'250-One\r\n250 Two\r\n')
self.mox.ReplayAll()
io = IO(self.sock)
code, message = io.recv_reply()
self.assertEqual('250', code)
self.assertEqual('One\r\nTwo', message)
示例5: test_recv_command
def test_recv_command(self):
self.sock.recv(IsA(int)).AndReturn('CMD\r\n')
self.mox.ReplayAll()
io = IO(self.sock)
command, arg = io.recv_command()
assert_equal('CMD', command)
assert_equal(None, arg)
示例6: test_recv_reply
def test_recv_reply(self):
self.sock.recv(IsA(int)).AndReturn(b'250 Ok\r\n')
self.mox.ReplayAll()
io = IO(self.sock)
code, message = io.recv_reply()
self.assertEqual('250', code)
self.assertEqual('Ok', message)
示例7: test_recv_reply_multipart
def test_recv_reply_multipart(self):
self.sock.recv(IsA(int)).AndReturn('250 ')
self.sock.recv(IsA(int)).AndReturn('Ok\r\n')
self.mox.ReplayAll()
io = IO(self.sock)
code, message = io.recv_reply()
assert_equal('250', code)
assert_equal('Ok', message)
示例8: test_recv
def test_recv(self):
self.sock.recv(IsA(int)).AndReturn("\r\nthree\r\n")
self.sock.recv(IsA(int)).AndReturn(".\r\nstuff\r\n")
self.mox.ReplayAll()
io = IO(self.sock)
io.recv_buffer = "one\r\ntwo"
dr = DataReader(io)
self.assertEqual("one\r\ntwo\r\nthree\r\n", dr.recv())
示例9: test_recv_line
def test_recv_line(self):
self.sock.recv(IsA(int)).AndReturn(b'one')
self.sock.recv(IsA(int)).AndReturn(b'\r\ntwo')
self.mox.ReplayAll()
io = IO(self.sock)
line = io.recv_line()
self.assertEqual(b'one', line)
self.assertEqual(b'two', io.recv_buffer)
示例10: test_recv
def test_recv(self):
self.sock.recv(IsA(int)).AndReturn(b'\r\nthree\r\n')
self.sock.recv(IsA(int)).AndReturn(b'.\r\nstuff\r\n')
self.mox.ReplayAll()
io = IO(self.sock)
io.recv_buffer = b'one\r\ntwo'
dr = DataReader(io)
self.assertEqual(b'one\r\ntwo\r\nthree\r\n', dr.recv())
示例11: __init__
def __init__(self, socket, handlers, auth_class=None,
tls=None, tls_immediately=False, tls_wrapper=None,
command_timeout=None, data_timeout=None):
self.handlers = handlers
self.extensions = Extensions()
self.have_mailfrom = None
self.have_rcptto = None
self.ehlo_as = None
self.auth_result = None
self.encrypted = False
self.extensions.add('8BITMIME')
self.extensions.add('PIPELINING')
self.extensions.add('ENHANCEDSTATUSCODES')
if tls and not tls_immediately:
self.extensions.add('STARTTLS')
if auth_class:
self.extensions.add('AUTH', auth_class(self))
self.io = IO(socket, tls_wrapper)
if tls:
self.tls = tls.copy()
self.tls.setdefault('server_side', True)
else:
self.tls = None
self.tls_immediately = tls_immediately
self.command_timeout = command_timeout
self.data_timeout = data_timeout or command_timeout
示例12: test_send_reply_multiline
def test_send_reply_multiline(self):
self.mox.ReplayAll()
io = IO(self.sock)
io.send_reply(Reply('100', 'One\r\nTwo'))
self.assertEqual(b'100-One\r\n100 Two\r\n', io.send_buffer.getvalue())
示例13: test_from_recv_buffer
def test_from_recv_buffer(self):
io = IO(None)
io.recv_buffer = "test\r\ndata"
dr = DataReader(io)
dr.from_recv_buffer()
self.assertEqual(["test\r\n", "data"], dr.lines)
示例14: Server
class Server(object):
"""Class that implements an SMTP server given a connected socket. This
object has an ``extensions`` attribute that is an |Extensions| object that
contains the SMTP extensions the server supports.
:param socket: Connected socket for the session.
:type socket: :class:`gevent.socket.socket`
:param handlers: Object with methods that will be called when
corresponding SMTP commands are received. These methods
can modify the |Reply| before the command response is sent.
:param auth_class: Optional |Auth| sub-class to enable authentication.
:param tls: Optional dictionary of TLS settings passed directly as
keyword arguments to :class:`gevent.ssl.SSLSocket`.
:param tls_immediately: If True, the socket will be encrypted
immediately.
:param tls_wrapper: Optional function that takes a socket and the ``tls``
dictionary, creates a new encrypted socket, performs
the TLS handshake, and returns it. The default uses
:class:`~gevent.ssl.SSLSocket`.
:type tls_immediately: True or False
:param command_timeout: Optional timeout waiting for a command to be
sent from the client.
:param data_timeout: Optional timeout waiting for data to be sent from
the client.
"""
def __init__(self, socket, handlers, auth_class=None,
tls=None, tls_immediately=False, tls_wrapper=None,
command_timeout=None, data_timeout=None):
self.handlers = handlers
self.extensions = Extensions()
self.have_mailfrom = None
self.have_rcptto = None
self.ehlo_as = None
self.auth_result = None
self.encrypted = False
self.extensions.add('8BITMIME')
self.extensions.add('PIPELINING')
self.extensions.add('ENHANCEDSTATUSCODES')
if tls and not tls_immediately:
self.extensions.add('STARTTLS')
if auth_class:
self.extensions.add('AUTH', auth_class(self))
self.io = IO(socket, tls_wrapper)
if tls:
self.tls = tls.copy()
self.tls.setdefault('server_side', True)
else:
self.tls = None
self.tls_immediately = tls_immediately
self.command_timeout = command_timeout
self.data_timeout = data_timeout or command_timeout
def _recv_command(self):
timeout = Timeout(self.command_timeout)
timeout.start()
try:
return self.io.recv_command()
finally:
timeout.cancel()
def _get_message_data(self):
max_size = self.extensions.getparam('SIZE', filter=int)
reader = DataReader(self.io, max_size)
err = None
timeout = Timeout(self.data_timeout)
timeout.start()
try:
data = reader.recv()
except ConnectionLost:
raise
except SmtpError, e:
data = None
err = e
finally:
示例15: test_send_reply
def test_send_reply(self):
self.mox.ReplayAll()
io = IO(self.sock)
io.send_reply(Reply('100', 'Ok'))
self.assertEqual(b'100 Ok\r\n', io.send_buffer.getvalue())