def test_customChallengers(self):
        """
        L{imap4.IMAP4Server} accepts a L{dict} mapping challenge type
        names to L{twisted.mail.interfaces.IChallengeResponse}
        providers.
        """

        @implementer(IChallengeResponse, IUsernamePassword)
        class SPECIALAuth(object):

            def getChallenge(self):
                return b'SPECIAL'


            def setResponse(self, response):
                self.username, self.password = response.split(None, 1)


            def moreChallenges(self):
                return False


            def checkPassword(self, password):
                self.password = self.password

        special = SPECIALAuth()
        verifyObject(IChallengeResponse, special)

        server = imap4.IMAP4Server({b'SPECIAL': SPECIALAuth})
        server.portal = self.portal

        transport = StringTransport()
        server.makeConnection(transport)
        self.addCleanup(server.connectionLost,
                        error.ConnectionDone("Connection done."))

        self.assertIn(b"AUTH=SPECIAL", transport.value())

        transport.clear()
        server.dataReceived(b'001 AUTHENTICATE SPECIAL\r\n')

        self.assertIn(base64.b64encode(special.getChallenge()),
                      transport.value())

        transport.clear()
        server.dataReceived(base64.b64encode(b'username password') + b'\r\n')

        self.assertEqual(transport.value(),
                         b"001 OK Authentication successful\r\n")

        L{imap4.IMAP4Server} accepts a L{dict} mapping challenge type
        names to L{twisted.mail.interfaces.IChallengeResponse}
        providers.
        
stackoverflow/venv/lib/python3.6/site-packages/twisted/mail/test/test_imap.py