code
stringlengths
26
870k
docstring
stringlengths
1
65.6k
func_name
stringlengths
1
194
language
stringclasses
1 value
repo
stringlengths
8
68
path
stringlengths
5
194
url
stringlengths
46
254
license
stringclasses
4 values
def assertLoggedIn(self, d, username): """ Assert that the L{Deferred} passed in is called back with the value 'username'. This represents a valid login for this TestCase. NOTE: To work, this method's return value must be returned from the test method, or otherwise hooked up to the test machinery. @param d: a L{Deferred} from an L{IChecker.requestAvatarId} method. @type d: L{Deferred} @rtype: L{Deferred} """ result = [] d.addBoth(result.append) self.assertEqual(len(result), 1, "login incomplete") if isinstance(result[0], Failure): result[0].raiseException() self.assertEqual(result[0], username)
Assert that the L{Deferred} passed in is called back with the value 'username'. This represents a valid login for this TestCase. NOTE: To work, this method's return value must be returned from the test method, or otherwise hooked up to the test machinery. @param d: a L{Deferred} from an L{IChecker.requestAvatarId} method. @type d: L{Deferred} @rtype: L{Deferred}
assertLoggedIn
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py
MIT
def test_defaultCheckers(self): """ L{UNIXPasswordDatabase} with no arguments has checks the C{pwd} database and then the C{spwd} database. """ checker = checkers.UNIXPasswordDatabase() def crypted(username, password): salt = crypt.crypt(password, username) crypted = crypt.crypt(password, '$1$' + salt) return crypted pwd = UserDatabase() pwd.addUser('alice', crypted('alice', 'password'), 1, 2, 'foo', '/foo', '/bin/sh') # x and * are convention for "look elsewhere for the password" pwd.addUser('bob', 'x', 1, 2, 'bar', '/bar', '/bin/sh') spwd = ShadowDatabase() spwd.addUser('alice', 'wrong', 1, 2, 3, 4, 5, 6, 7) spwd.addUser('bob', crypted('bob', 'password'), 8, 9, 10, 11, 12, 13, 14) self.patch(checkers, 'pwd', pwd) self.patch(checkers, 'spwd', spwd) mockos = MockOS() self.patch(util, 'os', mockos) mockos.euid = 2345 mockos.egid = 1234 cred = UsernamePassword(b"alice", b"password") self.assertLoggedIn(checker.requestAvatarId(cred), b'alice') self.assertEqual(mockos.seteuidCalls, []) self.assertEqual(mockos.setegidCalls, []) cred.username = b"bob" self.assertLoggedIn(checker.requestAvatarId(cred), b'bob') self.assertEqual(mockos.seteuidCalls, [0, 2345]) self.assertEqual(mockos.setegidCalls, [0, 1234])
L{UNIXPasswordDatabase} with no arguments has checks the C{pwd} database and then the C{spwd} database.
test_defaultCheckers
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py
MIT
def assertUnauthorizedLogin(self, d): """ Asserts that the L{Deferred} passed in is erred back with an L{UnauthorizedLogin} L{Failure}. This reprsents an invalid login for this TestCase. NOTE: To work, this method's return value must be returned from the test method, or otherwise hooked up to the test machinery. @param d: a L{Deferred} from an L{IChecker.requestAvatarId} method. @type d: L{Deferred} @rtype: L{None} """ self.assertRaises( checkers.UnauthorizedLogin, self.assertLoggedIn, d, 'bogus value')
Asserts that the L{Deferred} passed in is erred back with an L{UnauthorizedLogin} L{Failure}. This reprsents an invalid login for this TestCase. NOTE: To work, this method's return value must be returned from the test method, or otherwise hooked up to the test machinery. @param d: a L{Deferred} from an L{IChecker.requestAvatarId} method. @type d: L{Deferred} @rtype: L{None}
assertUnauthorizedLogin
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py
MIT
def test_passInCheckers(self): """ L{UNIXPasswordDatabase} takes a list of functions to check for UNIX user information. """ password = crypt.crypt('secret', 'secret') userdb = UserDatabase() userdb.addUser('anybody', password, 1, 2, 'foo', '/bar', '/bin/sh') checker = checkers.UNIXPasswordDatabase([userdb.getpwnam]) self.assertLoggedIn( checker.requestAvatarId(UsernamePassword(b'anybody', b'secret')), b'anybody')
L{UNIXPasswordDatabase} takes a list of functions to check for UNIX user information.
test_passInCheckers
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py
MIT
def test_verifyPassword(self): """ If the encrypted password provided by the getpwnam function is valid (verified by the L{verifyCryptedPassword} function), we callback the C{requestAvatarId} L{Deferred} with the username. """ def verifyCryptedPassword(crypted, pw): return crypted == pw def getpwnam(username): return [username, username] self.patch(checkers, 'verifyCryptedPassword', verifyCryptedPassword) checker = checkers.UNIXPasswordDatabase([getpwnam]) credential = UsernamePassword(b'username', b'username') self.assertLoggedIn(checker.requestAvatarId(credential), b'username')
If the encrypted password provided by the getpwnam function is valid (verified by the L{verifyCryptedPassword} function), we callback the C{requestAvatarId} L{Deferred} with the username.
test_verifyPassword
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py
MIT
def test_failOnKeyError(self): """ If the getpwnam function raises a KeyError, the login fails with an L{UnauthorizedLogin} exception. """ def getpwnam(username): raise KeyError(username) checker = checkers.UNIXPasswordDatabase([getpwnam]) credential = UsernamePassword(b'username', b'username') self.assertUnauthorizedLogin(checker.requestAvatarId(credential))
If the getpwnam function raises a KeyError, the login fails with an L{UnauthorizedLogin} exception.
test_failOnKeyError
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py
MIT
def test_failOnBadPassword(self): """ If the verifyCryptedPassword function doesn't verify the password, the login fails with an L{UnauthorizedLogin} exception. """ def verifyCryptedPassword(crypted, pw): return False def getpwnam(username): return [username, username] self.patch(checkers, 'verifyCryptedPassword', verifyCryptedPassword) checker = checkers.UNIXPasswordDatabase([getpwnam]) credential = UsernamePassword(b'username', b'username') self.assertUnauthorizedLogin(checker.requestAvatarId(credential))
If the verifyCryptedPassword function doesn't verify the password, the login fails with an L{UnauthorizedLogin} exception.
test_failOnBadPassword
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py
MIT
def test_loopThroughFunctions(self): """ UNIXPasswordDatabase.requestAvatarId loops through each getpwnam function associated with it and returns a L{Deferred} which fires with the result of the first one which returns a value other than None. ones do not verify the password. """ def verifyCryptedPassword(crypted, pw): return crypted == pw def getpwnam1(username): return [username, 'not the password'] def getpwnam2(username): return [username, username] self.patch(checkers, 'verifyCryptedPassword', verifyCryptedPassword) checker = checkers.UNIXPasswordDatabase([getpwnam1, getpwnam2]) credential = UsernamePassword(b'username', b'username') self.assertLoggedIn(checker.requestAvatarId(credential), b'username')
UNIXPasswordDatabase.requestAvatarId loops through each getpwnam function associated with it and returns a L{Deferred} which fires with the result of the first one which returns a value other than None. ones do not verify the password.
test_loopThroughFunctions
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py
MIT
def test_failOnSpecial(self): """ If the password returned by any function is C{""}, C{"x"}, or C{"*"} it is not compared against the supplied password. Instead it is skipped. """ pwd = UserDatabase() pwd.addUser('alice', '', 1, 2, '', 'foo', 'bar') pwd.addUser('bob', 'x', 1, 2, '', 'foo', 'bar') pwd.addUser('carol', '*', 1, 2, '', 'foo', 'bar') self.patch(checkers, 'pwd', pwd) checker = checkers.UNIXPasswordDatabase([checkers._pwdGetByName]) cred = UsernamePassword(b'alice', b'') self.assertUnauthorizedLogin(checker.requestAvatarId(cred)) cred = UsernamePassword(b'bob', b'x') self.assertUnauthorizedLogin(checker.requestAvatarId(cred)) cred = UsernamePassword(b'carol', b'*') self.assertUnauthorizedLogin(checker.requestAvatarId(cred))
If the password returned by any function is C{""}, C{"x"}, or C{"*"} it is not compared against the supplied password. Instead it is skipped.
test_failOnSpecial
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py
MIT
def test_ignoresComments(self): """ L{checkers.readAuthorizedKeyFile} does not attempt to turn comments into keys """ fileobj = BytesIO(b'# this comment is ignored\n' b'this is not\n' b'# this is again\n' b'and this is not') result = checkers.readAuthorizedKeyFile(fileobj, lambda x: x) self.assertEqual([b'this is not', b'and this is not'], list(result))
L{checkers.readAuthorizedKeyFile} does not attempt to turn comments into keys
test_ignoresComments
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py
MIT
def test_ignoresLeadingWhitespaceAndEmptyLines(self): """ L{checkers.readAuthorizedKeyFile} ignores leading whitespace in lines, as well as empty lines """ fileobj = BytesIO(b""" # ignore not ignored """) result = checkers.readAuthorizedKeyFile(fileobj, parseKey=lambda x: x) self.assertEqual([b'not ignored'], list(result))
L{checkers.readAuthorizedKeyFile} ignores leading whitespace in lines, as well as empty lines
test_ignoresLeadingWhitespaceAndEmptyLines
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py
MIT
def test_ignoresUnparsableKeys(self): """ L{checkers.readAuthorizedKeyFile} does not raise an exception when a key fails to parse (raises a L{twisted.conch.ssh.keys.BadKeyError}), but rather just keeps going """ def failOnSome(line): if line.startswith(b'f'): raise keys.BadKeyError('failed to parse') return line fileobj = BytesIO(b'failed key\ngood key') result = checkers.readAuthorizedKeyFile(fileobj, parseKey=failOnSome) self.assertEqual([b'good key'], list(result))
L{checkers.readAuthorizedKeyFile} does not raise an exception when a key fails to parse (raises a L{twisted.conch.ssh.keys.BadKeyError}), but rather just keeps going
test_ignoresUnparsableKeys
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py
MIT
def test_implementsInterface(self): """ L{checkers.InMemorySSHKeyDB} implements L{checkers.IAuthorizedKeysDB} """ keydb = checkers.InMemorySSHKeyDB({b'alice': [b'key']}) verifyObject(checkers.IAuthorizedKeysDB, keydb)
L{checkers.InMemorySSHKeyDB} implements L{checkers.IAuthorizedKeysDB}
test_implementsInterface
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py
MIT
def test_noKeysForUnauthorizedUser(self): """ If the user is not in the mapping provided to L{checkers.InMemorySSHKeyDB}, an empty iterator is returned by L{checkers.InMemorySSHKeyDB.getAuthorizedKeys} """ keydb = checkers.InMemorySSHKeyDB({b'alice': [b'keys']}) self.assertEqual([], list(keydb.getAuthorizedKeys(b'bob')))
If the user is not in the mapping provided to L{checkers.InMemorySSHKeyDB}, an empty iterator is returned by L{checkers.InMemorySSHKeyDB.getAuthorizedKeys}
test_noKeysForUnauthorizedUser
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py
MIT
def test_allKeysForAuthorizedUser(self): """ If the user is in the mapping provided to L{checkers.InMemorySSHKeyDB}, an iterator with all the keys is returned by L{checkers.InMemorySSHKeyDB.getAuthorizedKeys} """ keydb = checkers.InMemorySSHKeyDB({b'alice': [b'a', b'b']}) self.assertEqual([b'a', b'b'], list(keydb.getAuthorizedKeys(b'alice')))
If the user is in the mapping provided to L{checkers.InMemorySSHKeyDB}, an iterator with all the keys is returned by L{checkers.InMemorySSHKeyDB.getAuthorizedKeys}
test_allKeysForAuthorizedUser
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py
MIT
def test_implementsInterface(self): """ L{checkers.UNIXAuthorizedKeysFiles} implements L{checkers.IAuthorizedKeysDB}. """ keydb = checkers.UNIXAuthorizedKeysFiles(self.userdb) verifyObject(checkers.IAuthorizedKeysDB, keydb)
L{checkers.UNIXAuthorizedKeysFiles} implements L{checkers.IAuthorizedKeysDB}.
test_implementsInterface
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py
MIT
def test_noKeysForUnauthorizedUser(self): """ If the user is not in the user database provided to L{checkers.UNIXAuthorizedKeysFiles}, an empty iterator is returned by L{checkers.UNIXAuthorizedKeysFiles.getAuthorizedKeys}. """ keydb = checkers.UNIXAuthorizedKeysFiles(self.userdb, parseKey=lambda x: x) self.assertEqual([], list(keydb.getAuthorizedKeys('bob')))
If the user is not in the user database provided to L{checkers.UNIXAuthorizedKeysFiles}, an empty iterator is returned by L{checkers.UNIXAuthorizedKeysFiles.getAuthorizedKeys}.
test_noKeysForUnauthorizedUser
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py
MIT
def test_allKeysInAllAuthorizedFilesForAuthorizedUser(self): """ If the user is in the user database provided to L{checkers.UNIXAuthorizedKeysFiles}, an iterator with all the keys in C{~/.ssh/authorized_keys} and C{~/.ssh/authorized_keys2} is returned by L{checkers.UNIXAuthorizedKeysFiles.getAuthorizedKeys}. """ self.sshDir.child('authorized_keys2').setContent(b'key 3') keydb = checkers.UNIXAuthorizedKeysFiles(self.userdb, parseKey=lambda x: x) self.assertEqual(self.expectedKeys + [b'key 3'], list(keydb.getAuthorizedKeys(b'alice')))
If the user is in the user database provided to L{checkers.UNIXAuthorizedKeysFiles}, an iterator with all the keys in C{~/.ssh/authorized_keys} and C{~/.ssh/authorized_keys2} is returned by L{checkers.UNIXAuthorizedKeysFiles.getAuthorizedKeys}.
test_allKeysInAllAuthorizedFilesForAuthorizedUser
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py
MIT
def test_ignoresNonexistantFile(self): """ L{checkers.UNIXAuthorizedKeysFiles.getAuthorizedKeys} returns only the keys in C{~/.ssh/authorized_keys} and C{~/.ssh/authorized_keys2} if they exist. """ keydb = checkers.UNIXAuthorizedKeysFiles(self.userdb, parseKey=lambda x: x) self.assertEqual(self.expectedKeys, list(keydb.getAuthorizedKeys(b'alice')))
L{checkers.UNIXAuthorizedKeysFiles.getAuthorizedKeys} returns only the keys in C{~/.ssh/authorized_keys} and C{~/.ssh/authorized_keys2} if they exist.
test_ignoresNonexistantFile
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py
MIT
def test_ignoresUnreadableFile(self): """ L{checkers.UNIXAuthorizedKeysFiles.getAuthorizedKeys} returns only the keys in C{~/.ssh/authorized_keys} and C{~/.ssh/authorized_keys2} if they are readable. """ self.sshDir.child('authorized_keys2').makedirs() keydb = checkers.UNIXAuthorizedKeysFiles(self.userdb, parseKey=lambda x: x) self.assertEqual(self.expectedKeys, list(keydb.getAuthorizedKeys(b'alice')))
L{checkers.UNIXAuthorizedKeysFiles.getAuthorizedKeys} returns only the keys in C{~/.ssh/authorized_keys} and C{~/.ssh/authorized_keys2} if they are readable.
test_ignoresUnreadableFile
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py
MIT
def test_credentialsWithoutSignature(self): """ Calling L{checkers.SSHPublicKeyChecker.requestAvatarId} with credentials that do not have a signature fails with L{ValidPublicKey}. """ self.credentials.signature = None self.failureResultOf(self.checker.requestAvatarId(self.credentials), ValidPublicKey)
Calling L{checkers.SSHPublicKeyChecker.requestAvatarId} with credentials that do not have a signature fails with L{ValidPublicKey}.
test_credentialsWithoutSignature
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py
MIT
def test_credentialsWithBadKey(self): """ Calling L{checkers.SSHPublicKeyChecker.requestAvatarId} with credentials that have a bad key fails with L{keys.BadKeyError}. """ self.credentials.blob = b'' self.failureResultOf(self.checker.requestAvatarId(self.credentials), keys.BadKeyError)
Calling L{checkers.SSHPublicKeyChecker.requestAvatarId} with credentials that have a bad key fails with L{keys.BadKeyError}.
test_credentialsWithBadKey
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py
MIT
def test_credentialsNoMatchingKey(self): """ If L{checkers.IAuthorizedKeysDB.getAuthorizedKeys} returns no keys that match the credentials, L{checkers.SSHPublicKeyChecker.requestAvatarId} fails with L{UnauthorizedLogin}. """ self.credentials.blob = keydata.publicDSA_openssh self.failureResultOf(self.checker.requestAvatarId(self.credentials), UnauthorizedLogin)
If L{checkers.IAuthorizedKeysDB.getAuthorizedKeys} returns no keys that match the credentials, L{checkers.SSHPublicKeyChecker.requestAvatarId} fails with L{UnauthorizedLogin}.
test_credentialsNoMatchingKey
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py
MIT
def test_credentialsInvalidSignature(self): """ Calling L{checkers.SSHPublicKeyChecker.requestAvatarId} with credentials that are incorrectly signed fails with L{UnauthorizedLogin}. """ self.credentials.signature = ( keys.Key.fromString(keydata.privateDSA_openssh).sign(b'foo')) self.failureResultOf(self.checker.requestAvatarId(self.credentials), UnauthorizedLogin)
Calling L{checkers.SSHPublicKeyChecker.requestAvatarId} with credentials that are incorrectly signed fails with L{UnauthorizedLogin}.
test_credentialsInvalidSignature
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py
MIT
def test_failureVerifyingKey(self): """ If L{keys.Key.verify} raises an exception, L{checkers.SSHPublicKeyChecker.requestAvatarId} fails with L{UnauthorizedLogin}. """ def fail(*args, **kwargs): raise _DummyException() self.patch(keys.Key, 'verify', fail) self.failureResultOf(self.checker.requestAvatarId(self.credentials), UnauthorizedLogin) self.flushLoggedErrors(_DummyException)
If L{keys.Key.verify} raises an exception, L{checkers.SSHPublicKeyChecker.requestAvatarId} fails with L{UnauthorizedLogin}.
test_failureVerifyingKey
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py
MIT
def test_usernameReturnedOnSuccess(self): """ L{checker.SSHPublicKeyChecker.requestAvatarId}, if successful, callbacks with the username. """ d = self.checker.requestAvatarId(self.credentials) self.assertEqual(b'alice', self.successResultOf(d))
L{checker.SSHPublicKeyChecker.requestAvatarId}, if successful, callbacks with the username.
test_usernameReturnedOnSuccess
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py
MIT
def logPrefix(self): """ Return our logging prefix. """ return "MockConnection"
Return our logging prefix.
logPrefix
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_channel.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_channel.py
MIT
def sendData(self, channel, data): """ Record the sent data. """ self.data.setdefault(channel, []).append(data)
Record the sent data.
sendData
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_channel.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_channel.py
MIT
def sendExtendedData(self, channel, type, data): """ Record the sent extended data. """ self.extData.setdefault(channel, []).append((type, data))
Record the sent extended data.
sendExtendedData
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_channel.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_channel.py
MIT
def sendClose(self, channel): """ Record that the channel sent a close message. """ self.closes[channel] = True
Record that the channel sent a close message.
sendClose
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_channel.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_channel.py
MIT
def connectSSHTransport(service, hostAddress=None, peerAddress=None): """ Connect a SSHTransport which is already connected to a remote peer to the channel under test. @param service: Service used over the connected transport. @type service: L{SSHService} @param hostAddress: Local address of the connected transport. @type hostAddress: L{interfaces.IAddress} @param peerAddress: Remote address of the connected transport. @type peerAddress: L{interfaces.IAddress} """ transport = SSHServerTransport() transport.makeConnection(StringTransport( hostAddress=hostAddress, peerAddress=peerAddress)) transport.setService(service)
Connect a SSHTransport which is already connected to a remote peer to the channel under test. @param service: Service used over the connected transport. @type service: L{SSHService} @param hostAddress: Local address of the connected transport. @type hostAddress: L{interfaces.IAddress} @param peerAddress: Remote address of the connected transport. @type peerAddress: L{interfaces.IAddress}
connectSSHTransport
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_channel.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_channel.py
MIT
def setUp(self): """ Initialize the channel. remoteMaxPacket is 10 so that data is able to be sent (the default of 0 means no data is sent because no packets are made). """ self.conn = MockConnection() self.channel = channel.SSHChannel(conn=self.conn, remoteMaxPacket=10) self.channel.name = b'channel'
Initialize the channel. remoteMaxPacket is 10 so that data is able to be sent (the default of 0 means no data is sent because no packets are made).
setUp
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_channel.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_channel.py
MIT
def test_interface(self): """ L{SSHChannel} instances provide L{interfaces.ITransport}. """ self.assertTrue(verifyObject(interfaces.ITransport, self.channel))
L{SSHChannel} instances provide L{interfaces.ITransport}.
test_interface
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_channel.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_channel.py
MIT
def test_init(self): """ Test that SSHChannel initializes correctly. localWindowSize defaults to 131072 (2**17) and localMaxPacket to 32768 (2**15) as reasonable defaults (what OpenSSH uses for those variables). The values in the second set of assertions are meaningless; they serve only to verify that the instance variables are assigned in the correct order. """ c = channel.SSHChannel(conn=self.conn) self.assertEqual(c.localWindowSize, 131072) self.assertEqual(c.localWindowLeft, 131072) self.assertEqual(c.localMaxPacket, 32768) self.assertEqual(c.remoteWindowLeft, 0) self.assertEqual(c.remoteMaxPacket, 0) self.assertEqual(c.conn, self.conn) self.assertIsNone(c.data) self.assertIsNone(c.avatar) c2 = channel.SSHChannel(1, 2, 3, 4, 5, 6, 7) self.assertEqual(c2.localWindowSize, 1) self.assertEqual(c2.localWindowLeft, 1) self.assertEqual(c2.localMaxPacket, 2) self.assertEqual(c2.remoteWindowLeft, 3) self.assertEqual(c2.remoteMaxPacket, 4) self.assertEqual(c2.conn, 5) self.assertEqual(c2.data, 6) self.assertEqual(c2.avatar, 7)
Test that SSHChannel initializes correctly. localWindowSize defaults to 131072 (2**17) and localMaxPacket to 32768 (2**15) as reasonable defaults (what OpenSSH uses for those variables). The values in the second set of assertions are meaningless; they serve only to verify that the instance variables are assigned in the correct order.
test_init
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_channel.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_channel.py
MIT
def test_str(self): """ Test that str(SSHChannel) works gives the channel name and local and remote windows at a glance.. """ self.assertEqual( str(self.channel), '<SSHChannel channel (lw 131072 rw 0)>') self.assertEqual( str(channel.SSHChannel(localWindow=1)), '<SSHChannel None (lw 1 rw 0)>')
Test that str(SSHChannel) works gives the channel name and local and remote windows at a glance..
test_str
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_channel.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_channel.py
MIT
def test_bytes(self): """ Test that bytes(SSHChannel) works, gives the channel name and local and remote windows at a glance.. """ self.assertEqual( self.channel.__bytes__(), b'<SSHChannel channel (lw 131072 rw 0)>') self.assertEqual( channel.SSHChannel(localWindow=1).__bytes__(), b'<SSHChannel None (lw 1 rw 0)>')
Test that bytes(SSHChannel) works, gives the channel name and local and remote windows at a glance..
test_bytes
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_channel.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_channel.py
MIT
def test_logPrefix(self): """ Test that SSHChannel.logPrefix gives the name of the channel, the local channel ID and the underlying connection. """ self.assertEqual(self.channel.logPrefix(), 'SSHChannel channel ' '(unknown) on MockConnection')
Test that SSHChannel.logPrefix gives the name of the channel, the local channel ID and the underlying connection.
test_logPrefix
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_channel.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_channel.py
MIT
def test_addWindowBytes(self): """ Test that addWindowBytes adds bytes to the window and resumes writing if it was paused. """ cb = [False] def stubStartWriting(): cb[0] = True self.channel.startWriting = stubStartWriting self.channel.write(b'test') self.channel.writeExtended(1, b'test') self.channel.addWindowBytes(50) self.assertEqual(self.channel.remoteWindowLeft, 50 - 4 - 4) self.assertTrue(self.channel.areWriting) self.assertTrue(cb[0]) self.assertEqual(self.channel.buf, b'') self.assertEqual(self.conn.data[self.channel], [b'test']) self.assertEqual(self.channel.extBuf, []) self.assertEqual(self.conn.extData[self.channel], [(1, b'test')]) cb[0] = False self.channel.addWindowBytes(20) self.assertFalse(cb[0]) self.channel.write(b'a'*80) self.channel.loseConnection() self.channel.addWindowBytes(20) self.assertFalse(cb[0])
Test that addWindowBytes adds bytes to the window and resumes writing if it was paused.
test_addWindowBytes
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_channel.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_channel.py
MIT
def test_requestReceived(self): """ Test that requestReceived handles requests by dispatching them to request_* methods. """ self.channel.request_test_method = lambda data: data == b'' self.assertTrue(self.channel.requestReceived(b'test-method', b'')) self.assertFalse(self.channel.requestReceived(b'test-method', b'a')) self.assertFalse(self.channel.requestReceived(b'bad-method', b''))
Test that requestReceived handles requests by dispatching them to request_* methods.
test_requestReceived
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_channel.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_channel.py
MIT
def test_closeReceieved(self): """ Test that the default closeReceieved closes the connection. """ self.assertFalse(self.channel.closing) self.channel.closeReceived() self.assertTrue(self.channel.closing)
Test that the default closeReceieved closes the connection.
test_closeReceieved
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_channel.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_channel.py
MIT
def test_write(self): """ Test that write handles data correctly. Send data up to the size of the remote window, splitting the data into packets of length remoteMaxPacket. """ cb = [False] def stubStopWriting(): cb[0] = True # no window to start with self.channel.stopWriting = stubStopWriting self.channel.write(b'd') self.channel.write(b'a') self.assertFalse(self.channel.areWriting) self.assertTrue(cb[0]) # regular write self.channel.addWindowBytes(20) self.channel.write(b'ta') data = self.conn.data[self.channel] self.assertEqual(data, [b'da', b'ta']) self.assertEqual(self.channel.remoteWindowLeft, 16) # larger than max packet self.channel.write(b'12345678901') self.assertEqual(data, [b'da', b'ta', b'1234567890', b'1']) self.assertEqual(self.channel.remoteWindowLeft, 5) # running out of window cb[0] = False self.channel.write(b'123456') self.assertFalse(self.channel.areWriting) self.assertTrue(cb[0]) self.assertEqual(data, [b'da', b'ta', b'1234567890', b'1', b'12345']) self.assertEqual(self.channel.buf, b'6') self.assertEqual(self.channel.remoteWindowLeft, 0)
Test that write handles data correctly. Send data up to the size of the remote window, splitting the data into packets of length remoteMaxPacket.
test_write
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_channel.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_channel.py
MIT
def test_writeExtended(self): """ Test that writeExtended handles data correctly. Send extended data up to the size of the window, splitting the extended data into packets of length remoteMaxPacket. """ cb = [False] def stubStopWriting(): cb[0] = True # no window to start with self.channel.stopWriting = stubStopWriting self.channel.writeExtended(1, b'd') self.channel.writeExtended(1, b'a') self.channel.writeExtended(2, b't') self.assertFalse(self.channel.areWriting) self.assertTrue(cb[0]) # regular write self.channel.addWindowBytes(20) self.channel.writeExtended(2, b'a') data = self.conn.extData[self.channel] self.assertEqual(data, [(1, b'da'), (2, b't'), (2, b'a')]) self.assertEqual(self.channel.remoteWindowLeft, 16) # larger than max packet self.channel.writeExtended(3, b'12345678901') self.assertEqual(data, [(1, b'da'), (2, b't'), (2, b'a'), (3, b'1234567890'), (3, b'1')]) self.assertEqual(self.channel.remoteWindowLeft, 5) # running out of window cb[0] = False self.channel.writeExtended(4, b'123456') self.assertFalse(self.channel.areWriting) self.assertTrue(cb[0]) self.assertEqual(data, [(1, b'da'), (2, b't'), (2, b'a'), (3, b'1234567890'), (3, b'1'), (4, b'12345')]) self.assertEqual(self.channel.extBuf, [[4, b'6']]) self.assertEqual(self.channel.remoteWindowLeft, 0)
Test that writeExtended handles data correctly. Send extended data up to the size of the window, splitting the extended data into packets of length remoteMaxPacket.
test_writeExtended
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_channel.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_channel.py
MIT
def test_writeSequence(self): """ Test that writeSequence is equivalent to write(''.join(sequece)). """ self.channel.addWindowBytes(20) self.channel.writeSequence(map(intToBytes, range(10))) self.assertEqual(self.conn.data[self.channel], [b'0123456789'])
Test that writeSequence is equivalent to write(''.join(sequece)).
test_writeSequence
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_channel.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_channel.py
MIT
def test_loseConnection(self): """ Tesyt that loseConnection() doesn't close the channel until all the data is sent. """ self.channel.write(b'data') self.channel.writeExtended(1, b'datadata') self.channel.loseConnection() self.assertIsNone(self.conn.closes.get(self.channel)) self.channel.addWindowBytes(4) # send regular data self.assertIsNone(self.conn.closes.get(self.channel)) self.channel.addWindowBytes(8) # send extended data self.assertTrue(self.conn.closes.get(self.channel))
Tesyt that loseConnection() doesn't close the channel until all the data is sent.
test_loseConnection
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_channel.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_channel.py
MIT
def test_getPeer(self): """ L{SSHChannel.getPeer} returns the same object as the underlying transport's C{getPeer} method returns. """ peer = IPv4Address('TCP', '192.168.0.1', 54321) connectSSHTransport(service=self.channel.conn, peerAddress=peer) self.assertEqual(SSHTransportAddress(peer), self.channel.getPeer())
L{SSHChannel.getPeer} returns the same object as the underlying transport's C{getPeer} method returns.
test_getPeer
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_channel.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_channel.py
MIT
def test_getHost(self): """ L{SSHChannel.getHost} returns the same object as the underlying transport's C{getHost} method returns. """ host = IPv4Address('TCP', '127.0.0.1', 12345) connectSSHTransport(service=self.channel.conn, hostAddress=host) self.assertEqual(SSHTransportAddress(host), self.channel.getHost())
L{SSHChannel.getHost} returns the same object as the underlying transport's C{getHost} method returns.
test_getHost
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_channel.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_channel.py
MIT
def test_eofReceived(self): """ L{twisted.conch.scripts.cftp.SSHSession.eofReceived} loses the write half of its stdio connection. """ stdio = FakeStdio() channel = SSHSession() channel.stdio = stdio channel.eofReceived() self.assertTrue(stdio.writeConnLost)
L{twisted.conch.scripts.cftp.SSHSession.eofReceived} loses the write half of its stdio connection.
test_eofReceived
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
MIT
def setUp(self): """ Patch the L{ls} module's time function so the results of L{lsLine} are deterministic. """ self.now = 123456789 def fakeTime(): return self.now self.patch(ls, 'time', fakeTime) # Make sure that the timezone ends up the same after these tests as # it was before. if 'TZ' in os.environ: self.addCleanup(operator.setitem, os.environ, 'TZ', os.environ['TZ']) self.addCleanup(time.tzset) else: def cleanup(): # os.environ.pop is broken! Don't use it! Ever! Or die! try: del os.environ['TZ'] except KeyError: pass time.tzset() self.addCleanup(cleanup)
Patch the L{ls} module's time function so the results of L{lsLine} are deterministic.
setUp
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
MIT
def _lsInTimezone(self, timezone, stat): """ Call L{ls.lsLine} after setting the timezone to C{timezone} and return the result. """ # Set the timezone to a well-known value so the timestamps are # predictable. os.environ['TZ'] = timezone time.tzset() return ls.lsLine('foo', stat)
Call L{ls.lsLine} after setting the timezone to C{timezone} and return the result.
_lsInTimezone
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
MIT
def test_oldFile(self): """ A file with an mtime six months (approximately) or more in the past has a listing including a low-resolution timestamp. """ # Go with 7 months. That's more than 6 months. then = self.now - (60 * 60 * 24 * 31 * 7) stat = os.stat_result((0, 0, 0, 0, 0, 0, 0, 0, then, 0)) self.assertEqual( self._lsInTimezone('America/New_York', stat), '!--------- 0 0 0 0 Apr 26 1973 foo') self.assertEqual( self._lsInTimezone('Pacific/Auckland', stat), '!--------- 0 0 0 0 Apr 27 1973 foo')
A file with an mtime six months (approximately) or more in the past has a listing including a low-resolution timestamp.
test_oldFile
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
MIT
def test_oldSingleDigitDayOfMonth(self): """ A file with a high-resolution timestamp which falls on a day of the month which can be represented by one decimal digit is formatted with one padding 0 to preserve the columns which come after it. """ # A point about 7 months in the past, tweaked to fall on the first of a # month so we test the case we want to test. then = self.now - (60 * 60 * 24 * 31 * 7) + (60 * 60 * 24 * 5) stat = os.stat_result((0, 0, 0, 0, 0, 0, 0, 0, then, 0)) self.assertEqual( self._lsInTimezone('America/New_York', stat), '!--------- 0 0 0 0 May 01 1973 foo') self.assertEqual( self._lsInTimezone('Pacific/Auckland', stat), '!--------- 0 0 0 0 May 02 1973 foo')
A file with a high-resolution timestamp which falls on a day of the month which can be represented by one decimal digit is formatted with one padding 0 to preserve the columns which come after it.
test_oldSingleDigitDayOfMonth
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
MIT
def test_newFile(self): """ A file with an mtime fewer than six months (approximately) in the past has a listing including a high-resolution timestamp excluding the year. """ # A point about three months in the past. then = self.now - (60 * 60 * 24 * 31 * 3) stat = os.stat_result((0, 0, 0, 0, 0, 0, 0, 0, then, 0)) self.assertEqual( self._lsInTimezone('America/New_York', stat), '!--------- 0 0 0 0 Aug 28 17:33 foo') self.assertEqual( self._lsInTimezone('Pacific/Auckland', stat), '!--------- 0 0 0 0 Aug 29 09:33 foo')
A file with an mtime fewer than six months (approximately) in the past has a listing including a high-resolution timestamp excluding the year.
test_newFile
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
MIT
def test_localeIndependent(self): """ The month name in the date is locale independent. """ # A point about three months in the past. then = self.now - (60 * 60 * 24 * 31 * 3) stat = os.stat_result((0, 0, 0, 0, 0, 0, 0, 0, then, 0)) # Fake that we're in a language where August is not Aug (e.g.: Spanish) currentLocale = locale.getlocale() locale.setlocale(locale.LC_ALL, "es_AR.UTF8") self.addCleanup(locale.setlocale, locale.LC_ALL, currentLocale) self.assertEqual( self._lsInTimezone('America/New_York', stat), '!--------- 0 0 0 0 Aug 28 17:33 foo') self.assertEqual( self._lsInTimezone('Pacific/Auckland', stat), '!--------- 0 0 0 0 Aug 29 09:33 foo')
The month name in the date is locale independent.
test_localeIndependent
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
MIT
def test_newSingleDigitDayOfMonth(self): """ A file with a high-resolution timestamp which falls on a day of the month which can be represented by one decimal digit is formatted with one padding 0 to preserve the columns which come after it. """ # A point about three months in the past, tweaked to fall on the first # of a month so we test the case we want to test. then = self.now - (60 * 60 * 24 * 31 * 3) + (60 * 60 * 24 * 4) stat = os.stat_result((0, 0, 0, 0, 0, 0, 0, 0, then, 0)) self.assertEqual( self._lsInTimezone('America/New_York', stat), '!--------- 0 0 0 0 Sep 01 17:33 foo') self.assertEqual( self._lsInTimezone('Pacific/Auckland', stat), '!--------- 0 0 0 0 Sep 02 09:33 foo')
A file with a high-resolution timestamp which falls on a day of the month which can be represented by one decimal digit is formatted with one padding 0 to preserve the columns which come after it.
test_newSingleDigitDayOfMonth
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
MIT
def __init__(self, conn): """ @param conn: The SSH connection associated with this channel. @type conn: L{SSHConnection} """ self.conn = conn self.localClosed = 0 super(InMemorySSHChannel, self).__init__()
@param conn: The SSH connection associated with this channel. @type conn: L{SSHConnection}
__init__
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
MIT
def put(self, path, flags, stream): """ @param path: Path at which the stream is requested. @type path: L{str} @param path: Flags with which the stream is requested. @type path: L{str} @param stream: A stream. @type stream: C{File} """ self._cache[(path, flags)] = stream
@param path: Path at which the stream is requested. @type path: L{str} @param path: Flags with which the stream is requested. @type path: L{str} @param stream: A stream. @type stream: C{File}
put
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
MIT
def pop(self, path, flags): """ Remove a stream from the memory. @param path: Path at which the stream is requested. @type path: L{str} @param path: Flags with which the stream is requested. @type path: L{str} @return: A stream. @rtype: C{File} """ return self._cache.pop((path, flags))
Remove a stream from the memory. @param path: Path at which the stream is requested. @type path: L{str} @param path: Flags with which the stream is requested. @type path: L{str} @return: A stream. @rtype: C{File}
pop
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
MIT
def openFile(self, filename, flags, attrs): """ @see: L{filetransfer.FileTransferClient.openFile}. Retrieve and remove cached file based on flags. """ return self._availableFiles.pop(filename, flags)
@see: L{filetransfer.FileTransferClient.openFile}. Retrieve and remove cached file based on flags.
openFile
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
MIT
def __init__(self, name): """ @param name: Name of this file. @type name: L{str} """ self.name = name BytesIO.__init__(self)
@param name: Name of this file. @type name: L{str}
__init__
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
MIT
def writeChunk(self, start, data): """ @see: L{ISFTPFile.writeChunk} """ self.seek(start) self.write(data) return defer.succeed(self)
@see: L{ISFTPFile.writeChunk}
writeChunk
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
MIT
def close(self): """ @see: L{ISFTPFile.writeChunk} Keeps data after file was closed to help with testing. """ self._closed = True
@see: L{ISFTPFile.writeChunk} Keeps data after file was closed to help with testing.
close
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
MIT
def getvalue(self): """ Get current data of file. Allow reading data event when file is closed. """ return BytesIO.getvalue(self)
Get current data of file. Allow reading data event when file is closed.
getvalue
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
MIT
def setUp(self): """ Create a L{cftp.StdioClient} hooked up to dummy transport and a fake user database. """ self.fakeFilesystem = FilesystemAccessExpectations() sftpClient = InMemorySFTPClient(self.fakeFilesystem ) self.client = cftp.StdioClient(sftpClient) self.client.currentDirectory = '/' self.database = self.client._pwd = UserDatabase() # Use a fixed width for all tests so that we get the same results when # running these tests from different terminals. # Run tests in a wide console so that all items are delimited by at # least one space character. self.setKnownConsoleSize(500, 24) # Intentionally bypassing makeConnection - that triggers some code # which uses features not provided by our dumb Connection fake. self.client.transport = self.client.client.transport
Create a L{cftp.StdioClient} hooked up to dummy transport and a fake user database.
setUp
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
MIT
def test_exec(self): """ The I{exec} command runs its arguments locally in a child process using the user's shell. """ self.database.addUser( getpass.getuser(), 'secret', os.getuid(), 1234, 'foo', 'bar', sys.executable) d = self.client._dispatchCommand("exec print(1 + 2)") d.addCallback(self.assertEqual, b"3\n") return d
The I{exec} command runs its arguments locally in a child process using the user's shell.
test_exec
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
MIT
def test_execWithoutShell(self): """ If the local user has no shell, the I{exec} command runs its arguments using I{/bin/sh}. """ self.database.addUser( getpass.getuser(), 'secret', os.getuid(), 1234, 'foo', 'bar', '') d = self.client._dispatchCommand("exec echo hello") d.addCallback(self.assertEqual, b"hello\n") return d
If the local user has no shell, the I{exec} command runs its arguments using I{/bin/sh}.
test_execWithoutShell
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
MIT
def test_bang(self): """ The I{exec} command is run for lines which start with C{"!"}. """ self.database.addUser( getpass.getuser(), 'secret', os.getuid(), 1234, 'foo', 'bar', '/bin/sh') d = self.client._dispatchCommand("!echo hello") d.addCallback(self.assertEqual, b"hello\n") return d
The I{exec} command is run for lines which start with C{"!"}.
test_bang
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
MIT
def setKnownConsoleSize(self, width, height): """ For the duration of this test, patch C{cftp}'s C{fcntl} module to return a fixed width and height. @param width: the width in characters @type width: L{int} @param height: the height in characters @type height: L{int} """ # Local import to avoid win32 issues. import tty class FakeFcntl(object): def ioctl(self, fd, opt, mutate): if opt != tty.TIOCGWINSZ: self.fail("Only window-size queries supported.") return struct.pack("4H", height, width, 0, 0) self.patch(cftp, "fcntl", FakeFcntl())
For the duration of this test, patch C{cftp}'s C{fcntl} module to return a fixed width and height. @param width: the width in characters @type width: L{int} @param height: the height in characters @type height: L{int}
setKnownConsoleSize
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
MIT
def test_printProgressBarReporting(self): """ L{StdioClient._printProgressBar} prints a progress description, including percent done, amount transferred, transfer rate, and time remaining, all based the given start time, the given L{FileWrapper}'s progress information and the reactor's current time. """ # Use a short, known console width because this simple test doesn't # need to test the console padding. self.setKnownConsoleSize(10, 34) clock = self.client.reactor = Clock() wrapped = BytesIO(b"x") wrapped.name = b"sample" wrapper = cftp.FileWrapper(wrapped) wrapper.size = 1024 * 10 startTime = clock.seconds() clock.advance(2.0) wrapper.total += 4096 self.client._printProgressBar(wrapper, startTime) if _PY3: result = b"\rb'sample' 40% 4.0kB 2.0kBps 00:03 " else: result = "\rsample 40% 4.0kB 2.0kBps 00:03 " self.assertEqual(self.client.transport.value(), result)
L{StdioClient._printProgressBar} prints a progress description, including percent done, amount transferred, transfer rate, and time remaining, all based the given start time, the given L{FileWrapper}'s progress information and the reactor's current time.
test_printProgressBarReporting
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
MIT
def test_printProgressBarNoProgress(self): """ L{StdioClient._printProgressBar} prints a progress description that indicates 0 bytes transferred if no bytes have been transferred and no time has passed. """ self.setKnownConsoleSize(10, 34) clock = self.client.reactor = Clock() wrapped = BytesIO(b"x") wrapped.name = b"sample" wrapper = cftp.FileWrapper(wrapped) startTime = clock.seconds() self.client._printProgressBar(wrapper, startTime) if _PY3: result = b"\rb'sample' 0% 0.0B 0.0Bps 00:00 " else: result = "\rsample 0% 0.0B 0.0Bps 00:00 " self.assertEqual(self.client.transport.value(), result)
L{StdioClient._printProgressBar} prints a progress description that indicates 0 bytes transferred if no bytes have been transferred and no time has passed.
test_printProgressBarNoProgress
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
MIT
def test_printProgressBarEmptyFile(self): """ Print the progress for empty files. """ self.setKnownConsoleSize(10, 34) wrapped = BytesIO() wrapped.name = b'empty-file' wrapper = cftp.FileWrapper(wrapped) self.client._printProgressBar(wrapper, 0) if _PY3: result = b"\rb'empty-file'100% 0.0B 0.0Bps 00:00 " else: result = "\rempty-file100% 0.0B 0.0Bps 00:00 " self.assertEqual(result, self.client.transport.value())
Print the progress for empty files.
test_printProgressBarEmptyFile
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
MIT
def test_getFilenameEmpty(self): """ Returns empty value for both filename and remaining data. """ result = self.client._getFilename(' ') self.assertEqual(('', ''), result)
Returns empty value for both filename and remaining data.
test_getFilenameEmpty
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
MIT
def test_getFilenameOnlyLocal(self): """ Returns empty value for remaining data when line contains only a filename. """ result = self.client._getFilename('only-local') self.assertEqual(('only-local', ''), result)
Returns empty value for remaining data when line contains only a filename.
test_getFilenameOnlyLocal
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
MIT
def test_getFilenameNotQuoted(self): """ Returns filename and remaining data striped of leading and trailing spaces. """ result = self.client._getFilename(' local remote file ') self.assertEqual(('local', 'remote file'), result)
Returns filename and remaining data striped of leading and trailing spaces.
test_getFilenameNotQuoted
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
MIT
def test_getFilenameQuoted(self): """ Returns filename and remaining data not striped of leading and trailing spaces when quoted paths are requested. """ result = self.client._getFilename(' " local file " " remote file " ') self.assertEqual((' local file ', '" remote file "'), result)
Returns filename and remaining data not striped of leading and trailing spaces when quoted paths are requested.
test_getFilenameQuoted
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
MIT
def makeFile(self, path=None, content=b''): """ Create a local file and return its path. When `path` is L{None}, it will create a new temporary file. @param path: Optional path for the new file. @type path: L{str} @param content: Content to be written in the new file. @type content: L{bytes} @return: Path to the newly create file. """ if path is None: path = self.mktemp() with open(path, 'wb') as file: file.write(content) return path
Create a local file and return its path. When `path` is L{None}, it will create a new temporary file. @param path: Optional path for the new file. @type path: L{str} @param content: Content to be written in the new file. @type content: L{bytes} @return: Path to the newly create file.
makeFile
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
MIT
def checkPutMessage(self, transfers, randomOrder=False): """ Check output of cftp client for a put request. @param transfers: List with tuple of (local, remote, progress). @param randomOrder: When set to C{True}, it will ignore the order in which put reposes are received """ output = self.client.transport.value() if _PY3: output = output.decode("utf-8") output = output.split('\n\r') expectedOutput = [] actualOutput = [] for local, remote, expected in transfers: # For each transfer we have a list of reported progress which # ends with the final message informing that file was transferred. expectedTransfer = [] for line in expected: expectedTransfer.append('%s %s' % (local, line)) expectedTransfer.append('Transferred %s to %s' % (local, remote)) expectedOutput.append(expectedTransfer) progressParts = output.pop(0).strip('\r').split('\r') actual = progressParts[:-1] last = progressParts[-1].strip('\n').split('\n') actual.extend(last) actualTransfer = [] # Each transferred file is on a line with summary on the last # line. Summary is copying at the end. for line in actual[:-1]: # Output line is in the format # NAME PROGRESS_PERCENTAGE PROGRESS_BYTES SPEED ETA. # For testing we only care about the # PROGRESS_PERCENTAGE and PROGRESS values. # Ignore SPPED and ETA. line = line.strip().rsplit(' ', 2)[0] # NAME can be followed by a lot of spaces so we need to # reduce them to single space. line = line.strip().split(' ', 1) actualTransfer.append('%s %s' % (line[0], line[1].strip())) actualTransfer.append(actual[-1]) actualOutput.append(actualTransfer) if randomOrder: self.assertEqual(sorted(expectedOutput), sorted(actualOutput)) else: self.assertEqual(expectedOutput, actualOutput) self.assertEqual( 0, len(output), 'There are still put responses which were not checked.', )
Check output of cftp client for a put request. @param transfers: List with tuple of (local, remote, progress). @param randomOrder: When set to C{True}, it will ignore the order in which put reposes are received
checkPutMessage
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
MIT
def test_cmd_PUTSingleNoRemotePath(self): """ A name based on local path is used when remote path is not provided. The progress is updated while chunks are transferred. """ content = b'Test\r\nContent' localPath = self.makeFile(content=content) flags = ( filetransfer.FXF_WRITE | filetransfer.FXF_CREAT | filetransfer.FXF_TRUNC ) remoteName = os.path.join('/', os.path.basename(localPath)) remoteFile = InMemoryRemoteFile(remoteName) self.fakeFilesystem.put(remoteName, flags, defer.succeed(remoteFile)) self.client.client.options['buffersize'] = 10 deferred = self.client.cmd_PUT(localPath) self.successResultOf(deferred) self.assertEqual(content, remoteFile.getvalue()) self.assertTrue(remoteFile._closed) self.checkPutMessage( [(localPath, remoteName, ['76% 10.0B', '100% 13.0B', '100% 13.0B'])])
A name based on local path is used when remote path is not provided. The progress is updated while chunks are transferred.
test_cmd_PUTSingleNoRemotePath
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
MIT
def test_cmd_PUTSingleRemotePath(self): """ Remote path is extracted from first filename after local file. Any other data in the line is ignored. """ localPath = self.makeFile() flags = ( filetransfer.FXF_WRITE | filetransfer.FXF_CREAT | filetransfer.FXF_TRUNC ) remoteName = '/remote-path' remoteFile = InMemoryRemoteFile(remoteName) self.fakeFilesystem.put(remoteName, flags, defer.succeed(remoteFile)) deferred = self.client.cmd_PUT( '%s %s ignored' % (localPath, remoteName)) self.successResultOf(deferred) self.checkPutMessage([(localPath, remoteName, ['100% 0.0B'])]) self.assertTrue(remoteFile._closed) self.assertEqual(b'', remoteFile.getvalue())
Remote path is extracted from first filename after local file. Any other data in the line is ignored.
test_cmd_PUTSingleRemotePath
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
MIT
def test_cmd_PUTMultipleNoRemotePath(self): """ When a gobbing expression is used local files are transferred with remote file names based on local names. """ first = self.makeFile() firstName = os.path.basename(first) secondName = 'second-name' parent = os.path.dirname(first) second = self.makeFile(path=os.path.join(parent, secondName)) flags = ( filetransfer.FXF_WRITE | filetransfer.FXF_CREAT | filetransfer.FXF_TRUNC ) firstRemotePath = '/%s' % (firstName,) secondRemotePath = '/%s' % (secondName,) firstRemoteFile = InMemoryRemoteFile(firstRemotePath) secondRemoteFile = InMemoryRemoteFile(secondRemotePath) self.fakeFilesystem.put( firstRemotePath, flags, defer.succeed(firstRemoteFile)) self.fakeFilesystem.put( secondRemotePath, flags, defer.succeed(secondRemoteFile)) deferred = self.client.cmd_PUT(os.path.join(parent, '*')) self.successResultOf(deferred) self.assertTrue(firstRemoteFile._closed) self.assertEqual(b'', firstRemoteFile.getvalue()) self.assertTrue(secondRemoteFile._closed) self.assertEqual(b'', secondRemoteFile.getvalue()) self.checkPutMessage([ (first, firstRemotePath, ['100% 0.0B']), (second, secondRemotePath, ['100% 0.0B']), ], randomOrder=True, )
When a gobbing expression is used local files are transferred with remote file names based on local names.
test_cmd_PUTMultipleNoRemotePath
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
MIT
def test_cmd_PUTMultipleWithRemotePath(self): """ When a gobbing expression is used local files are transferred with remote file names based on local names. when a remote folder is requested remote paths are composed from remote path and local filename. """ first = self.makeFile() firstName = os.path.basename(first) secondName = 'second-name' parent = os.path.dirname(first) second = self.makeFile(path=os.path.join(parent, secondName)) flags = ( filetransfer.FXF_WRITE | filetransfer.FXF_CREAT | filetransfer.FXF_TRUNC ) firstRemoteFile = InMemoryRemoteFile(firstName) secondRemoteFile = InMemoryRemoteFile(secondName) firstRemotePath = '/remote/%s' % (firstName,) secondRemotePath = '/remote/%s' % (secondName,) self.fakeFilesystem.put( firstRemotePath, flags, defer.succeed(firstRemoteFile)) self.fakeFilesystem.put( secondRemotePath, flags, defer.succeed(secondRemoteFile)) deferred = self.client.cmd_PUT( '%s remote' % (os.path.join(parent, '*'),)) self.successResultOf(deferred) self.assertTrue(firstRemoteFile._closed) self.assertEqual(b'', firstRemoteFile.getvalue()) self.assertTrue(secondRemoteFile._closed) self.assertEqual(b'', secondRemoteFile.getvalue()) self.checkPutMessage([ (first, firstName, ['100% 0.0B']), (second, secondName, ['100% 0.0B']), ], randomOrder=True, )
When a gobbing expression is used local files are transferred with remote file names based on local names. when a remote folder is requested remote paths are composed from remote path and local filename.
test_cmd_PUTMultipleWithRemotePath
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
MIT
def __init__(self, onOutReceived): """ @param onOutReceived: A L{Deferred} to be fired as soon as data is received from stdout. """ self.clearBuffer() self.onOutReceived = onOutReceived self.onProcessEnd = None self._expectingCommand = None self._processEnded = False
@param onOutReceived: A L{Deferred} to be fired as soon as data is received from stdout.
__init__
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
MIT
def clearBuffer(self): """ Clear any buffered data received from stdout. Should be private. """ self.buffer = b'' self._linesReceived = [] self._lineBuffer = b''
Clear any buffered data received from stdout. Should be private.
clearBuffer
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
MIT
def outReceived(self, data): """ Called by Twisted when the cftp client prints data to stdout. """ log.msg('got %r' % data) lines = (self._lineBuffer + data).split(b'\n') self._lineBuffer = lines.pop(-1) self._linesReceived.extend(lines) # XXX - not strictly correct. # We really want onOutReceived to fire after the first 'cftp>' prompt # has been received. (See use in OurServerCmdLineClientTests.setUp) if self.onOutReceived is not None: d, self.onOutReceived = self.onOutReceived, None d.callback(data) self.buffer += data self._checkForCommand()
Called by Twisted when the cftp client prints data to stdout.
outReceived
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
MIT
def errReceived(self, data): """ Called by Twisted when the cftp client prints data to stderr. """ log.msg('err: %s' % data)
Called by Twisted when the cftp client prints data to stderr.
errReceived
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
MIT
def getBuffer(self): """ Return the contents of the buffer of data received from stdout. """ return self.buffer
Return the contents of the buffer of data received from stdout.
getBuffer
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
MIT
def runCommand(self, command): """ Issue the given command via the cftp client. Return a C{Deferred} that fires when the server returns a result. Note that the C{Deferred} will callback even if the server returns some kind of error. @param command: A string containing an sftp command. @return: A C{Deferred} that fires when the sftp server returns a result. The payload is the server's response string. """ self._expectingCommand = defer.Deferred() self.clearBuffer() if isinstance(command, unicode): command = command.encode("utf-8") self.transport.write(command + b'\n') return self._expectingCommand
Issue the given command via the cftp client. Return a C{Deferred} that fires when the server returns a result. Note that the C{Deferred} will callback even if the server returns some kind of error. @param command: A string containing an sftp command. @return: A C{Deferred} that fires when the sftp server returns a result. The payload is the server's response string.
runCommand
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
MIT
def runScript(self, commands): """ Run each command in sequence and return a Deferred that fires when all commands are completed. @param commands: A list of strings containing sftp commands. @return: A C{Deferred} that fires when all commands are completed. The payload is a list of response strings from the server, in the same order as the commands. """ sem = defer.DeferredSemaphore(1) dl = [sem.run(self.runCommand, command) for command in commands] return defer.gatherResults(dl)
Run each command in sequence and return a Deferred that fires when all commands are completed. @param commands: A list of strings containing sftp commands. @return: A C{Deferred} that fires when all commands are completed. The payload is a list of response strings from the server, in the same order as the commands.
runScript
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
MIT
def killProcess(self): """ Kill the process if it is still running. If the process is still running, sends a KILL signal to the transport and returns a C{Deferred} which fires when L{processEnded} is called. @return: a C{Deferred}. """ if self._processEnded: return defer.succeed(None) self.onProcessEnd = defer.Deferred() self.transport.signalProcess('KILL') return self.onProcessEnd
Kill the process if it is still running. If the process is still running, sends a KILL signal to the transport and returns a C{Deferred} which fires when L{processEnded} is called. @return: a C{Deferred}.
killProcess
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
MIT
def processEnded(self, reason): """ Called by Twisted when the cftp client process ends. """ self._processEnded = True if self.onProcessEnd: d, self.onProcessEnd = self.onProcessEnd, None d.callback(None)
Called by Twisted when the cftp client process ends.
processEnded
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
MIT
def runCommand(self, command): """ Run the given command with the cftp client. Return a C{Deferred} that fires when the command is complete. Payload is the server's output for that command. """ return self.processProtocol.runCommand(command)
Run the given command with the cftp client. Return a C{Deferred} that fires when the command is complete. Payload is the server's output for that command.
runCommand
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
MIT
def runScript(self, *commands): """ Run the given commands with the cftp client. Returns a C{Deferred} that fires when the commands are all complete. The C{Deferred}'s payload is a list of output for each command. """ return self.processProtocol.runScript(commands)
Run the given commands with the cftp client. Returns a C{Deferred} that fires when the commands are all complete. The C{Deferred}'s payload is a list of output for each command.
runScript
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
MIT
def cmdOutput(output): """ Callback function for handling command output. """ cmds = [] for cmd in output: if _PY3 and isinstance(cmd, bytes): cmd = cmd.decode("utf-8") cmds.append(cmd) return cmds[:3] + cmds[4:]
Callback function for handling command output.
testCdPwd.cmdOutput
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
MIT
def testCdPwd(self): """ Test that 'pwd' reports the current remote directory, that 'lpwd' reports the current local directory, and that changing to a subdirectory then changing to its parent leaves you in the original remote directory. """ # XXX - not actually a unit test, see docstring. homeDir = self.testDir d = self.runScript('pwd', 'lpwd', 'cd testDirectory', 'cd ..', 'pwd') def cmdOutput(output): """ Callback function for handling command output. """ cmds = [] for cmd in output: if _PY3 and isinstance(cmd, bytes): cmd = cmd.decode("utf-8") cmds.append(cmd) return cmds[:3] + cmds[4:] d.addCallback(cmdOutput) d.addCallback(self.assertEqual, [homeDir.path, os.getcwd(), '', homeDir.path]) return d
Test that 'pwd' reports the current remote directory, that 'lpwd' reports the current local directory, and that changing to a subdirectory then changing to its parent leaves you in the original remote directory.
testCdPwd
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
MIT
def testChAttrs(self): """ Check that 'ls -l' output includes the access permissions and that this output changes appropriately with 'chmod'. """ def _check(results): self.flushLoggedErrors() self.assertTrue(results[0].startswith(b'-rw-r--r--')) self.assertEqual(results[1], b'') self.assertTrue(results[2].startswith(b'----------'), results[2]) self.assertEqual(results[3], b'') d = self.runScript('ls -l testfile1', 'chmod 0 testfile1', 'ls -l testfile1', 'chmod 644 testfile1') return d.addCallback(_check)
Check that 'ls -l' output includes the access permissions and that this output changes appropriately with 'chmod'.
testChAttrs
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
MIT
def testList(self): """ Check 'ls' works as expected. Checks for wildcards, hidden files, listing directories and listing empty directories. """ def _check(results): self.assertEqual(results[0], [b'testDirectory', b'testRemoveFile', b'testRenameFile', b'testfile1']) self.assertEqual(results[1], [b'testDirectory', b'testRemoveFile', b'testRenameFile', b'testfile1']) self.assertEqual(results[2], [b'testRemoveFile', b'testRenameFile']) self.assertEqual(results[3], [b'.testHiddenFile', b'testRemoveFile', b'testRenameFile']) self.assertEqual(results[4], [b'']) d = self.runScript('ls', 'ls ../' + self.testDir.basename(), 'ls *File', 'ls -a *File', 'ls -l testDirectory') d.addCallback(lambda xs: [x.split(b'\n') for x in xs]) return d.addCallback(_check)
Check 'ls' works as expected. Checks for wildcards, hidden files, listing directories and listing empty directories.
testList
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
MIT
def testHelp(self): """ Check that running the '?' command returns help. """ d = self.runCommand('?') helpText = cftp.StdioClient(None).cmd_HELP('').strip() if isinstance(helpText, unicode): helpText = helpText.encode("utf-8") d.addCallback(self.assertEqual, helpText) return d
Check that running the '?' command returns help.
testHelp
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
MIT
def assertFilesEqual(self, name1, name2, msg=None): """ Assert that the files at C{name1} and C{name2} contain exactly the same data. """ self.assertEqual(name1.getContent(), name2.getContent(), msg)
Assert that the files at C{name1} and C{name2} contain exactly the same data.
assertFilesEqual
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
MIT
def testGet(self): """ Test that 'get' saves the remote file to the correct local location, that the output of 'get' is correct and that 'rm' actually removes the file. """ # XXX - not actually a unit test expectedOutput = ("Transferred %s/testfile1 to %s/test file2" % (self.testDir.path, self.testDir.path)) if isinstance(expectedOutput, unicode): expectedOutput = expectedOutput.encode("utf-8") def _checkGet(result): self.assertTrue(result.endswith(expectedOutput)) self.assertFilesEqual(self.testDir.child('testfile1'), self.testDir.child('test file2'), "get failed") return self.runCommand('rm "test file2"') d = self.runCommand('get testfile1 "%s/test file2"' % (self.testDir.path,)) d.addCallback(_checkGet) d.addCallback(lambda _: self.assertFalse( self.testDir.child('test file2').exists())) return d
Test that 'get' saves the remote file to the correct local location, that the output of 'get' is correct and that 'rm' actually removes the file.
testGet
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
MIT
def testWildcardGet(self): """ Test that 'get' works correctly when given wildcard parameters. """ def _check(ignored): self.assertFilesEqual(self.testDir.child('testRemoveFile'), FilePath('testRemoveFile'), 'testRemoveFile get failed') self.assertFilesEqual(self.testDir.child('testRenameFile'), FilePath('testRenameFile'), 'testRenameFile get failed') d = self.runCommand('get testR*') return d.addCallback(_check)
Test that 'get' works correctly when given wildcard parameters.
testWildcardGet
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
MIT
def testPut(self): """ Check that 'put' uploads files correctly and that they can be successfully removed. Also check the output of the put command. """ # XXX - not actually a unit test expectedOutput = (b'Transferred ' + self.testDir.asBytesMode().path + b'/testfile1 to ' + self.testDir.asBytesMode().path + b'/test"file2') def _checkPut(result): self.assertFilesEqual(self.testDir.child('testfile1'), self.testDir.child('test"file2')) self.assertTrue(result.endswith(expectedOutput)) return self.runCommand('rm "test\\"file2"') d = self.runCommand('put %s/testfile1 "test\\"file2"' % (self.testDir.path,)) d.addCallback(_checkPut) d.addCallback(lambda _: self.assertFalse( self.testDir.child('test"file2').exists())) return d
Check that 'put' uploads files correctly and that they can be successfully removed. Also check the output of the put command.
testPut
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_cftp.py
MIT