当前位置: 首页>>代码示例>>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;未经允许,请勿转载。