5858 detected = detector.from_buffer('some buffered content', config_path='/path/to/configfile')
5959
6060'''
61+ import types
6162
6263USAGE = """
6364tika.py [-v] [-e] [-o <outputDir>] [--server <TikaServerEndpoint>] [--install <UrlToTikaServerJar>] [--port <portNumber>] <command> <option> <urlOrPathToFile>
@@ -326,7 +327,7 @@ def parse1(option, urlOrPath, serverEndpoint=ServerEndpoint, verbose=Verbose, ti
326327 service = services .get (option , services ['all' ])
327328 if service == '/tika' : responseMimeType = 'text/plain'
328329 headers .update ({'Accept' : responseMimeType , 'Content-Disposition' : make_content_disposition_header (path .encode ('utf-8' ) if type (path ) is unicode_string else path )})
329- with urlOrPath if isinstance (urlOrPath , io . BufferedIOBase ) else open (path , 'rb' ) as f :
330+ with urlOrPath if _is_file_object (urlOrPath ) else open (path , 'rb' ) as f :
330331 status , response = callServer ('put' , serverEndpoint , service , f ,
331332 headers , verbose , tikaServerJar , config_path = config_path ,
332333 rawResponse = rawResponse , requestOptions = requestOptions )
@@ -691,7 +692,15 @@ def toFilename(url):
691692 value = re .sub (r'[^\w\s\.\-]' , '-' , path ).strip ().lower ()
692693 return re .sub (r'[-\s]+' , '-' , value ).strip ("-" )[- 200 :]
693694
694-
695+
696+ def _is_file_object (f ):
697+ try :
698+ file_types = (types .FileType , io .IOBase )
699+ except AttributeError :
700+ file_types = (io .IOBase ,)
701+
702+ return isinstance (f , file_types )
703+
695704def getRemoteFile (urlOrPath , destPath ):
696705 '''
697706 Fetches URL to local path or just returns absolute path.
@@ -700,7 +709,7 @@ def getRemoteFile(urlOrPath, destPath):
700709 :return: tuple having (path, 'local'/'remote'/'binary')
701710 '''
702711 # handle binary stream input
703- if isinstance (urlOrPath , io . BufferedIOBase ):
712+ if _is_file_object (urlOrPath ):
704713 return (urlOrPath .name , 'binary' )
705714
706715 urlp = urlparse (urlOrPath )
0 commit comments