當前位置: 首頁>>代碼示例>>Python>>正文


Python credentials.Anonymous方法代碼示例

本文整理匯總了Python中twisted.cred.credentials.Anonymous方法的典型用法代碼示例。如果您正苦於以下問題:Python credentials.Anonymous方法的具體用法?Python credentials.Anonymous怎麽用?Python credentials.Anonymous使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在twisted.cred.credentials的用法示例。


在下文中一共展示了credentials.Anonymous方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _get_config_for_all_services

# 需要導入模塊: from twisted.cred import credentials [as 別名]
# 或者: from twisted.cred.credentials import Anonymous [as 別名]
def _get_config_for_all_services(self, session):
        if session is None:
            provider_cert = self._get_ca_cert_path()
            session = Session(Anonymous(), self.api_uri, provider_cert)

        services_dict = self._load_provider_configs()
        configs_path = self._get_configs_path()
        with open(configs_path) as jsonf:
            services_dict = Record(**json.load(jsonf)).services
        pending = []
        base = self._disco.get_base_uri()
        for service in self._provider_config.services:
            if service in self.SERVICES_MAP.keys():
                for subservice in self.SERVICES_MAP[service]:
                    uri = base + str(services_dict[subservice])
                    path = self._get_service_config_path(subservice)
                    d = session.fetch_provider_configs(
                        uri, path, method='GET')
                    pending.append(d)
        return defer.gatherResults(pending) 
開發者ID:leapcode,項目名稱:bitmask-dev,代碼行數:22,代碼來源:config.py

示例2: _authorizedResource

# 需要導入模塊: from twisted.cred import credentials [as 別名]
# 或者: from twisted.cred.credentials import Anonymous [as 別名]
def _authorizedResource(self, request):
        """
        Get the L{IResource} which the given request is authorized to receive.
        If the proper authorization headers are present, the resource will be
        requested from the portal.  If not, an anonymous login attempt will be
        made.
        """
        authheader = request.getHeader(b'authorization')
        if not authheader:
            return util.DeferredResource(self._login(Anonymous()))

        factory, respString = self._selectParseHeader(authheader)
        if factory is None:
            return UnauthorizedResource(self._credentialFactories)
        try:
            credentials = factory.decode(respString, request)
        except error.LoginFailed:
            return UnauthorizedResource(self._credentialFactories)
        except:
            log.err(None, "Unexpected failure from credentials factory")
            return ErrorPage(500, None, None)
        else:
            return util.DeferredResource(self._login(credentials)) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:25,代碼來源:wrapper.py

示例3: test_anonymousLogin

# 需要導入模塊: from twisted.cred import credentials [as 別名]
# 或者: from twisted.cred.credentials import Anonymous [as 別名]
def test_anonymousLogin(self):
        """
        Verify that a PB server using a portal configured with a checker which
        allows IAnonymous credentials can be logged into using IAnonymous
        credentials.
        """
        self.portal.registerChecker(checkers.AllowAnonymousAccess())
        d = self.clientFactory.login(credentials.Anonymous(), "BRAINS!")

        def cbLoggedIn(perspective):
            return perspective.callRemote('echo', 123)
        d.addCallback(cbLoggedIn)

        d.addCallback(self.assertEqual, 123)

        self.establishClientAndServer()
        self.pump.flush()
        return d 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:20,代碼來源:test_pb.py

示例4: test_anonymousLoginWithMultipleCheckers

# 需要導入模塊: from twisted.cred import credentials [as 別名]
# 或者: from twisted.cred.credentials import Anonymous [as 別名]
def test_anonymousLoginWithMultipleCheckers(self):
        """
        Like L{test_anonymousLogin} but against a portal with a checker for
        both IAnonymous and IUsernamePassword.
        """
        self.portal.registerChecker(checkers.AllowAnonymousAccess())
        self.portal.registerChecker(
            checkers.InMemoryUsernamePasswordDatabaseDontUse(user=b'pass'))
        d = self.clientFactory.login(credentials.Anonymous(), "BRAINS!")

        def cbLogin(perspective):
            return perspective.callRemote('echo', 123)
        d.addCallback(cbLogin)

        d.addCallback(self.assertEqual, 123)

        self.establishClientAndServer()
        self.pump.flush()

        return d 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:22,代碼來源:test_pb.py

示例5: _authorizedResource

# 需要導入模塊: from twisted.cred import credentials [as 別名]
# 或者: from twisted.cred.credentials import Anonymous [as 別名]
def _authorizedResource(self, request):
        """
        Get the L{IResource} which the given request is authorized to receive.
        If the proper authorization headers are present, the resource will be
        requested from the portal.  If not, an anonymous login attempt will be
        made.
        """
        authheader = request.getHeader(b'authorization')
        if not authheader:
            return util.DeferredResource(self._login(Anonymous()))

        factory, respString = self._selectParseHeader(authheader)
        if factory is None:
            return UnauthorizedResource(self._credentialFactories)
        try:
            credentials = factory.decode(respString, request)
        except error.LoginFailed:
            return UnauthorizedResource(self._credentialFactories)
        except:
            self._log.failure("Unexpected failure from credentials factory")
            return ErrorPage(500, None, None)
        else:
            return util.DeferredResource(self._login(credentials)) 
開發者ID:wistbean,項目名稱:learn_python3_spider,代碼行數:25,代碼來源:wrapper.py

示例6: authenticate

# 需要導入模塊: from twisted.cred import credentials [as 別名]
# 或者: from twisted.cred.credentials import Anonymous [as 別名]
def authenticate(self, request):
        """
        Attempt to authenticate the given request

        @param request: An L{IRequest} to be authenticated.
        """
        authHeader = request.headers.getHeader('authorization')

        if authHeader is None:
            return self.portal.login(credentials.Anonymous(),
                                     None,
                                     *self.interfaces
                                     ).addCallbacks(self._loginSucceeded,
                                                    self._loginFailed,
                                                    (request,), None,
                                                    (request,), None)

        elif authHeader[0] not in self.credentialFactories:
            return self._loginFailed(None, request)
        else:
            return self.login(self.credentialFactories[authHeader[0]],
                              authHeader[1], request) 
開發者ID:apple,項目名稱:ccs-calendarserver,代碼行數:24,代碼來源:wrapper.py

示例7: _authorizedResource

# 需要導入模塊: from twisted.cred import credentials [as 別名]
# 或者: from twisted.cred.credentials import Anonymous [as 別名]
def _authorizedResource(self, request):
        """
        Get the L{IResource} which the given request is authorized to receive.
        If the proper authorization headers are present, the resource will be
        requested from the portal.  If not, an anonymous login attempt will be
        made.
        """
        authheader = request.getHeader('authorization')
        if not authheader:
            return util.DeferredResource(self._login(Anonymous()))

        factory, respString = self._selectParseHeader(authheader)
        if factory is None:
            return UnauthorizedResource(self._credentialFactories)
        try:
            credentials = factory.decode(respString, request)
        except error.LoginFailed:
            return UnauthorizedResource(self._credentialFactories)
        except:
            log.err(None, "Unexpected failure from credentials factory")
            return ErrorPage(500, None, None)
        else:
            return util.DeferredResource(self._login(credentials)) 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:25,代碼來源:wrapper.py

示例8: test_anonymousLogin

# 需要導入模塊: from twisted.cred import credentials [as 別名]
# 或者: from twisted.cred.credentials import Anonymous [as 別名]
def test_anonymousLogin(self):
        """
        Verify that a PB server using a portal configured with an checker which
        allows IAnonymous credentials can be logged into using IAnonymous
        credentials.
        """
        self.portal.registerChecker(checkers.AllowAnonymousAccess())
        factory = pb.PBClientFactory()
        d = factory.login(credentials.Anonymous(), "BRAINS!")

        def cbLoggedIn(perspective):
            return perspective.callRemote('echo', 123)
        d.addCallback(cbLoggedIn)

        d.addCallback(self.assertEqual, 123)

        d.addCallback(self._disconnect, factory)

        connector = reactor.connectTCP("127.0.0.1", self.portno, factory)
        self.addCleanup(connector.disconnect)
        return d 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:23,代碼來源:test_pb.py

示例9: test_anonymousLoginNotPermitted

# 需要導入模塊: from twisted.cred import credentials [as 別名]
# 或者: from twisted.cred.credentials import Anonymous [as 別名]
def test_anonymousLoginNotPermitted(self):
        """
        Verify that without an anonymous checker set up, anonymous login is
        rejected.
        """
        self.portal.registerChecker(
            checkers.InMemoryUsernamePasswordDatabaseDontUse(user='pass'))
        factory = pb.PBClientFactory()
        d = factory.login(credentials.Anonymous(), "BRAINS!")
        self.assertFailure(d, UnhandledCredentials)

        def cleanup(ignore):
            errors = self.flushLoggedErrors(UnhandledCredentials)
            self.assertEquals(len(errors), 1)
            return self._disconnect(None, factory)
        d.addCallback(cleanup)

        connector = reactor.connectTCP('127.0.0.1', self.portno, factory)
        self.addCleanup(connector.disconnect)
        return d 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:22,代碼來源:test_pb.py

示例10: send_changes

# 需要導入模塊: from twisted.cred import credentials [as 別名]
# 或者: from twisted.cred.credentials import Anonymous [as 別名]
def send_changes(self, changes, request):
        """
        Submit the changes, if any
        """
        if not changes:
            logging.warning("No changes found")
            request.setResponseCode(OK)
            request.write(json.dumps({"result": "No changes found."}))
            request.finish()
            return

        host, port = self.master.split(':')
        port = int(port)

        if self.auth is not None:
            auth = credentials.UsernamePassword(*self.auth.split(":"))
        else:
            auth = credentials.Anonymous()

        factory = pb.PBClientFactory()
        deferred = factory.login(auth)
        reactor.connectTCP(host, port, factory)
        deferred.addErrback(self.connectFailed, request)
        deferred.addCallback(self.connected, changes, request) 
開發者ID:buildbot,項目名稱:buildbot-contrib,代碼行數:26,代碼來源:github_buildbot.py

示例11: _get_or_create_session

# 需要導入模塊: from twisted.cred import credentials [as 別名]
# 或者: from twisted.cred.credentials import Anonymous [as 別名]
def _get_or_create_session(self, provider, full_id, password=""):
        if full_id in self._sessions:
            return self._sessions[full_id]
        if full_id == ANONYMOUS:
            credentials = Anonymous()
            provider_id = provider.domain
        else:
            username, provider_id = config.get_username_and_provider(
                full_id)
            credentials = UsernamePassword(username, password)
        api = self._get_api(provider)
        provider_pem = config.get_ca_cert_path(_preffix, provider_id)
        session = Session(credentials, api, provider_pem)
        self._sessions[full_id] = session
        return session 
開發者ID:leapcode,項目名稱:bitmask-dev,代碼行數:17,代碼來源:_protocol.py

示例12: testAnonymousAccessSucceeds

# 需要導入模塊: from twisted.cred import credentials [as 別名]
# 或者: from twisted.cred.credentials import Anonymous [as 別名]
def testAnonymousAccessSucceeds(self):
        """
        Test that we can log in anonymously using this checker.
        """
        checker = strcred.makeChecker('anonymous')
        request = checker.requestAvatarId(credentials.Anonymous())
        def _gotAvatar(avatar):
            self.assertIdentical(checkers.ANONYMOUS, avatar)
        return request.addCallback(_gotAvatar) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:11,代碼來源:test_strcred.py

示例13: ftp_PASS

# 需要導入模塊: from twisted.cred import credentials [as 別名]
# 或者: from twisted.cred.credentials import Anonymous [as 別名]
def ftp_PASS(self, password):
        """
        Second part of login.  Get the password the peer wants to
        authenticate with.
        """
        if self.factory.allowAnonymous and self._user == self.factory.userAnonymous:
            # anonymous login
            creds = credentials.Anonymous()
            reply = GUEST_LOGGED_IN_PROCEED
        else:
            # user login
            creds = credentials.UsernamePassword(self._user, password)
            reply = USR_LOGGED_IN_PROCEED
        del self._user

        def _cbLogin(result):
            (interface, avatar, logout) = result
            assert interface is IFTPShell, "The realm is busted, jerk."
            self.shell = avatar
            self.logout = logout
            self.workingDirectory = []
            self.state = self.AUTHED
            return reply

        def _ebLogin(failure):
            failure.trap(cred_error.UnauthorizedLogin, cred_error.UnhandledCredentials)
            self.state = self.UNAUTH
            raise AuthorizationError

        d = self.portal.login(creds, None, IFTPShell)
        d.addCallbacks(_cbLogin, _ebLogin)
        return d 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:34,代碼來源:ftp.py

示例14: remote_loginAnonymous

# 需要導入模塊: from twisted.cred import credentials [as 別名]
# 或者: from twisted.cred.credentials import Anonymous [as 別名]
def remote_loginAnonymous(self, mind):
        """
        Attempt an anonymous login.

        @param mind: An object to use as the mind parameter to the portal login
            call (possibly None).

        @rtype: L{Deferred}
        @return: A Deferred which will be called back with an avatar when login
            succeeds or which will be errbacked if login fails somehow.
        """
        d = self.portal.login(Anonymous(), mind, IPerspective)
        d.addCallback(self._cbLogin)
        return d 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:16,代碼來源:pb.py

示例15: testAnonymousAccessSucceeds

# 需要導入模塊: from twisted.cred import credentials [as 別名]
# 或者: from twisted.cred.credentials import Anonymous [as 別名]
def testAnonymousAccessSucceeds(self):
        """
        We can log in anonymously using this checker.
        """
        checker = strcred.makeChecker('anonymous')
        request = checker.requestAvatarId(credentials.Anonymous())
        def _gotAvatar(avatar):
            self.assertIdentical(checkers.ANONYMOUS, avatar)
        return request.addCallback(_gotAvatar) 
開發者ID:wistbean,項目名稱:learn_python3_spider,代碼行數:11,代碼來源:test_strcred.py


注:本文中的twisted.cred.credentials.Anonymous方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。