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


Python controller.Controller类代码示例

本文整理汇总了Python中aiosmtpd.controller.Controller的典型用法代码示例。如果您正苦于以下问题:Python Controller类的具体用法?Python Controller怎么用?Python Controller使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: test_real_mail_aiosmtpd

    def test_real_mail_aiosmtpd(self):
        """ Test sending messages with a real-world SMTPD server """
        if aiosmtpd is None:
            self.skipTest('aiosmtpd not available')

        # Start an smtp server
        mail_handler = StashingHandler()
        controller = Controller(mail_handler, loop=None,
                                hostname='localhost', port=self.smtpd_port)
        controller.start()

        # Give it time to settle
        sleep(0.5)

        # Initialize a Postman
        postman = Postman('[email protected]',
                          NoLoginSMTP('localhost', self.smtpd_port, None, None))

        # Send messages
        with postman.connect() as c:
            # Send plaintext message
            msg = Message(['[email protected]'], 'Subject', 'HTML message')
            c.sendmail(msg)

            # Send unicode message
            msg = Message(['[email protected]'], u'Håkon', u'Håkon')
            c.sendmail(msg)

        # Done
        controller.stop()

        # Test
        self.assertEqual(len(mail_handler.mail), 2)
开发者ID:kolypto,项目名称:py-mailem,代码行数:33,代码来源:smtp-test.py

示例2: setUp

 def setUp(self):
     self.stream = StringIO()
     handler = Debugging(self.stream)
     controller = Controller(handler)
     controller.start()
     self.addCleanup(controller.stop)
     self.address = (controller.hostname, controller.port)
开发者ID:kozzztik,项目名称:aiosmtpd,代码行数:7,代码来源:test_handlers.py

示例3: test_mail_with_compatible_smtputf8

 def test_mail_with_compatible_smtputf8(self):
     handler = ReceivingHandler()
     controller = Controller(handler)
     controller.start()
     self.addCleanup(controller.stop)
     recipient = 'bart\[email protected]'
     sender = 'anne\[email protected]'
     with SMTP(controller.hostname, controller.port) as client:
         client.ehlo('example.com')
         client.send(bytes(
             'MAIL FROM: <' + sender + '> SMTPUTF8\r\n',
             encoding='utf-8'))
         code, response = client.getreply()
         self.assertEqual(code, 250)
         self.assertEqual(response, b'OK')
         client.send(bytes(
             'RCPT TO: <' + recipient + '>\r\n',
             encoding='utf-8'))
         code, response = client.getreply()
         self.assertEqual(code, 250)
         self.assertEqual(response, b'OK')
         code, response = client.data('')
         self.assertEqual(code, 250)
         self.assertEqual(response, b'OK')
     self.assertEqual(handler.box[0].rcpt_tos[0], recipient)
     self.assertEqual(handler.box[0].mail_from, sender)
开发者ID:kozzztik,项目名称:aiosmtpd,代码行数:26,代码来源:test_smtp.py

示例4: test_helo_hook

 def test_helo_hook(self):
     controller = Controller(HELOHandler())
     controller.start()
     self.addCleanup(controller.stop)
     with SMTP(controller.hostname, controller.port) as client:
         code, response = client.helo('me')
     self.assertEqual(code, 250)
     self.assertEqual(response, b'geddy.example.com')
开发者ID:kozzztik,项目名称:aiosmtpd,代码行数:8,代码来源:test_handlers.py

示例5: test_smtp_utf8

 def test_smtp_utf8(self):
     controller = Controller(Sink())
     controller.start()
     self.addCleanup(controller.stop)
     with SMTP(controller.hostname, controller.port) as client:
         code, response = client.ehlo('example.com')
     self.assertEqual(code, 250)
     self.assertIn(b'SMTPUTF8', response.splitlines())
开发者ID:aio-libs,项目名称:aiosmtpd,代码行数:8,代码来源:test_server.py

示例6: test_socket_error

 def test_socket_error(self):
     # Testing starting a server with a port already in use
     s1 = Controller(Sink(), port=8025)
     s2 = Controller(Sink(), port=8025)
     self.addCleanup(s1.stop)
     self.addCleanup(s2.stop)
     s1.start()
     self.assertRaises(socket.error, s2.start)
开发者ID:aio-libs,项目名称:aiosmtpd,代码行数:8,代码来源:test_server.py

示例7: test_mail_hook

 def test_mail_hook(self):
     controller = Controller(MAILHandler())
     controller.start()
     self.addCleanup(controller.stop)
     with SMTP(controller.hostname, controller.port) as client:
         client.helo('me')
         code, response = client.mail('[email protected]')
     self.assertEqual(code, 250)
     self.assertEqual(response, b'Yeah, sure')
开发者ID:kozzztik,项目名称:aiosmtpd,代码行数:9,代码来源:test_handlers.py

示例8: test_default_greeting

 def test_default_greeting(self):
     controller = Controller(Sink())
     controller.start()
     self.addCleanup(controller.stop)
     with SMTP() as client:
         code, msg = client.connect(controller.hostname, controller.port)
         self.assertEqual(code, 220)
         # The hostname prefix is unpredictable.
         self.assertEqual(msg[-len(GREETING):], bytes(GREETING, 'utf-8'))
开发者ID:kozzztik,项目名称:aiosmtpd,代码行数:9,代码来源:test_smtp.py

示例9: test_server_attribute

 def test_server_attribute(self):
     controller = Controller(Sink())
     self.assertIsNone(controller.server)
     try:
         controller.start()
         self.assertIsNotNone(controller.server)
     finally:
         controller.stop()
         self.assertIsNone(controller.server)
开发者ID:aio-libs,项目名称:aiosmtpd,代码行数:9,代码来源:test_server.py

示例10: test_mail_with_unrequited_smtputf8

 def test_mail_with_unrequited_smtputf8(self):
     controller = Controller(Sink())
     controller.start()
     self.addCleanup(controller.stop)
     with SMTP(controller.hostname, controller.port) as client:
         client.ehlo('example.com')
         code, response = client.docmd('MAIL FROM: <[email protected]>')
         self.assertEqual(code, 250)
         self.assertEqual(response, b'OK')
开发者ID:kozzztik,项目名称:aiosmtpd,代码行数:9,代码来源:test_smtp.py

示例11: test_ehlo_hook

 def test_ehlo_hook(self):
     controller = Controller(EHLOHandler())
     controller.start()
     self.addCleanup(controller.stop)
     with SMTP(controller.hostname, controller.port) as client:
         code, response = client.ehlo('me')
     self.assertEqual(code, 250)
     lines = response.decode('utf-8').splitlines()
     self.assertEqual(lines[-1], 'alex.example.com')
开发者ID:kozzztik,项目名称:aiosmtpd,代码行数:9,代码来源:test_handlers.py

示例12: test_mail_with_incompatible_smtputf8

 def test_mail_with_incompatible_smtputf8(self):
     controller = Controller(Sink())
     controller.start()
     self.addCleanup(controller.stop)
     with SMTP(controller.hostname, controller.port) as client:
         client.ehlo('example.com')
         code, response = client.docmd(
             'MAIL FROM: <[email protected]> SMTPUTF8=YES')
         self.assertEqual(code, 501)
         self.assertEqual(response, b'Error: SMTPUTF8 takes no arguments')
开发者ID:kozzztik,项目名称:aiosmtpd,代码行数:10,代码来源:test_smtp.py

示例13: test_mail_invalid_body

 def test_mail_invalid_body(self):
     controller = Controller(Sink())
     controller.start()
     self.addCleanup(controller.stop)
     with SMTP(controller.hostname, controller.port) as client:
         client.ehlo('example.com')
         code, response = client.docmd(
             'MAIL FROM: <[email protected]> BODY 9BIT')
         self.assertEqual(code, 501)
         self.assertEqual(response,
                          b'Error: BODY can only be one of 7BIT, 8BITMIME')
开发者ID:kozzztik,项目名称:aiosmtpd,代码行数:11,代码来源:test_smtp.py

示例14: test_deliver_bytes

 def test_deliver_bytes(self):
     with ExitStack() as resources:
         controller = Controller(self.proxy, port=9024)
         controller.start()
         resources.callback(controller.stop)
         client = resources.enter_context(
             SMTP(*(controller.hostname, controller.port)))
         client.sendmail(
             '[email protected]', ['[email protected]'], self.source)
         client.quit()
     self.assertEqual(self.upstream.content, self.expected)
     self.assertEqual(self.upstream.original_content, self.expected)
开发者ID:kozzztik,项目名称:aiosmtpd,代码行数:12,代码来源:test_handlers.py

示例15: test_data_hook

    def test_data_hook(self):
        controller = Controller(DATAHandler())
        controller.start()
        self.addCleanup(controller.stop)
        with SMTP(controller.hostname, controller.port) as client:
            with self.assertRaises(SMTPDataError) as cm:
                client.sendmail('[email protected]', ['[email protected]'], """\
From: [email protected]
To: [email protected]
Subject: Test

Yikes
""")
            self.assertEqual(cm.exception.smtp_code, 599)
            self.assertEqual(cm.exception.smtp_error, b'Not today')
开发者ID:kozzztik,项目名称:aiosmtpd,代码行数:15,代码来源:test_handlers.py


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