本文整理汇总了Python中twisted.cred.credentials.IAnonymous方法的典型用法代码示例。如果您正苦于以下问题:Python credentials.IAnonymous方法的具体用法?Python credentials.IAnonymous怎么用?Python credentials.IAnonymous使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.cred.credentials
的用法示例。
在下文中一共展示了credentials.IAnonymous方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_createsDictionary
# 需要导入模块: from twisted.cred import credentials [as 别名]
# 或者: from twisted.cred.credentials import IAnonymous [as 别名]
def test_createsDictionary(self):
"""
Test that the --auth command line creates a dictionary
mapping supported interfaces to the list of credentials
checkers that support it.
"""
options = DummyOptions()
options.parseOptions(['--auth', 'memory', '--auth', 'anonymous'])
chd = options['credInterfaces']
self.assertEqual(len(chd[credentials.IAnonymous]), 1)
self.assertEqual(len(chd[credentials.IUsernamePassword]), 1)
chdAnonymous = chd[credentials.IAnonymous][0]
chdUserPass = chd[credentials.IUsernamePassword][0]
self.assertTrue(checkers.ICredentialsChecker.providedBy(chdAnonymous))
self.assertTrue(checkers.ICredentialsChecker.providedBy(chdUserPass))
self.assertIn(credentials.IAnonymous,
chdAnonymous.credentialInterfaces)
self.assertIn(credentials.IUsernamePassword,
chdUserPass.credentialInterfaces)
示例2: test_createsDictionary
# 需要导入模块: from twisted.cred import credentials [as 别名]
# 或者: from twisted.cred.credentials import IAnonymous [as 别名]
def test_createsDictionary(self):
"""
The C{--auth} command line creates a dictionary mapping supported
interfaces to the list of credentials checkers that support it.
"""
options = DummyOptions()
options.parseOptions(['--auth', 'memory', '--auth', 'anonymous'])
chd = options['credInterfaces']
self.assertEqual(len(chd[credentials.IAnonymous]), 1)
self.assertEqual(len(chd[credentials.IUsernamePassword]), 1)
chdAnonymous = chd[credentials.IAnonymous][0]
chdUserPass = chd[credentials.IUsernamePassword][0]
self.assertTrue(checkers.ICredentialsChecker.providedBy(chdAnonymous))
self.assertTrue(checkers.ICredentialsChecker.providedBy(chdUserPass))
self.assertIn(credentials.IAnonymous,
chdAnonymous.credentialInterfaces)
self.assertIn(credentials.IUsernamePassword,
chdUserPass.credentialInterfaces)
示例3: makeService
# 需要导入模块: from twisted.cred import credentials [as 别名]
# 或者: from twisted.cred.credentials import IAnonymous [as 别名]
def makeService(config):
f = ftp.FTPFactory()
r = ftp.FTPRealm(config['root'])
p = portal.Portal(r)
p.registerChecker(checkers.AllowAnonymousAccess(), credentials.IAnonymous)
if config['password-file'] is not None:
p.registerChecker(checkers.FilePasswordDB(config['password-file'], cache=True))
f.tld = config['root']
f.userAnonymous = config['userAnonymous']
f.portal = p
f.protocol = ftp.FTP
try:
portno = int(config['port'])
except KeyError:
portno = 2121
return internet.TCPServer(portno, f)
示例4: test_createsDictionary
# 需要导入模块: from twisted.cred import credentials [as 别名]
# 或者: from twisted.cred.credentials import IAnonymous [as 别名]
def test_createsDictionary(self):
"""
Test that the --auth command line creates a dictionary
mapping supported interfaces to the list of credentials
checkers that support it.
"""
options = DummyOptions()
options.parseOptions(['--auth', 'memory', '--auth', 'anonymous'])
chd = options['credInterfaces']
self.assertEquals(len(chd[credentials.IAnonymous]), 1)
self.assertEquals(len(chd[credentials.IUsernamePassword]), 1)
chdAnonymous = chd[credentials.IAnonymous][0]
chdUserPass = chd[credentials.IUsernamePassword][0]
self.assertTrue(checkers.ICredentialsChecker.providedBy(chdAnonymous))
self.assertTrue(checkers.ICredentialsChecker.providedBy(chdUserPass))
self.assertIn(credentials.IAnonymous,
chdAnonymous.credentialInterfaces)
self.assertIn(credentials.IUsernamePassword,
chdUserPass.credentialInterfaces)
示例5: test_isChecker
# 需要导入模块: from twisted.cred import credentials [as 别名]
# 或者: from twisted.cred.credentials import IAnonymous [as 别名]
def test_isChecker(self):
"""
Verifies that strcred.makeChecker('anonymous') returns an object
that implements the L{ICredentialsChecker} interface.
"""
checker = strcred.makeChecker('anonymous')
self.assertTrue(checkers.ICredentialsChecker.providedBy(checker))
self.assertIn(credentials.IAnonymous, checker.credentialInterfaces)
示例6: test_supportsInterface
# 需要导入模块: from twisted.cred import credentials [as 别名]
# 或者: from twisted.cred.credentials import IAnonymous [as 别名]
def test_supportsInterface(self):
"""
Test that the supportsInterface method behaves appropriately.
"""
options = OptionsForUsernamePassword()
self.assertTrue(
options.supportsInterface(credentials.IUsernamePassword))
self.assertFalse(
options.supportsInterface(credentials.IAnonymous))
self.assertRaises(
strcred.UnsupportedInterfaces, options.addChecker,
self.anonChecker)
示例7: test_supportsAllInterfaces
# 需要导入模块: from twisted.cred import credentials [as 别名]
# 或者: from twisted.cred.credentials import IAnonymous [as 别名]
def test_supportsAllInterfaces(self):
"""
Test that the supportsInterface method behaves appropriately
when the supportedInterfaces attribute is None.
"""
options = OptionsSupportsAllInterfaces()
self.assertTrue(
options.supportsInterface(credentials.IUsernamePassword))
self.assertTrue(
options.supportsInterface(credentials.IAnonymous))
示例8: test_portalRejectedSenderAddress
# 需要导入模块: from twisted.cred import credentials [as 别名]
# 或者: from twisted.cred.credentials import IAnonymous [as 别名]
def test_portalRejectedSenderAddress(self):
"""
Test that a C{MAIL FROM} command with an address rejected by an
L{smtp.SMTP} instance's portal is responded to with the correct error
code.
"""
class DisallowAnonymousAccess(object):
"""
Checker for L{IAnonymous} which rejects authentication attempts.
"""
credentialInterfaces = (IAnonymous,)
def requestAvatarId(self, credentials):
return defer.fail(UnauthorizedLogin())
realm = SingletonRealm(smtp.IMessageDelivery, NotImplementedDelivery())
portal = Portal(realm, [DisallowAnonymousAccess()])
proto = smtp.SMTP()
proto.portal = portal
trans = StringTransport()
proto.makeConnection(trans)
# Deal with the necessary preliminaries
proto.dataReceived('HELO example.com\r\n')
trans.clear()
# Try to specify our sender address
proto.dataReceived('MAIL FROM:<alice@example.com>\r\n')
# Clean up the protocol before doing anything that might raise an
# exception.
proto.connectionLost(error.ConnectionLost())
# Make sure that we received exactly the correct response
self.assertEqual(
trans.value(),
'550 Cannot receive from specified address '
'<alice@example.com>: Sender not acceptable\r\n')
示例9: test_supportsInterface
# 需要导入模块: from twisted.cred import credentials [as 别名]
# 或者: from twisted.cred.credentials import IAnonymous [as 别名]
def test_supportsInterface(self):
"""
The supportsInterface method behaves appropriately.
"""
options = OptionsForUsernamePassword()
self.assertTrue(
options.supportsInterface(credentials.IUsernamePassword))
self.assertFalse(
options.supportsInterface(credentials.IAnonymous))
self.assertRaises(
strcred.UnsupportedInterfaces, options.addChecker,
self.anonChecker)
示例10: test_supportsAllInterfaces
# 需要导入模块: from twisted.cred import credentials [as 别名]
# 或者: from twisted.cred.credentials import IAnonymous [as 别名]
def test_supportsAllInterfaces(self):
"""
The supportsInterface method behaves appropriately
when the supportedInterfaces attribute is None.
"""
options = OptionsSupportsAllInterfaces()
self.assertTrue(
options.supportsInterface(credentials.IUsernamePassword))
self.assertTrue(
options.supportsInterface(credentials.IAnonymous))
示例11: test_portalRejectedSenderAddress
# 需要导入模块: from twisted.cred import credentials [as 别名]
# 或者: from twisted.cred.credentials import IAnonymous [as 别名]
def test_portalRejectedSenderAddress(self):
"""
Test that a C{MAIL FROM} command with an address rejected by an
L{smtp.SMTP} instance's portal is responded to with the correct error
code.
"""
class DisallowAnonymousAccess(object):
"""
Checker for L{IAnonymous} which rejects authentication attempts.
"""
credentialInterfaces = (IAnonymous,)
def requestAvatarId(self, credentials):
return defer.fail(UnauthorizedLogin())
realm = SingletonRealm(smtp.IMessageDelivery, NotImplementedDelivery())
portal = Portal(realm, [DisallowAnonymousAccess()])
proto = smtp.SMTP()
proto.portal = portal
trans = StringTransport()
proto.makeConnection(trans)
# Deal with the necessary preliminaries
proto.dataReceived(b'HELO example.com\r\n')
trans.clear()
# Try to specify our sender address
proto.dataReceived(b'MAIL FROM:<alice@example.com>\r\n')
# Clean up the protocol before doing anything that might raise an
# exception.
proto.connectionLost(error.ConnectionLost())
# Make sure that we received exactly the correct response
self.assertEqual(
trans.value(),
b'550 Cannot receive from specified address '
b'<alice@example.com>: Sender not acceptable\r\n')
示例12: test_portalRejectedSenderAddress
# 需要导入模块: from twisted.cred import credentials [as 别名]
# 或者: from twisted.cred.credentials import IAnonymous [as 别名]
def test_portalRejectedSenderAddress(self):
"""
Test that a C{MAIL FROM} command with an address rejected by an
L{smtp.SMTP} instance's portal is responded to with the correct error
code.
"""
class DisallowAnonymousAccess(object):
"""
Checker for L{IAnonymous} which rejects authentication attempts.
"""
implements(ICredentialsChecker)
credentialInterfaces = (IAnonymous,)
def requestAvatarId(self, credentials):
return defer.fail(UnauthorizedLogin())
realm = SingletonRealm(smtp.IMessageDelivery, NotImplementedDelivery())
portal = Portal(realm, [DisallowAnonymousAccess()])
proto = smtp.SMTP()
proto.portal = portal
trans = StringTransport()
proto.makeConnection(trans)
# Deal with the necessary preliminaries
proto.dataReceived('HELO example.com\r\n')
trans.clear()
# Try to specify our sender address
proto.dataReceived('MAIL FROM:<alice@example.com>\r\n')
# Clean up the protocol before doing anything that might raise an
# exception.
proto.connectionLost(error.ConnectionLost())
# Make sure that we received exactly the correct response
self.assertEqual(
trans.value(),
'550 Cannot receive from specified address '
'<alice@example.com>: Sender not acceptable\r\n')
示例13: test_supportsInterface
# 需要导入模块: from twisted.cred import credentials [as 别名]
# 或者: from twisted.cred.credentials import IAnonymous [as 别名]
def test_supportsInterface(self):
"""
Test that the supportsInterface method behaves appropriately.
"""
options = OptionsForUsernamePassword()
self.assertTrue(
options.supportsInterface(credentials.IUsernamePassword))
self.assertFalse(
options.supportsInterface(credentials.IAnonymous))
self.assertRaises(
strcred.UnsupportedInterfaces, options.addChecker, self.anonChecker)
示例14: setUp
# 需要导入模块: from twisted.cred import credentials [as 别名]
# 或者: from twisted.cred.credentials import IAnonymous [as 别名]
def setUp(self):
# Create a directory
self.directory = self.mktemp()
os.mkdir(self.directory)
# Start the server
p = portal.Portal(ftp.FTPRealm(self.directory))
p.registerChecker(checkers.AllowAnonymousAccess(),
credentials.IAnonymous)
self.factory = ftp.FTPFactory(portal=p)
self.port = reactor.listenTCP(0, self.factory, interface="127.0.0.1")
# Hook the server's buildProtocol to make the protocol instance
# accessible to tests.
buildProtocol = self.factory.buildProtocol
d1 = defer.Deferred()
def _rememberProtocolInstance(addr):
protocol = buildProtocol(addr)
self.serverProtocol = protocol.wrappedProtocol
d1.callback(None)
return protocol
self.factory.buildProtocol = _rememberProtocolInstance
# Connect a client to it
portNum = self.port.getHost().port
clientCreator = protocol.ClientCreator(reactor, ftp.FTPClientBasic)
d2 = clientCreator.connectTCP("127.0.0.1", portNum)
def gotClient(client):
self.client = client
d2.addCallback(gotClient)
return defer.gatherResults([d1, d2])
示例15: setUp
# 需要导入模块: from twisted.cred import credentials [as 别名]
# 或者: from twisted.cred.credentials import IAnonymous [as 别名]
def setUp(self):
# Create a directory
self.directory = self.mktemp()
os.mkdir(self.directory)
self.dirPath = filepath.FilePath(self.directory)
# Start the server
p = portal.Portal(ftp.FTPRealm(self.directory))
p.registerChecker(checkers.AllowAnonymousAccess(),
credentials.IAnonymous)
self.factory = ftp.FTPFactory(portal=p,
userAnonymous=self.userAnonymous)
port = reactor.listenTCP(0, self.factory, interface="127.0.0.1")
self.addCleanup(port.stopListening)
# Hook the server's buildProtocol to make the protocol instance
# accessible to tests.
buildProtocol = self.factory.buildProtocol
d1 = defer.Deferred()
def _rememberProtocolInstance(addr):
# Done hooking this.
del self.factory.buildProtocol
protocol = buildProtocol(addr)
self.serverProtocol = protocol.wrappedProtocol
def cleanupServer():
if self.serverProtocol.transport is not None:
self.serverProtocol.transport.loseConnection()
self.addCleanup(cleanupServer)
d1.callback(None)
return protocol
self.factory.buildProtocol = _rememberProtocolInstance
# Connect a client to it
portNum = port.getHost().port
clientCreator = protocol.ClientCreator(reactor, self.clientFactory)
d2 = clientCreator.connectTCP("127.0.0.1", portNum)
def gotClient(client):
self.client = client
self.addCleanup(self.client.transport.loseConnection)
d2.addCallback(gotClient)
return defer.gatherResults([d1, d2])