本文整理汇总了Python中ftplib.error_temp方法的典型用法代码示例。如果您正苦于以下问题:Python ftplib.error_temp方法的具体用法?Python ftplib.error_temp怎么用?Python ftplib.error_temp使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ftplib
的用法示例。
在下文中一共展示了ftplib.error_temp方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_max_connections_per_ip
# 需要导入模块: import ftplib [as 别名]
# 或者: from ftplib import error_temp [as 别名]
def test_max_connections_per_ip(self):
# Test FTPServer.max_cons_per_ip attribute
self.server.server.max_cons_per_ip = 3
self.client.quit()
c1 = self.client_class()
c2 = self.client_class()
c3 = self.client_class()
c4 = self.client_class()
try:
c1.connect(self.server.host, self.server.port)
c2.connect(self.server.host, self.server.port)
c3.connect(self.server.host, self.server.port)
self.assertRaises(ftplib.error_temp, c4.connect, self.server.host,
self.server.port)
# Make sure client has been disconnected.
# socket.error (Windows) or EOFError (Linux) exception is
# supposed to be raised in such a case.
self.assertRaises((socket.error, EOFError), c4.sendcmd, 'noop')
finally:
for c in (c1, c2, c3, c4):
try:
c.quit()
except (socket.error, EOFError): # already disconnected
c.close()
示例2: test_active_conn_error
# 需要导入模块: import ftplib [as 别名]
# 或者: from ftplib import error_temp [as 别名]
def test_active_conn_error(self):
# we open a socket() but avoid to invoke accept() to
# reproduce this error condition:
# http://code.google.com/p/pyftpdlib/source/detail?r=905
with contextlib.closing(socket.socket()) as sock:
sock.bind((HOST, 0))
port = sock.getsockname()[1]
self.client.sock.settimeout(.1)
try:
resp = self.client.sendport(HOST, port)
except ftplib.error_temp as err:
self.assertEqual(str(err)[:3], '425')
except (socket.timeout, getattr(ssl, "SSLError", object())):
pass
else:
self.assertNotEqual(str(resp)[:3], '200')
示例3: test_stou_max_tries
# 需要导入模块: import ftplib [as 别名]
# 或者: from ftplib import error_temp [as 别名]
def test_stou_max_tries(self):
# Emulates case where the max number of tries to find out a
# unique file name when processing STOU command gets hit.
class TestFS(AbstractedFS):
def mkstemp(self, *args, **kwargs):
raise IOError(errno.EEXIST,
"No usable temporary file name found")
self.server.handler.abstracted_fs = TestFS
try:
self.client.quit()
self.client.connect(self.server.host, self.server.port)
self.client.login(USER, PASSWD)
self.assertRaises(ftplib.error_temp, self.client.sendcmd, 'stou')
finally:
self.server.handler.abstracted_fs = AbstractedFS
示例4: exists
# 需要导入模块: import ftplib [as 别名]
# 或者: from ftplib import error_temp [as 别名]
def exists(self, name):
self._start_connection()
try:
nlst = self._connection.nlst(
os.path.dirname(name) + '/'
)
if name in nlst or os.path.basename(name) in nlst:
return True
else:
return False
except ftplib.error_temp:
return False
except ftplib.error_perm:
# error_perm: 550 Can't find file
return False
except ftplib.all_errors:
raise FTPStorageException('Error when testing existence of %s'
% name)
示例5: read_file_as_bytes
# 需要导入模块: import ftplib [as 别名]
# 或者: from ftplib import error_temp [as 别名]
def read_file_as_bytes(self, filename): # pragma: no cover
ftp = self.get_connection()
bytes_string = BytesIO()
try:
try:
ftp.retrbinary("RETR {}".format(filename), bytes_string.write)
except (ftplib.error_temp, ftplib.error_perm, EOFError, IOError) as e:
# Bad connection. attempt to reconnect.
logger.warn(
"Failed RETR {}:\n{}\n" "Attempting reconnect.".format(filename, e)
)
ftp = self.reconnect()
ftp.retrbinary("RETR {}".format(filename), bytes_string.write)
except Exception as e:
logger.warn(
"Failed RETR {}:\n{}\n" "Not attempting reconnect.".format(filename, e)
)
return None
bytes_string.seek(0)
logger.info("Successfully retrieved ftp://ftp.ncdc.noaa.gov{}".format(filename))
return bytes_string
示例6: test_on_incomplete_file_received
# 需要导入模块: import ftplib [as 别名]
# 或者: from ftplib import error_temp [as 别名]
def test_on_incomplete_file_received(self):
self.client.login(USER, PASSWD)
data = b'abcde12345' * 1000000
dummyfile = BytesIO()
dummyfile.write(data)
dummyfile.seek(0)
with contextlib.closing(
self.client.transfercmd('stor ' + self.testfn2)) as conn:
bytes_sent = 0
while True:
chunk = dummyfile.read(BUFSIZE)
conn.sendall(chunk)
bytes_sent += len(chunk)
# stop transfer while it isn't finished yet
if bytes_sent >= INTERRUPTED_TRANSF_SIZE or not chunk:
self.client.putcmd('abor')
break
# If a data transfer is in progress server is supposed to send
# a 426 reply followed by a 226 reply.
self.assertRaises(ftplib.error_temp, self.client.getresp) # 426
self.assertEqual(self.client.getresp()[:3], "226")
self.read_file(
'on_connect,on_login:%s,on_incomplete_file_received:%s,' %
(USER, self.testfn2))
示例7: test_stou_max_tries
# 需要导入模块: import ftplib [as 别名]
# 或者: from ftplib import error_temp [as 别名]
def test_stou_max_tries(self):
# Emulates case where the max number of tries to find out a
# unique file name when processing STOU command gets hit.
class TestFS(AbstractedFS):
def mkstemp(self, *args, **kwargs):
raise IOError(errno.EEXIST,
"No usable temporary file name found")
with self.server.lock:
self.server.handler.abstracted_fs = TestFS
try:
self.client.quit()
self.client.connect(self.server.host, self.server.port)
self.client.login(USER, PASSWD)
self.assertRaises(ftplib.error_temp, self.client.sendcmd, 'stou')
finally:
with self.server.lock:
self.server.handler.abstracted_fs = AbstractedFS
示例8: ftp_errors
# 需要导入模块: import ftplib [as 别名]
# 或者: from ftplib import error_temp [as 别名]
def ftp_errors(fs, path=None):
# type: (FTPFS, Optional[Text]) -> Iterator[None]
try:
with fs._lock:
yield
except socket.error:
raise errors.RemoteConnectionError(
msg="unable to connect to {}".format(fs.host)
)
except EOFError:
raise errors.RemoteConnectionError(msg="lost connection to {}".format(fs.host))
except error_temp as error:
if path is not None:
raise errors.ResourceError(
path, msg="ftp error on resource '{}' ({})".format(path, error)
)
else:
raise errors.OperationFailed(msg="ftp error ({})".format(error))
except error_perm as error:
code, message = _parse_ftp_error(error)
if code == "552":
raise errors.InsufficientStorage(path=path, msg=message)
elif code in ("501", "550"):
raise errors.ResourceNotFound(path=cast(str, path))
raise errors.PermissionDenied(msg=message)
示例9: close
# 需要导入模块: import ftplib [as 别名]
# 或者: from ftplib import error_temp [as 别名]
def close(self):
# type: () -> None
if not self.closed:
with self._lock:
try:
if self._write_conn is not None:
self._write_conn.close()
self._write_conn = None
self.ftp.voidresp() # Ensure last write completed
if self._read_conn is not None:
self._read_conn.close()
self._read_conn = None
try:
self.ftp.quit()
except error_temp: # pragma: no cover
pass
finally:
super(FTPFile, self).close()
示例10: test_exceptions
# 需要导入模块: import ftplib [as 别名]
# 或者: from ftplib import error_temp [as 别名]
def test_exceptions(self):
self.assertRaises(ValueError, self.client.sendcmd, 'echo 40\r\n0')
self.assertRaises(ValueError, self.client.sendcmd, 'echo 40\n0')
self.assertRaises(ValueError, self.client.sendcmd, 'echo 40\r0')
self.assertRaises(ftplib.error_temp, self.client.sendcmd, 'echo 400')
self.assertRaises(ftplib.error_temp, self.client.sendcmd, 'echo 499')
self.assertRaises(ftplib.error_perm, self.client.sendcmd, 'echo 500')
self.assertRaises(ftplib.error_perm, self.client.sendcmd, 'echo 599')
self.assertRaises(ftplib.error_proto, self.client.sendcmd, 'echo 999')
示例11: test_all_errors
# 需要导入模块: import ftplib [as 别名]
# 或者: from ftplib import error_temp [as 别名]
def test_all_errors(self):
exceptions = (ftplib.error_reply, ftplib.error_temp, ftplib.error_perm,
ftplib.error_proto, ftplib.Error, IOError, EOFError)
for x in exceptions:
try:
raise x('exception not included in all_errors set')
except ftplib.all_errors:
pass
示例12: test_exceptions
# 需要导入模块: import ftplib [as 别名]
# 或者: from ftplib import error_temp [as 别名]
def test_exceptions(self):
self.assertRaises(ftplib.error_temp, self.client.sendcmd, 'echo 400')
self.assertRaises(ftplib.error_temp, self.client.sendcmd, 'echo 499')
self.assertRaises(ftplib.error_perm, self.client.sendcmd, 'echo 500')
self.assertRaises(ftplib.error_perm, self.client.sendcmd, 'echo 599')
self.assertRaises(ftplib.error_proto, self.client.sendcmd, 'echo 999')
示例13: test_stou_rest
# 需要导入模块: import ftplib [as 别名]
# 或者: from ftplib import error_temp [as 别名]
def test_stou_rest(self):
# Watch for STOU preceded by REST, which makes no sense.
self.client.sendcmd('type i')
self.client.sendcmd('rest 10')
self.assertRaisesRegex(ftplib.error_temp, "Can't STOU while REST",
self.client.sendcmd, 'stou')
示例14: test_appe_rest
# 需要导入模块: import ftplib [as 别名]
# 或者: from ftplib import error_temp [as 别名]
def test_appe_rest(self):
# Watch for APPE preceded by REST, which makes no sense.
self.client.sendcmd('type i')
self.client.sendcmd('rest 10')
self.assertRaisesRegex(ftplib.error_temp, "Can't APPE while REST",
self.client.sendcmd, 'appe x')
示例15: test_max_connections
# 需要导入模块: import ftplib [as 别名]
# 或者: from ftplib import error_temp [as 别名]
def test_max_connections(self):
# Test FTPServer.max_cons attribute
self.server.server.max_cons = 3
self.client.quit()
c1 = self.client_class()
c2 = self.client_class()
c3 = self.client_class()
try:
c1.connect(self.server.host, self.server.port)
c2.connect(self.server.host, self.server.port)
self.assertRaises(ftplib.error_temp, c3.connect, self.server.host,
self.server.port)
# with passive data channel established
c2.quit()
c1.login(USER, PASSWD)
c1.makepasv()
self.assertRaises(ftplib.error_temp, c2.connect, self.server.host,
self.server.port)
# with passive data socket waiting for connection
c1.login(USER, PASSWD)
c1.sendcmd('pasv')
self.assertRaises(ftplib.error_temp, c2.connect, self.server.host,
self.server.port)
# with active data channel established
c1.login(USER, PASSWD)
with contextlib.closing(c1.makeport()):
self.assertRaises(
ftplib.error_temp, c2.connect, self.server.host,
self.server.port)
finally:
for c in (c1, c2, c3):
try:
c.quit()
except (socket.error, EOFError): # already disconnected
c.close()