@@ -349,7 +349,8 @@ def makefile(self, mode="r", buffering=None, *,
349349        text .mode  =  mode 
350350        return  text 
351351
352-     def  _sendfile_zerocopy (self , zerocopy_func , giveup_err , file , offset = 0 , count = None ):
352+     def  _sendfile_zerocopy (self , zerocopy_func , giveup_exc_type , file ,
353+                            offset = 0 , count = None ):
353354        """ 
354355        Send a file using a zero-copy function. 
355356        """ 
@@ -360,11 +361,11 @@ def _sendfile_zerocopy(self, zerocopy_func, giveup_err, file, offset=0, count=No
360361        try :
361362            fileno  =  file .fileno ()
362363        except  (AttributeError , io .UnsupportedOperation ) as  err :
363-             raise  giveup_err (err )  # not a regular file 
364+             raise  giveup_exc_type (err )  # not a regular file 
364365        try :
365366            fsize  =  os .fstat (fileno ).st_size 
366367        except  OSError  as  err :
367-             raise  giveup_err (err )  # not a regular file 
368+             raise  giveup_exc_type (err )  # not a regular file 
368369        if  not  fsize :
369370            return  0   # empty file 
370371        # Truncate to 1GiB to avoid OverflowError, see bpo-38319. 
@@ -406,7 +407,7 @@ def _sendfile_zerocopy(self, zerocopy_func, giveup_err, file, offset=0, count=No
406407                        # one being 'file' is not a regular mmap(2)-like 
407408                        # file, in which case we'll fall back on using 
408409                        # plain send(). 
409-                         raise  giveup_err (err )
410+                         raise  giveup_exc_type (err )
410411                    raise  err  from  None 
411412                else :
412413                    if  sent  ==  0 :
@@ -418,17 +419,17 @@ def _sendfile_zerocopy(self, zerocopy_func, giveup_err, file, offset=0, count=No
418419            if  total_sent  >  0  and  hasattr (file , 'seek' ):
419420                file .seek (offset )
420421
421-     def  _sendfile_use_sendfile (self , file , offset = 0 , count = None ):
422-         if  not  (sendfile  :=  getattr (os , 'sendfile' , None )):
422+     if  hasattr (os , 'sendfile' ):
423+         def  _sendfile_use_sendfile (self , file , offset = 0 , count = None ):
424+             return  self ._sendfile_zerocopy (
425+                 partial (os .sendfile , self .fileno ()),
426+                 _GiveupOnSendfile ,
427+                 file , offset , count ,
428+             )
429+     else :
430+         def  _sendfile_use_sendfile (self , file , offset = 0 , count = None ):
423431            raise  _GiveupOnSendfile (
424432                "os.sendfile() not available on this platform" )
425-         return  self ._sendfile_zerocopy (
426-             zerocopy_func = partial (sendfile , self .fileno ()),
427-             giveup_err = _GiveupOnSendfile ,
428-             file = file ,
429-             offset = offset ,
430-             count = count ,
431-         )
432433
433434    def  _sendfile_use_send (self , file , offset = 0 , count = None ):
434435        self ._check_sendfile_params (file , offset , count )
0 commit comments