Python twisted.cred() Examples

The following are 12 code examples of twisted.cred(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module twisted , or try the search function .
Example #1
Source File: smtp.py    From Safejumper-for-Desktop with GNU General Public License v2.0 6 votes vote down vote up
def _cbAnonymousAuthentication(self, result):
        """
        Save the state resulting from a successful anonymous cred login.
        """
        (iface, avatar, logout) = result
        if issubclass(iface, IMessageDeliveryFactory):
            self.deliveryFactory = avatar
            self.delivery = None
        elif issubclass(iface, IMessageDelivery):
            self.deliveryFactory = None
            self.delivery = avatar
        else:
            raise RuntimeError("%s is not a supported interface" % (iface.__name__,))
        self._onLogout = logout
        self.challenger = None


    # overridable methods: 
Example #2
Source File: smtp.py    From learn_python3_spider with MIT License 6 votes vote down vote up
def _cbAnonymousAuthentication(self, result):
        """
        Save the state resulting from a successful anonymous cred login.
        """
        (iface, avatar, logout) = result
        if issubclass(iface, IMessageDeliveryFactory):
            self.deliveryFactory = avatar
            self.delivery = None
        elif issubclass(iface, IMessageDelivery):
            self.deliveryFactory = None
            self.delivery = avatar
        else:
            raise RuntimeError("%s is not a supported interface" % (iface.__name__,))
        self._onLogout = logout
        self.challenger = None


    # overridable methods: 
Example #3
Source File: smtp.py    From learn_python3_spider with MIT License 6 votes vote down vote up
def _ebAuthenticated(self, reason):
        """
        Handle cred login errors by translating them to the SMTP authenticate
        failed.  Translate all other errors into a generic SMTP error code and
        log the failure for inspection.  Stop all errors from propagating.

        @param reason: Reason for failure.
        """
        self.challenge = None
        if reason.check(cred.error.UnauthorizedLogin):
            self.sendCode(535, b'Authentication failed')
        else:
            log.err(reason, "SMTP authentication failure")
            self.sendCode(
                451,
                b'Requested action aborted: local error in processing') 
Example #4
Source File: smtp.py    From Safejumper-for-Desktop with GNU General Public License v2.0 5 votes vote down vote up
def _cbAuthenticated(self, loginInfo):
        """
        Save the state resulting from a successful cred login and mark this
        connection as authenticated.
        """
        result = SMTP._cbAnonymousAuthentication(self, loginInfo)
        self.authenticated = True
        return result 
Example #5
Source File: smtp.py    From Safejumper-for-Desktop with GNU General Public License v2.0 5 votes vote down vote up
def _ebAuthenticated(self, reason):
        """
        Handle cred login errors by translating them to the SMTP authenticate
        failed.  Translate all other errors into a generic SMTP error code and
        log the failure for inspection.  Stop all errors from propagating.
        """
        self.challenge = None
        if reason.check(cred.error.UnauthorizedLogin):
            self.sendCode(535, 'Authentication failed')
        else:
            log.err(reason, "SMTP authentication failure")
            self.sendCode(
                451,
                'Requested action aborted: local error in processing') 
Example #6
Source File: smtp.py    From learn_python3_spider with MIT License 5 votes vote down vote up
def _cbAuthenticated(self, loginInfo):
        """
        Save the state resulting from a successful cred login and mark this
        connection as authenticated.
        """
        result = SMTP._cbAnonymousAuthentication(self, loginInfo)
        self.authenticated = True
        return result 
Example #7
Source File: smtp.py    From python-for-android with Apache License 2.0 5 votes vote down vote up
def _cbAuthenticated(self, loginInfo):
        """
        Save the state resulting from a successful cred login and mark this
        connection as authenticated.
        """
        result = SMTP._cbAnonymousAuthentication(self, loginInfo)
        self.authenticated = True
        return result 
Example #8
Source File: smtp.py    From python-for-android with Apache License 2.0 5 votes vote down vote up
def _ebAuthenticated(self, reason):
        """
        Handle cred login errors by translating them to the SMTP authenticate
        failed.  Translate all other errors into a generic SMTP error code and
        log the failure for inspection.  Stop all errors from propagating.
        """
        self.challenge = None
        if reason.check(cred.error.UnauthorizedLogin):
            self.sendCode(535, 'Authentication failed')
        else:
            log.err(reason, "SMTP authentication failure")
            self.sendCode(
                451,
                'Requested action aborted: local error in processing') 
Example #9
Source File: pb.py    From BitTorrent with GNU General Public License v3.0 5 votes vote down vote up
def brokerAttached(self, reference, identity, broker):
        """An intermediary method to override.

        Normally you will want to use 'attached', as described in
        L{twisted.cred.perspective.Perspective}.attached; however, this method
        serves the same purpose, and in some circumstances, you are sure that
        the protocol that objects will be attaching to your Perspective with is
        Perspective Broker, and in that case you may wish to get the Broker
        object they are connecting with, for example, to determine what host
        they are connecting from.  Bear in mind that when overriding this
        method, other, non-PB protocols will not notify you of being attached
        or detached.
        """
        warnings.warn("pb.Perspective is deprecated, please use pb.Avatar.", DeprecationWarning, 2)
        return self.attached(reference, identity) 
Example #10
Source File: pb.py    From BitTorrent with GNU General Public License v3.0 5 votes vote down vote up
def _cbLogInResponded(identity, d, client, serviceName, perspectiveName):
    warnings.warn("This is deprecated. Use PBClientFactory.", DeprecationWarning, 2)
    if identity:
        identity.callRemote("attach", serviceName, perspectiveName, client).chainDeferred(d)
    else:
        from twisted import cred
        d.errback(cred.error.Unauthorized("invalid username or password")) 
Example #11
Source File: pb.py    From BitTorrent with GNU General Public License v3.0 5 votes vote down vote up
def _cbGotIdentity(self, i):
         self._identityWrapper = i
         if i:
             for d in self._connectDeferreds:
                 d.callback(i)
             self._connectDeferreds[:] = []
         else:
             from twisted import cred
             e = cred.error.Unauthorized("invalid username or password")
             self._ebGotIdentity(e) 
Example #12
Source File: pb.py    From BitTorrent with GNU General Public License v3.0 5 votes vote down vote up
def login(self, credentials, client=None):
        """Login and get perspective from remote PB server.

        Currently only credentials implementing
        L{twisted.cred.credentials.IUsernamePassword} are supported.

        @return: Deferred of RemoteReference to the perspective.
        """
        d = self.getRootObject()
        d.addCallback(self._cbSendUsername, credentials.username, credentials.password, client)
        return d