MCPcopy Index your code
hub / github.com/RustPython/RustPython / retrfile

Method retrfile

Lib/urllib/request.py:1802–1844  ·  view source on GitHub ↗
(self, file, type)

Source from the content-addressed store, hash-verified

1800 self.ftp.cwd(_target)
1801
1802 def retrfile(self, file, type):
1803 import ftplib
1804 self.endtransfer()
1805 if type in ('d', 'D'): cmd = 'TYPE A'; isdir = 1
1806 else: cmd = 'TYPE ' + type; isdir = 0
1807 try:
1808 self.ftp.voidcmd(cmd)
1809 except ftplib.all_errors:
1810 self.init()
1811 self.ftp.voidcmd(cmd)
1812 conn = None
1813 if file and not isdir:
1814 # Try to retrieve as a file
1815 try:
1816 cmd = 'RETR ' + file
1817 conn, retrlen = self.ftp.ntransfercmd(cmd)
1818 except ftplib.error_perm as reason:
1819 if str(reason)[:3] != '550':
1820 raise URLError(f'ftp error: {reason}') from reason
1821 if not conn:
1822 # Set transfer mode to ASCII!
1823 self.ftp.voidcmd('TYPE A')
1824 # Try a directory listing. Verify that directory exists.
1825 if file:
1826 pwd = self.ftp.pwd()
1827 try:
1828 try:
1829 self.ftp.cwd(file)
1830 except ftplib.error_perm as reason:
1831 raise URLError('ftp error: %r' % reason) from reason
1832 finally:
1833 self.ftp.cwd(pwd)
1834 cmd = 'LIST ' + file
1835 else:
1836 cmd = 'LIST'
1837 conn, retrlen = self.ftp.ntransfercmd(cmd)
1838 self.busy = 1
1839
1840 ftpobj = addclosehook(conn.makefile('rb'), self.file_close)
1841 self.refcount += 1
1842 conn.close()
1843 # Pass back both a suitably decorated object and a retrieval length
1844 return (ftpobj, retrlen)
1845
1846 def endtransfer(self):
1847 if not self.busy:

Callers 1

ftp_openMethod · 0.45

Calls 11

endtransferMethod · 0.95
initMethod · 0.95
URLErrorClass · 0.90
addclosehookClass · 0.90
strFunction · 0.85
voidcmdMethod · 0.80
pwdMethod · 0.80
ntransfercmdMethod · 0.45
cwdMethod · 0.45
makefileMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected