@@ -434,10 +434,7 @@ def retrbinary(self, cmd, callback, blocksize=8192, rest=None):
434434 """
435435 self .voidcmd ('TYPE I' )
436436 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 ):
441438 callback (data )
442439 # shutdown ssl layer
443440 if _SSLSocket is not None and isinstance (conn , _SSLSocket ):
@@ -496,10 +493,7 @@ def storbinary(self, cmd, fp, blocksize=8192, callback=None, rest=None):
496493 """
497494 self .voidcmd ('TYPE I' )
498495 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 ):
503497 conn .sendall (buf )
504498 if callback :
505499 callback (buf )
@@ -561,7 +555,7 @@ def dir(self, *args):
561555 LIST command. (This *should* only be used for a pathname.)'''
562556 cmd = 'LIST'
563557 func = None
564- if args [- 1 :] and type (args [- 1 ]) != type ( '' ):
558+ if args [- 1 :] and not isinstance (args [- 1 ], str ):
565559 args , func = args [:- 1 ], args [- 1 ]
566560 for arg in args :
567561 if arg :
@@ -713,28 +707,12 @@ class FTP_TLS(FTP):
713707 '221 Goodbye.'
714708 >>>
715709 '''
716- ssl_version = ssl .PROTOCOL_TLS_CLIENT
717710
718711 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' ):
734714 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 ()
738716 self .context = context
739717 self ._prot_p = False
740718 super ().__init__ (host , user , passwd , acct ,
@@ -749,7 +727,7 @@ def auth(self):
749727 '''Set up secure control connection by using TLS/SSL.'''
750728 if isinstance (self .sock , ssl .SSLSocket ):
751729 raise ValueError ("Already using TLS" )
752- if self .ssl_version >= ssl .PROTOCOL_TLS :
730+ if self .context . protocol >= ssl .PROTOCOL_TLS :
753731 resp = self .voidcmd ('AUTH TLS' )
754732 else :
755733 resp = self .voidcmd ('AUTH SSL' )
0 commit comments