當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。