Skip to content

Commit

Permalink
Fix for #375 #382 Adds an option for raw response returning in parser.py
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismattmann committed Jan 1, 2023
1 parent b6f1374 commit ca2a692
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions tika/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import os
import json

def from_file(filename, serverEndpoint=ServerEndpoint, service='all', xmlContent=False, headers=None, config_path=None, requestOptions={}):
def from_file(filename, serverEndpoint=ServerEndpoint, service='all', xmlContent=False, headers=None, config_path=None, requestOptions={}, raw_response=False):
'''
Parses a file for metadata and content
:param filename: path to file which needs to be parsed or binary file using open(path,'rb')
Expand All @@ -41,10 +41,13 @@ def from_file(filename, serverEndpoint=ServerEndpoint, service='all', xmlContent
else:
output = parse1(service, filename, serverEndpoint, services={'meta': '/meta', 'text': '/tika', 'all': '/rmeta/xml'},
headers=headers, config_path=config_path, requestOptions=requestOptions)
return _parse(output, service)
if raw_response:
return output
else:
return _parse(output, service)


def from_buffer(string, serverEndpoint=ServerEndpoint, xmlContent=False, headers=None, config_path=None, requestOptions={}):
def from_buffer(string, serverEndpoint=ServerEndpoint, xmlContent=False, headers=None, config_path=None, requestOptions={}, raw_response=False):
'''
Parses the content from buffer
:param string: Buffer value
Expand All @@ -63,7 +66,10 @@ def from_buffer(string, serverEndpoint=ServerEndpoint, xmlContent=False, headers
else:
status, response = callServer('put', serverEndpoint, '/rmeta/xml', string, headers, False, config_path=config_path, requestOptions=requestOptions)

return _parse((status,response))
if raw_response:
return (status, response)
else:
return _parse((status,response))

def _parse(output, service='all'):
'''
Expand Down

0 comments on commit ca2a692

Please sign in to comment.