@@ -434,10 +434,7 @@ def retrbinary(self, cmd, callback, blocksize=8192, rest=None):
434
434
"""
435
435
self .voidcmd ('TYPE I' )
436
436
with self .transfercmd (cmd , rest ) as conn :
437
- while 1 :
438
- data = conn .recv (blocksize )
439
- if not data :
440
- break
437
+ while data := conn .recv (blocksize ):
441
438
callback (data )
442
439
# shutdown ssl layer
443
440
if _SSLSocket is not None and isinstance (conn , _SSLSocket ):
@@ -496,10 +493,7 @@ def storbinary(self, cmd, fp, blocksize=8192, callback=None, rest=None):
496
493
"""
497
494
self .voidcmd ('TYPE I' )
498
495
with self .transfercmd (cmd , rest ) as conn :
499
- while 1 :
500
- buf = fp .read (blocksize )
501
- if not buf :
502
- break
496
+ while buf := fp .read (blocksize ):
503
497
conn .sendall (buf )
504
498
if callback :
505
499
callback (buf )
@@ -561,7 +555,7 @@ def dir(self, *args):
561
555
LIST command. (This *should* only be used for a pathname.)'''
562
556
cmd = 'LIST'
563
557
func = None
564
- if args [- 1 :] and type (args [- 1 ]) != type ( '' ):
558
+ if args [- 1 :] and not isinstance (args [- 1 ], str ):
565
559
args , func = args [:- 1 ], args [- 1 ]
566
560
for arg in args :
567
561
if arg :
@@ -713,28 +707,12 @@ class FTP_TLS(FTP):
713
707
'221 Goodbye.'
714
708
>>>
715
709
'''
716
- ssl_version = ssl .PROTOCOL_TLS_CLIENT
717
710
718
711
def __init__ (self , host = '' , user = '' , passwd = '' , acct = '' ,
719
- keyfile = None , certfile = None , context = None ,
720
- timeout = _GLOBAL_DEFAULT_TIMEOUT , source_address = None , * ,
721
- encoding = 'utf-8' ):
722
- if context is not None and keyfile is not None :
723
- raise ValueError ("context and keyfile arguments are mutually "
724
- "exclusive" )
725
- if context is not None and certfile is not None :
726
- raise ValueError ("context and certfile arguments are mutually "
727
- "exclusive" )
728
- if keyfile is not None or certfile is not None :
729
- import warnings
730
- warnings .warn ("keyfile and certfile are deprecated, use a "
731
- "custom context instead" , DeprecationWarning , 2 )
732
- self .keyfile = keyfile
733
- self .certfile = certfile
712
+ * , context = None , timeout = _GLOBAL_DEFAULT_TIMEOUT ,
713
+ source_address = None , encoding = 'utf-8' ):
734
714
if context is None :
735
- context = ssl ._create_stdlib_context (self .ssl_version ,
736
- certfile = certfile ,
737
- keyfile = keyfile )
715
+ context = ssl ._create_stdlib_context ()
738
716
self .context = context
739
717
self ._prot_p = False
740
718
super ().__init__ (host , user , passwd , acct ,
@@ -749,7 +727,7 @@ def auth(self):
749
727
'''Set up secure control connection by using TLS/SSL.'''
750
728
if isinstance (self .sock , ssl .SSLSocket ):
751
729
raise ValueError ("Already using TLS" )
752
- if self .ssl_version >= ssl .PROTOCOL_TLS :
730
+ if self .context . protocol >= ssl .PROTOCOL_TLS :
753
731
resp = self .voidcmd ('AUTH TLS' )
754
732
else :
755
733
resp = self .voidcmd ('AUTH SSL' )
0 commit comments