Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(2392)

Side by Side Diff: Lib/ftplib.py

Issue 10883: urllib: socket is not closed explicitly
Patch Set: Created 1 year, 10 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | Lib/test/test_urllib2.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 """An FTP client class and some helper functions. 1 """An FTP client class and some helper functions.
2 2
3 Based on RFC 959: File Transfer Protocol (FTP), by J. Postel and J. Reynolds 3 Based on RFC 959: File Transfer Protocol (FTP), by J. Postel and J. Reynolds
4 4
5 Example: 5 Example:
6 6
7 >>> from ftplib import FTP 7 >>> from ftplib import FTP
8 >>> ftp = FTP('ftp.python.org') # connect to host, default port 8 >>> ftp = FTP('ftp.python.org') # connect to host, default port
9 >>> ftp.login() # default, i.e.: user anonymous, passwd anonymous@ 9 >>> ftp.login() # default, i.e.: user anonymous, passwd anonymous@
10 '230 Guest login ok, access restrictions apply.' 10 '230 Guest login ok, access restrictions apply.'
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 Optional `rest' argument can be a string that is sent as the 336 Optional `rest' argument can be a string that is sent as the
337 argument to a REST command. This is essentially a server 337 argument to a REST command. This is essentially a server
338 marker used to tell the server to skip over any data up to the 338 marker used to tell the server to skip over any data up to the
339 given marker. 339 given marker.
340 """ 340 """
341 size = None 341 size = None
342 if self.passiveserver: 342 if self.passiveserver:
343 host, port = self.makepasv() 343 host, port = self.makepasv()
344 conn = socket.create_connection((host, port), self.timeout, 344 conn = socket.create_connection((host, port), self.timeout,
345 source_address=self.source_address) 345 source_address=self.source_address)
346 if rest is not None: 346 try:
347 self.sendcmd("REST %s" % rest) 347 if rest is not None:
348 resp = self.sendcmd(cmd) 348 self.sendcmd("REST %s" % rest)
349 # Some servers apparently send a 200 reply to 349 resp = self.sendcmd(cmd)
350 # a LIST or STOR command, before the 150 reply 350 # Some servers apparently send a 200 reply to
351 # (and way before the 226 reply). This seems to 351 # a LIST or STOR command, before the 150 reply
352 # be in violation of the protocol (which only allows 352 # (and way before the 226 reply). This seems to
353 # 1xx or error messages for LIST), so we just discard 353 # be in violation of the protocol (which only allows
354 # this response. 354 # 1xx or error messages for LIST), so we just discard
355 if resp[0] == '2': 355 # this response.
356 resp = self.getresp() 356 if resp[0] == '2':
357 if resp[0] != '1': 357 resp = self.getresp()
358 raise error_reply(resp) 358 if resp[0] != '1':
359 raise error_reply(resp)
360 except:
361 conn.close()
362 raise
359 else: 363 else:
360 sock = self.makeport() 364 sock = self.makeport()
361 if rest is not None: 365 if rest is not None:
362 self.sendcmd("REST %s" % rest) 366 self.sendcmd("REST %s" % rest)
363 resp = self.sendcmd(cmd) 367 resp = self.sendcmd(cmd)
364 # See above. 368 # See above.
365 if resp[0] == '2': 369 if resp[0] == '2':
366 resp = self.getresp() 370 resp = self.getresp()
367 if resp[0] != '1': 371 if resp[0] != '1':
368 raise error_reply(resp) 372 raise error_reply(resp)
(...skipping 740 matching lines...) Expand 10 before | Expand all | Expand 10 after
1109 elif file == '-p': 1113 elif file == '-p':
1110 ftp.set_pasv(not ftp.passiveserver) 1114 ftp.set_pasv(not ftp.passiveserver)
1111 else: 1115 else:
1112 ftp.retrbinary('RETR ' + file, \ 1116 ftp.retrbinary('RETR ' + file, \
1113 sys.stdout.write, 1024) 1117 sys.stdout.write, 1024)
1114 ftp.quit() 1118 ftp.quit()
1115 1119
1116 1120
1117 if __name__ == '__main__': 1121 if __name__ == '__main__':
1118 test() 1122 test()
OLDNEW
« no previous file with comments | « no previous file | Lib/test/test_urllib2.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld cbc36f91f3f7