本文整理汇总了Python中twisted.cred.checkers.FilePasswordDB方法的典型用法代码示例。如果您正苦于以下问题:Python checkers.FilePasswordDB方法的具体用法?Python checkers.FilePasswordDB怎么用?Python checkers.FilePasswordDB使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.cred.checkers
的用法示例。
在下文中一共展示了checkers.FilePasswordDB方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: makeService
# 需要导入模块: from twisted.cred import checkers [as 别名]
# 或者: from twisted.cred.checkers import FilePasswordDB [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)
示例2: getCheckers
# 需要导入模块: from twisted.cred import checkers [as 别名]
# 或者: from twisted.cred.checkers import FilePasswordDB [as 别名]
def getCheckers(self):
diskHash = self.diskHash or (lambda x: x)
hashCheck = self.diskHash and (lambda username, password, stored: self.diskHash(password))
for cache in True, False:
fn = self.mktemp()
fObj = file(fn, 'w')
for u, p in self._validCredentials:
fObj.write('%s:%s\n' % (u, diskHash(p)))
fObj.close()
yield checkers.FilePasswordDB(fn, cache=cache, hash=hashCheck)
fn = self.mktemp()
fObj = file(fn, 'w')
for u, p in self._validCredentials:
fObj.write('%s dingle dongle %s\n' % (diskHash(p), u))
fObj.close()
yield checkers.FilePasswordDB(fn, ' ', 3, 0, cache=cache, hash=hashCheck)
fn = self.mktemp()
fObj = file(fn, 'w')
for u, p in self._validCredentials:
fObj.write('zip,zap,%s,zup,%s\n' % (u.title(), diskHash(p)))
fObj.close()
yield checkers.FilePasswordDB(fn, ',', 2, 4, False, cache=cache, hash=hashCheck)
示例3: opt_passwd
# 需要导入模块: from twisted.cred import checkers [as 别名]
# 或者: from twisted.cred.checkers import FilePasswordDB [as 别名]
def opt_passwd(self, filename):
"""
Name of a passwd-style file. (This is for
backwards-compatibility only; you should use the --auth
command instead.)
"""
self.addChecker(checkers.FilePasswordDB(filename))
示例4: test_getUserNonexistentDatabase
# 需要导入模块: from twisted.cred import checkers [as 别名]
# 或者: from twisted.cred.checkers import FilePasswordDB [as 别名]
def test_getUserNonexistentDatabase(self):
"""
A missing db file will cause a permanent rejection of authorization
attempts.
"""
self.db = checkers.FilePasswordDB('test_thisbetternoteverexist.db')
self.assertRaises(error.UnauthorizedLogin, self.db.getUser, 'user')
示例5: testUserLookup
# 需要导入模块: from twisted.cred import checkers [as 别名]
# 或者: from twisted.cred.checkers import FilePasswordDB [as 别名]
def testUserLookup(self):
self.db = checkers.FilePasswordDB(self.dbfile)
for (u, p) in self.users:
self.assertRaises(KeyError, self.db.getUser, u.upper())
self.assertEqual(self.db.getUser(u), (u, p))
示例6: testCaseInSensitivity
# 需要导入模块: from twisted.cred import checkers [as 别名]
# 或者: from twisted.cred.checkers import FilePasswordDB [as 别名]
def testCaseInSensitivity(self):
self.db = checkers.FilePasswordDB(self.dbfile, caseSensitive=False)
for (u, p) in self.users:
self.assertEqual(self.db.getUser(u.upper()), (u, p))
示例7: testRequestAvatarId
# 需要导入模块: from twisted.cred import checkers [as 别名]
# 或者: from twisted.cred.checkers import FilePasswordDB [as 别名]
def testRequestAvatarId(self):
self.db = checkers.FilePasswordDB(self.dbfile)
creds = [credentials.UsernamePassword(u, p) for u, p in self.users]
d = defer.gatherResults(
[defer.maybeDeferred(self.db.requestAvatarId, c) for c in creds])
d.addCallback(self.assertEqual, [u for u, p in self.users])
return d
示例8: setUp
# 需要导入模块: from twisted.cred import checkers [as 别名]
# 或者: from twisted.cred.checkers import FilePasswordDB [as 别名]
def setUp(self):
dbfile = self.mktemp()
self.db = checkers.FilePasswordDB(dbfile, hash=self.hash)
with open(dbfile, 'wb') as f:
for (u, p) in self.users:
f.write(u + b":" + self.hash(u, p, u[:2]) + b"\n")
r = TestRealm()
self.port = portal.Portal(r)
self.port.registerChecker(self.db)
示例9: getCheckers
# 需要导入模块: from twisted.cred import checkers [as 别名]
# 或者: from twisted.cred.checkers import FilePasswordDB [as 别名]
def getCheckers(self):
diskHash = self.diskHash or (lambda x: x)
hashCheck = self.diskHash and (lambda username, password,
stored: self.diskHash(password))
for cache in True, False:
fn = self.mktemp()
with open(fn, 'wb') as fObj:
for u, p in self._validCredentials:
fObj.write(u + b":" + diskHash(p) + b"\n")
yield checkers.FilePasswordDB(fn, cache=cache, hash=hashCheck)
fn = self.mktemp()
with open(fn, 'wb') as fObj:
for u, p in self._validCredentials:
fObj.write(diskHash(p) + b' dingle dongle ' + u + b'\n')
yield checkers.FilePasswordDB(fn, b' ', 3, 0,
cache=cache, hash=hashCheck)
fn = self.mktemp()
with open(fn, 'wb') as fObj:
for u, p in self._validCredentials:
fObj.write(b'zip,zap,' + u.title() + b',zup,'\
+ diskHash(p) + b'\n',)
yield checkers.FilePasswordDB(fn, b',', 2, 4, False,
cache=cache, hash=hashCheck)
示例10: setUp
# 需要导入模块: from twisted.cred import checkers [as 别名]
# 或者: from twisted.cred.checkers import FilePasswordDB [as 别名]
def setUp(self):
self.filename = self.mktemp()
with open(self.filename, 'wb') as f:
f.write(b'admin:asdf\nalice:foo\n')
self.goodChecker = checkers.FilePasswordDB(self.filename)
self.badChecker = checkers.FilePasswordDB(
self.filename, hash=self._hash)
self.anonChecker = checkers.AllowAnonymousAccess()
示例11: opt_password_file
# 需要导入模块: from twisted.cred import checkers [as 别名]
# 或者: from twisted.cred.checkers import FilePasswordDB [as 别名]
def opt_password_file(self, filename):
"""
Specify a file containing username:password login info for
authenticated connections. (DEPRECATED; see --help-auth instead)
"""
self['password-file'] = filename
msg = deprecate.getDeprecationWarningString(
self.opt_password_file, versions.Version('Twisted', 11, 1, 0))
warnings.warn(msg, category=DeprecationWarning, stacklevel=2)
self.addChecker(checkers.FilePasswordDB(filename, cache=True))
示例12: generateChecker
# 需要导入模块: from twisted.cred import checkers [as 别名]
# 或者: from twisted.cred.checkers import FilePasswordDB [as 别名]
def generateChecker(self, argstring):
"""
This checker factory expects to get the location of a file.
The file should conform to the format required by
L{FilePasswordDB} (using defaults for all
initialization parameters).
"""
from twisted.python.filepath import FilePath
if not argstring.strip():
raise ValueError('%r requires a filename' % self.authType)
elif not FilePath(argstring).isfile():
self.errorOutput.write('%s: %s\n' % (invalidFileWarning, argstring))
return FilePasswordDB(argstring)
示例13: get_web_app
# 需要导入模块: from twisted.cred import checkers [as 别名]
# 或者: from twisted.cred.checkers import FilePasswordDB [as 别名]
def get_web_app(config, controller):
auth = config.get_bool('web', 'auth', False)
if auth:
auth_file = config.get_string('web', 'auth-db')
portal = Portal(PublicHTMLRealm(config, controller),
[FilePasswordDB(auth_file)])
credential_factory = DigestCredentialFactory('md5', b'scrapy-do')
resource = HTTPAuthSessionWrapper(portal, [credential_factory])
return resource
return WebApp(config, controller)
示例14: setUp
# 需要导入模块: from twisted.cred import checkers [as 别名]
# 或者: from twisted.cred.checkers import FilePasswordDB [as 别名]
def setUp(self):
self.filename = self.mktemp()
file(self.filename, 'w').write('admin:asdf\nalice:foo\n')
self.goodChecker = checkers.FilePasswordDB(self.filename)
self.badChecker = checkers.FilePasswordDB(self.filename, hash=self._hash)
self.anonChecker = checkers.AllowAnonymousAccess()
示例15: testUserLookup
# 需要导入模块: from twisted.cred import checkers [as 别名]
# 或者: from twisted.cred.checkers import FilePasswordDB [as 别名]
def testUserLookup(self):
dbfile = self.mktemp()
db = checkers.FilePasswordDB(dbfile)
f = file(dbfile, 'w')
for (u, p) in self.users:
f.write('%s:%s\n' % (u, p))
f.close()
for (u, p) in self.users:
self.failUnlessRaises(KeyError, db.getUser, u.upper())
self.assertEquals(db.getUser(u), (u, p))