本文整理汇总了Python中twisted.cred.checkers.ANONYMOUS属性的典型用法代码示例。如果您正苦于以下问题:Python checkers.ANONYMOUS属性的具体用法?Python checkers.ANONYMOUS怎么用?Python checkers.ANONYMOUS使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类twisted.cred.checkers
的用法示例。
在下文中一共展示了checkers.ANONYMOUS属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_anonymousAccess
# 需要导入模块: from twisted.cred import checkers [as 别名]
# 或者: from twisted.cred.checkers import ANONYMOUS [as 别名]
def test_anonymousAccess(self):
"""
Anonymous requests are allowed if a L{Portal} has an anonymous checker
registered.
"""
unprotectedContents = b"contents of the unprotected child resource"
self.avatars[ANONYMOUS] = Resource()
self.avatars[ANONYMOUS].putChild(
self.childName, Data(unprotectedContents, 'text/plain'))
self.portal.registerChecker(AllowAnonymousAccess())
self.credentialFactories.append(BasicCredentialFactory('example.com'))
request = self.makeRequest([self.childName])
child = getChildForRequest(self.wrapper, request)
d = request.notifyFinish()
def cbFinished(ignored):
self.assertEqual(request.written, [unprotectedContents])
d.addCallback(cbFinished)
request.render(child)
return d
示例2: requestAvatar
# 需要导入模块: from twisted.cred import checkers [as 别名]
# 或者: from twisted.cred.checkers import ANONYMOUS [as 别名]
def requestAvatar(self, avatarId, mind, interface):
"""
Verify that the mind and interface supplied have the expected values
(this should really be done somewhere else, like inside a test method)
and return an avatar appropriate for the given identifier.
"""
assert interface == pb.IPerspective
assert mind == "BRAINS!"
if avatarId is checkers.ANONYMOUS:
return pb.IPerspective, Echoer(), lambda: None
else:
self.lastPerspective = self.perspectiveFactory(avatarId)
self.lastPerspective.loggedIn = True
return (
pb.IPerspective, self.lastPerspective,
self.lastPerspective.logout)
示例3: test_anonymousAccess
# 需要导入模块: from twisted.cred import checkers [as 别名]
# 或者: from twisted.cred.checkers import ANONYMOUS [as 别名]
def test_anonymousAccess(self):
"""
Anonymous requests are allowed if a L{Portal} has an anonymous checker
registered.
"""
unprotectedContents = "contents of the unprotected child resource"
self.avatars[ANONYMOUS] = Resource()
self.avatars[ANONYMOUS].putChild(
self.childName, Data(unprotectedContents, 'text/plain'))
self.portal.registerChecker(AllowAnonymousAccess())
self.credentialFactories.append(BasicCredentialFactory('example.com'))
request = self.makeRequest([self.childName])
child = getChildForRequest(self.wrapper, request)
d = request.notifyFinish()
def cbFinished(ignored):
self.assertEquals(request.written, [unprotectedContents])
d.addCallback(cbFinished)
request.render(child)
return d
示例4: _login
# 需要导入模块: from twisted.cred import checkers [as 别名]
# 或者: from twisted.cred.checkers import ANONYMOUS [as 别名]
def _login(self, credentials, request):
pattern = re.compile("^/sandbox/")
def loginSucceeded(args):
interface, avatar, logout = args
if avatar == checkers.ANONYMOUS and not pattern.match(request.path):
return self._anonymous_resource
else:
return self._root_resource
def loginFailed(result):
if result.check(error.Unauthorized, error.LoginFailed):
return UnauthorizedResource(self._credentialFactories)
else:
log.err(
result,
"HTTPAuthSessionWrapper.getChildWithDefault encountered "
"unexpected error")
return ErrorPage(500, None, None)
d = self._portal.login(credentials, None, IResource)
d.addCallbacks(loginSucceeded, loginFailed)
return d
示例5: _get_or_create_session
# 需要导入模块: from twisted.cred import checkers [as 别名]
# 或者: from twisted.cred.checkers 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
示例6: do_get_vpn_cert
# 需要导入模块: from twisted.cred import checkers [as 别名]
# 或者: from twisted.cred.checkers import ANONYMOUS [as 别名]
def do_get_vpn_cert(self, full_id, anonymous=False):
if anonymous:
_, provider_id = full_id.split('@')
provider = config.Provider.get(provider_id, autoconf=True)
d = self._get_or_create_session(
provider, ANONYMOUS).get_vpn_cert()
else:
if (full_id not in self._sessions or
not self._sessions[full_id].is_authenticated):
return fail(RuntimeError("There is no session for such user"))
d = self._sessions[full_id].get_vpn_cert()
return d
示例7: testAnonymousAccessSucceeds
# 需要导入模块: from twisted.cred import checkers [as 别名]
# 或者: from twisted.cred.checkers 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)
示例8: requestAvatar
# 需要导入模块: from twisted.cred import checkers [as 别名]
# 或者: from twisted.cred.checkers import ANONYMOUS [as 别名]
def requestAvatar(self, avatarId, mind, *interfaces):
for iface in interfaces:
if iface is IFTPShell:
if avatarId is checkers.ANONYMOUS:
avatar = FTPAnonymousShell(self.anonymousRoot)
else:
avatar = FTPShell(self.getHomeDirectory(avatarId))
return (IFTPShell, avatar,
getattr(avatar, 'logout', lambda: None))
raise NotImplementedError(
"Only IFTPShell interface is supported by this realm")
示例9: requestAvatar
# 需要导入模块: from twisted.cred import checkers [as 别名]
# 或者: from twisted.cred.checkers import ANONYMOUS [as 别名]
def requestAvatar(self, avatarId, mind, *interfaces):
"""
Get the mailbox for an authenticated user.
The mailbox for the authenticated user will be returned only if the
given interfaces include L{IMailbox <pop3.IMailbox>}. Requests for
anonymous access will be met with a mailbox containing a message
indicating that an internal error has occurred.
@type avatarId: L{bytes} or C{twisted.cred.checkers.ANONYMOUS}
@param avatarId: A string which identifies a user or an object which
signals a request for anonymous access.
@type mind: L{None}
@param mind: Unused.
@type interfaces: n-L{tuple} of C{zope.interface.Interface}
@param interfaces: A group of interfaces, one of which the avatar
must support.
@rtype: 3-L{tuple} of (0) L{IMailbox <pop3.IMailbox>},
(1) L{IMailbox <pop3.IMailbox>} provider, (2) no-argument
callable
@return: A tuple of the supported interface, a mailbox, and a
logout function.
@raise NotImplementedError: When the given interfaces do not include
L{IMailbox <pop3.IMailbox>}.
"""
if pop3.IMailbox not in interfaces:
raise NotImplementedError("No interface")
if avatarId == checkers.ANONYMOUS:
mbox = StringListMailbox([INTERNAL_ERROR])
else:
mbox = MaildirMailbox(os.path.join(self.root, avatarId))
return (
pop3.IMailbox,
mbox,
lambda: None
)
示例10: test_anonymous
# 需要导入模块: from twisted.cred import checkers [as 别名]
# 或者: from twisted.cred.checkers import ANONYMOUS [as 别名]
def test_anonymous(self):
"""
L{ftp.BaseFTPRealm} returns an L{ftp.FTPAnonymousShell} instance for
anonymous avatar requests.
"""
anonymous = self.mktemp()
realm = ftp.BaseFTPRealm(anonymous)
iface, avatar, logout = realm.requestAvatar(
checkers.ANONYMOUS, None, ftp.IFTPShell)
self.assertIsInstance(avatar, ftp.FTPAnonymousShell)
self.assertEqual(avatar.filesystemRoot, filepath.FilePath(anonymous))
示例11: testAnonymousAccessSucceeds
# 需要导入模块: from twisted.cred import checkers [as 别名]
# 或者: from twisted.cred.checkers 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)
示例12: requestAvatar
# 需要导入模块: from twisted.cred import checkers [as 别名]
# 或者: from twisted.cred.checkers import ANONYMOUS [as 别名]
def requestAvatar(self, avatarId, mind, *interfaces):
if IHTTPUser in interfaces:
if avatarId == checkers.ANONYMOUS:
return IHTTPUser, TestHTTPUser('anonymous')
return IHTTPUser, TestHTTPUser(avatarId)
raise NotImplementedError("Only IHTTPUser interface is supported")
示例13: requestAvatar
# 需要导入模块: from twisted.cred import checkers [as 别名]
# 或者: from twisted.cred.checkers import ANONYMOUS [as 别名]
def requestAvatar(self, avatarId, mind, *interfaces):
if pop3.IMailbox not in interfaces:
raise NotImplementedError("No interface")
if avatarId == checkers.ANONYMOUS:
mbox = StringListMailbox([INTERNAL_ERROR])
else:
mbox = MaildirMailbox(os.path.join(self.root, avatarId))
return (
pop3.IMailbox,
mbox,
lambda: None
)
示例14: requestAvatarId
# 需要导入模块: from twisted.cred import checkers [as 别名]
# 或者: from twisted.cred.checkers import ANONYMOUS [as 别名]
def requestAvatarId(self, credentials):
session = self.get_session(credentials.request)
if session.is_logged_in() and self._services_factory.has_session(session.user_uuid):
return defer.succeed(session.user_uuid)
return defer.succeed(ANONYMOUS)
示例15: requestAvatar
# 需要导入模块: from twisted.cred import checkers [as 别名]
# 或者: from twisted.cred.checkers import ANONYMOUS [as 别名]
def requestAvatar(self, avatarId, mind, *interfaces):
for iface in interfaces:
if iface is IFTPShell:
if avatarId is checkers.ANONYMOUS:
avatar = FTPAnonymousShell(self.anonymousRoot)
else:
avatar = FTPShell(filepath.FilePath("/home/" + avatarId))
return IFTPShell, avatar, getattr(avatar, 'logout', lambda: None)
raise NotImplementedError("Only IFTPShell interface is supported by this realm")
# --- FTP CLIENT -------------------------------------------------------------
####
# And now for the client...
# Notes:
# * Reference: http://cr.yp.to/ftp.html
# * FIXME: Does not support pipelining (which is not supported by all
# servers anyway). This isn't a functionality limitation, just a
# small performance issue.
# * Only has a rudimentary understanding of FTP response codes (although
# the full response is passed to the caller if they so choose).
# * Assumes that USER and PASS should always be sent
# * Always sets TYPE I (binary mode)
# * Doesn't understand any of the weird, obscure TELNET stuff (\377...)
# * FIXME: Doesn't share any code with the FTPServer