@@ -2208,41 +2208,41 @@ def download_file_from_internet_file(url, headers=geturls_headers_pywwwget_pytho
22082208 else :
22092209 return download_file_from_sftp_file (url )
22102210 elif (urlparts .scheme == "tcp" or urlparts .scheme == "udp" ):
2211- outfile = MkTempFile ()
2212- returnval = recv_via_url (outfile , url , recv_to_fileobj )
2213- if (not returnval ):
2214- return False
2215- # Optional autosave (works for UDP seq meta and TCP/UDP in general)
2216- try :
2217- parts , o = _parse_net_url (url )
2218- except Exception :
2219- parts , o = (None , {})
2220- if o and o .get ("save" ):
2221- # prefer meta filename if available
2222- fname = None
2211+ outfile = MkTempFile ()
2212+ returnval = recv_via_url (outfile , url , recv_to_fileobj )
2213+ if (not returnval ):
2214+ return False
2215+ # Optional autosave (works for UDP seq meta and TCP/UDP in general)
22232216 try :
2224- meta = getattr (outfile , "_pywwwget_meta" , None )
2225- if meta and isinstance (meta , dict ):
2226- fname = meta .get ("filename" ) or None
2217+ parts , o = _parse_net_url (url )
22272218 except Exception :
2219+ parts , o = (None , {})
2220+ if o and o .get ("save" ):
2221+ # prefer meta filename if available
22282222 fname = None
2229- if not fname :
22302223 try :
2231- fname = _guess_filename (url ) or None
2224+ meta = getattr (outfile , "_pywwwget_meta" , None )
2225+ if meta and isinstance (meta , dict ):
2226+ fname = meta .get ("filename" ) or None
22322227 except Exception :
22332228 fname = None
2234- out_path = _choose_output_path (fname , overwrite = bool (o .get ("overwrite" )), save_dir = o .get ("save_dir" ))
2235- try :
2236- _autosave_fileobj (outfile , out_path )
2229+ if not fname :
2230+ try :
2231+ fname = _guess_filename (url ) or None
2232+ except Exception :
2233+ fname = None
2234+ out_path = _choose_output_path (fname , overwrite = bool (o .get ("overwrite" )), save_dir = o .get ("save_dir" ))
22372235 try :
2238- sys .stdout .write ("Saved: %s\n " % out_path )
2239- sys .stdout .flush ()
2236+ _autosave_fileobj (outfile , out_path )
2237+ try :
2238+ sys .stdout .write ("Saved: %s\n " % out_path )
2239+ sys .stdout .flush ()
2240+ except Exception :
2241+ pass
22402242 except Exception :
22412243 pass
2242- except Exception :
2243- pass
2244- outfile .seek (0 , 0 )
2245- return outfile
2244+ outfile .seek (0 , 0 )
2245+ return outfile
22462246
22472247 else :
22482248 return False
@@ -4678,28 +4678,28 @@ def _udpseq_recv_to_fileobj(fileobj, host, port,
46784678 # if host isn't bindable, bind on all interfaces
46794679 sock .bind (("0.0.0.0" , int (port )))
46804680
4681- # If port=0 was used, the OS will pick a free port. Capture actual bound addr/port.
4682- try :
4683- bound_host , bound_port = sock .getsockname ()[0 ], sock .getsockname ()[1 ]
4684- except Exception :
4685- bound_host , bound_port = (host , int (port ))
4686-
4687- if print_url :
4688- for u in _format_listen_urls ("udp" , bound_host if bound_host else host , bound_port , url_path , url_query ):
4689- try :
4690- sys .stdout .write ("Listening: %s\n " % u )
4691- except Exception :
4692- # Python 2 fallback
4693- try :
4694- print ("Listening: %s" % u )
4695- except Exception :
4696- pass
4681+ # If port=0 was used, the OS will pick a free port. Capture actual bound addr/port.
46974682 try :
4698- sys . stdout . flush ()
4683+ bound_host , bound_port = sock . getsockname ()[ 0 ], sock . getsockname ()[ 1 ]
46994684 except Exception :
4700- pass
4701-
4702-
4685+ bound_host , bound_port = (host , int (port ))
4686+
4687+ if print_url :
4688+ for u in _format_listen_urls ("udp" , bound_host if bound_host else host , bound_port , url_path , url_query ):
4689+ try :
4690+ sys .stdout .write ("Listening: %s\n " % u )
4691+ except Exception :
4692+ # Python 2 fallback
4693+ try :
4694+ print ("Listening: %s" % u )
4695+ except Exception :
4696+ pass
4697+ try :
4698+ sys .stdout .flush ()
4699+ except Exception :
4700+ pass
4701+
4702+
47034703 expected = 0
47044704 received = {} # seq -> payload
47054705 done_seen = False
0 commit comments