@@ -325,8 +325,10 @@ def parse1(option, urlOrPath, serverEndpoint=ServerEndpoint, verbose=Verbose, ti
325325 service = services .get (option , services ['all' ])
326326 if service == '/tika' : responseMimeType = 'text/plain'
327327 headers .update ({'Accept' : responseMimeType , 'Content-Disposition' : make_content_disposition_header (path .encode ('utf-8' ) if type (path ) is unicode_string else path )})
328- status , response = callServer ('put' , serverEndpoint , service , open (path , 'rb' ),
329- headers , verbose , tikaServerJar , config_path = config_path , rawResponse = rawResponse , requestOptions = requestOptions )
328+ with open (path , 'rb' ) as f :
329+ status , response = callServer ('put' , serverEndpoint , service , f ,
330+ headers , verbose , tikaServerJar , config_path = config_path ,
331+ rawResponse = rawResponse , requestOptions = requestOptions )
330332
331333 if file_type == 'remote' : os .unlink (path )
332334 return (status , response )
@@ -761,8 +763,6 @@ def checkPortIsOpen(remoteServerHost=ServerHost, port = Port):
761763 return True
762764 else :
763765 return False
764- sock .close ()
765- #FIXME: the above line is unreachable
766766
767767 except KeyboardInterrupt :
768768 print ("You pressed Ctrl+C" )
@@ -776,6 +776,9 @@ def checkPortIsOpen(remoteServerHost=ServerHost, port = Port):
776776 print ("Couldn't connect to server" )
777777 sys .exit ()
778778
779+ finally :
780+ sock .close ()
781+
779782def main (argv = None ):
780783 """Run Tika from command line according to USAGE."""
781784 global Verbose
0 commit comments