当前位置: 首页>>代码示例>>Python>>正文


Python smtpd.SMTPChannel方法代码示例

本文整理汇总了Python中smtpd.SMTPChannel方法的典型用法代码示例。如果您正苦于以下问题:Python smtpd.SMTPChannel方法的具体用法?Python smtpd.SMTPChannel怎么用?Python smtpd.SMTPChannel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在smtpd的用法示例。


在下文中一共展示了smtpd.SMTPChannel方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: import smtpd [as 别名]
# 或者: from smtpd import SMTPChannel [as 别名]
def __init__(self, localaddr, map, debug=False, esmtp=True):
        self._localaddr = localaddr
        self._remoteaddr = None
        self.__smtpchannel = _SMTPChannel if esmtp else smtpd.SMTPChannel
        self.__debug = debug
        self.__messages = []
        asyncore.dispatcher.__init__(self, map=map)
        try:
            self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
            # try to re-use a server port if possible
            self.set_reuse_addr()
            self.bind(localaddr)
            self.listen(5)
        except:
            # cleanup asyncore.socket_map before raising
            self.close()
            raise 
开发者ID:exasol,项目名称:script-languages,代码行数:19,代码来源:__init__.py

示例2: setUp

# 需要导入模块: import smtpd [as 别名]
# 或者: from smtpd import SMTPChannel [as 别名]
def setUp(self):
        self.real_getfqdn = socket.getfqdn
        socket.getfqdn = mock_socket.getfqdn
        # temporarily replace sys.stdout to capture DebuggingServer output
        self.old_stdout = sys.stdout
        self.output = io.StringIO()
        sys.stdout = self.output

        self.serv_evt = threading.Event()
        self.client_evt = threading.Event()
        # Capture SMTPChannel debug output
        self.old_DEBUGSTREAM = smtpd.DEBUGSTREAM
        smtpd.DEBUGSTREAM = io.StringIO()
        # Pick a random unused port by passing 0 for the port number
        self.serv = smtpd.DebuggingServer((HOST, 0), ('nowhere', -1),
                                          decode_data=True)
        # Keep a note of what port was assigned
        self.port = self.serv.socket.getsockname()[1]
        serv_args = (self.serv, self.serv_evt, self.client_evt)
        self.thread = threading.Thread(target=debugging_server, args=serv_args)
        self.thread.start()

        # wait until server thread has assigned a port number
        self.serv_evt.wait()
        self.serv_evt.clear() 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:27,代码来源:test_smtplib.py

示例3: test_process_message_with_decode_data_true

# 需要导入模块: import smtpd [as 别名]
# 或者: from smtpd import SMTPChannel [as 别名]
def test_process_message_with_decode_data_true(self):
        server = smtpd.DebuggingServer((support.HOST, 0), ('b', 0),
                                       decode_data=True)
        conn, addr = server.accept()
        channel = smtpd.SMTPChannel(server, conn, addr, decode_data=True)
        with support.captured_stdout() as s:
            self.send_data(channel, b'From: test\n\nhello\n')
        stdout = s.getvalue()
        self.assertEqual(stdout, textwrap.dedent("""\
             ---------- MESSAGE FOLLOWS ----------
             From: test
             X-Peer: peer-address

             hello
             ------------ END MESSAGE ------------
             """)) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:18,代码来源:test_smtpd.py

示例4: test_process_message_with_decode_data_false

# 需要导入模块: import smtpd [as 别名]
# 或者: from smtpd import SMTPChannel [as 别名]
def test_process_message_with_decode_data_false(self):
        server = smtpd.DebuggingServer((support.HOST, 0), ('b', 0),
                                       decode_data=False)
        conn, addr = server.accept()
        channel = smtpd.SMTPChannel(server, conn, addr, decode_data=False)
        with support.captured_stdout() as s:
            self.send_data(channel, b'From: test\n\nh\xc3\xa9llo\xff\n')
        stdout = s.getvalue()
        self.assertEqual(stdout, textwrap.dedent("""\
             ---------- MESSAGE FOLLOWS ----------
             b'From: test'
             b'X-Peer: peer-address'
             b''
             b'h\\xc3\\xa9llo\\xff'
             ------------ END MESSAGE ------------
             """)) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:18,代码来源:test_smtpd.py

示例5: test_process_SMTPUTF8_message_with_enable_SMTPUTF8_true

# 需要导入模块: import smtpd [as 别名]
# 或者: from smtpd import SMTPChannel [as 别名]
def test_process_SMTPUTF8_message_with_enable_SMTPUTF8_true(self):
        server = smtpd.DebuggingServer((support.HOST, 0), ('b', 0),
                                       enable_SMTPUTF8=True)
        conn, addr = server.accept()
        channel = smtpd.SMTPChannel(server, conn, addr, enable_SMTPUTF8=True)
        with support.captured_stdout() as s:
            self.send_data(channel, b'From: test\n\nh\xc3\xa9llo\xff\n',
                           enable_SMTPUTF8=True)
        stdout = s.getvalue()
        self.assertEqual(stdout, textwrap.dedent("""\
             ---------- MESSAGE FOLLOWS ----------
             mail options: ['BODY=8BITMIME', 'SMTPUTF8']
             b'From: test'
             b'X-Peer: peer-address'
             b''
             b'h\\xc3\\xa9llo\\xff'
             ------------ END MESSAGE ------------
             """)) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:20,代码来源:test_smtpd.py

示例6: test_with_decode_data_false

# 需要导入模块: import smtpd [as 别名]
# 或者: from smtpd import SMTPChannel [as 别名]
def test_with_decode_data_false(self):
        server = DummyServer((support.HOST, 0), ('b', 0), decode_data=False)
        conn, addr = server.accept()
        channel = smtpd.SMTPChannel(server, conn, addr, decode_data=False)
        self.write_line(channel, b'EHLO example')
        for line in [
            b'MAIL from: <foo@example.com> size=20 SMTPUTF8',
            b'MAIL from: <foo@example.com> size=20 SMTPUTF8 BODY=8BITMIME',
        ]:
            self.write_line(channel, line)
            self.assertEqual(channel.socket.last, self.error_response)
        self.write_line(
            channel,
            b'MAIL from: <foo@example.com> size=20 SMTPUTF8 BODY=UNKNOWN')
        self.assertEqual(
            channel.socket.last,
            b'501 Error: BODY can only be one of 7BIT, 8BITMIME\r\n')
        self.write_line(
            channel, b'MAIL from: <foo@example.com> size=20 body=8bitmime')
        self.assertEqual(channel.socket.last, b'250 OK\r\n') 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:22,代码来源:test_smtpd.py

示例7: setUp

# 需要导入模块: import smtpd [as 别名]
# 或者: from smtpd import SMTPChannel [as 别名]
def setUp(self):
        self.real_getfqdn = socket.getfqdn
        socket.getfqdn = mock_socket.getfqdn
        # temporarily replace sys.stdout to capture DebuggingServer output
        self.old_stdout = sys.stdout
        self.output = io.StringIO()
        sys.stdout = self.output

        self.serv_evt = threading.Event()
        self.client_evt = threading.Event()
        # Capture SMTPChannel debug output
        self.old_DEBUGSTREAM = smtpd.DEBUGSTREAM
        smtpd.DEBUGSTREAM = io.StringIO()
        # Pick a random unused port by passing 0 for the port number
        self.serv = smtpd.DebuggingServer((HOST, 0), ('nowhere', -1))
        # Keep a note of what port was assigned
        self.port = self.serv.socket.getsockname()[1]
        serv_args = (self.serv, self.serv_evt, self.client_evt)
        self.thread = threading.Thread(target=debugging_server, args=serv_args)
        self.thread.start()

        # wait until server thread has assigned a port number
        self.serv_evt.wait()
        self.serv_evt.clear() 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:26,代码来源:test_smtplib.py

示例8: setUp

# 需要导入模块: import smtpd [as 别名]
# 或者: from smtpd import SMTPChannel [as 别名]
def setUp(self):
        self.real_getfqdn = socket.getfqdn
        socket.getfqdn = mock_socket.getfqdn
        # temporarily replace sys.stdout to capture DebuggingServer output
        self.old_stdout = sys.stdout
        self.output = io.StringIO()
        sys.stdout = self.output

        self.serv_evt = threading.Event()
        self.client_evt = threading.Event()
        # Capture SMTPChannel debug output
        self.old_DEBUGSTREAM = smtpd.DEBUGSTREAM
        smtpd.DEBUGSTREAM = io.StringIO()
        # Pick a random unused port by passing 0 for the port number
        self.serv = smtpd.DebuggingServer((HOST, 0), ('nowhere', -1),
                                          decode_data=True)
        # Keep a note of what server host and port were assigned
        self.host, self.port = self.serv.socket.getsockname()[:2]
        serv_args = (self.serv, self.serv_evt, self.client_evt)
        self.thread = threading.Thread(target=debugging_server, args=serv_args)
        self.thread.start()

        # wait until server thread has assigned a port number
        self.serv_evt.wait()
        self.serv_evt.clear() 
开发者ID:bkerler,项目名称:android_universal,代码行数:27,代码来源:test_smtplib.py

示例9: test_with_decode_data_false

# 需要导入模块: import smtpd [as 别名]
# 或者: from smtpd import SMTPChannel [as 别名]
def test_with_decode_data_false(self):
        server = DummyServer((support.HOST, 0), ('b', 0))
        conn, addr = server.accept()
        channel = smtpd.SMTPChannel(server, conn, addr)
        self.write_line(channel, b'EHLO example')
        for line in [
            b'MAIL from: <foo@example.com> size=20 SMTPUTF8',
            b'MAIL from: <foo@example.com> size=20 SMTPUTF8 BODY=8BITMIME',
        ]:
            self.write_line(channel, line)
            self.assertEqual(channel.socket.last, self.error_response)
        self.write_line(
            channel,
            b'MAIL from: <foo@example.com> size=20 SMTPUTF8 BODY=UNKNOWN')
        self.assertEqual(
            channel.socket.last,
            b'501 Error: BODY can only be one of 7BIT, 8BITMIME\r\n')
        self.write_line(
            channel, b'MAIL from: <foo@example.com> size=20 body=8bitmime')
        self.assertEqual(channel.socket.last, b'250 OK\r\n') 
开发者ID:bkerler,项目名称:android_universal,代码行数:22,代码来源:test_smtpd.py

示例10: testSecondHELO

# 需要导入模块: import smtpd [as 别名]
# 或者: from smtpd import SMTPChannel [as 别名]
def testSecondHELO(self):
        # check that a second HELO returns a message that it's a duplicate
        # (this behavior is specific to smtpd.SMTPChannel)
        smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=15)
        smtp.helo()
        expected = (503, 'Duplicate HELO/EHLO')
        self.assertEqual(smtp.helo(), expected)
        smtp.quit() 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:10,代码来源:test_smtplib.py

示例11: __init__

# 需要导入模块: import smtpd [as 别名]
# 或者: from smtpd import SMTPChannel [as 别名]
def __init__(self, extra_features, *args, **kw):
        self._extrafeatures = ''.join(
            [ "250-{0}\r\n".format(x) for x in extra_features ])
        smtpd.SMTPChannel.__init__(self, *args, **kw) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:6,代码来源:test_smtplib.py

示例12: testSecondHELO

# 需要导入模块: import smtpd [as 别名]
# 或者: from smtpd import SMTPChannel [as 别名]
def testSecondHELO(self):
        # check that a second HELO returns a message that it's a duplicate
        # (this behavior is specific to smtpd.SMTPChannel)
        smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=3)
        smtp.helo()
        expected = (503, 'Duplicate HELO/EHLO')
        self.assertEqual(smtp.helo(), expected)
        smtp.quit() 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:10,代码来源:test_smtplib.py

示例13: __init__

# 需要导入模块: import smtpd [as 别名]
# 或者: from smtpd import SMTPChannel [as 别名]
def __init__(self, server, conn, addr):
        smtpd.SMTPChannel.__init__(self, server, conn, addr)
        self._server = server 
开发者ID:webkom,项目名称:lego,代码行数:5,代码来源:channel.py

示例14: smtp_LHLO

# 需要导入模块: import smtpd [as 别名]
# 或者: from smtpd import SMTPChannel [as 别名]
def smtp_LHLO(self, arg):
        smtpd.SMTPChannel.smtp_HELO(self, arg) 
开发者ID:webkom,项目名称:lego,代码行数:4,代码来源:channel.py

示例15: testSecondHELO

# 需要导入模块: import smtpd [as 别名]
# 或者: from smtpd import SMTPChannel [as 别名]
def testSecondHELO(self):
        # check that a second HELO returns a message that it's a duplicate
        # (this behavior is specific to smtpd.SMTPChannel)
        smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=3)
        smtp.helo()
        expected = (503, b'Duplicate HELO/EHLO')
        self.assertEqual(smtp.helo(), expected)
        smtp.quit() 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:10,代码来源:test_smtplib.py


注:本文中的smtpd.SMTPChannel方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。