Skip to content
This repository has been archived by the owner on Mar 8, 2020. It is now read-only.

Commit

Permalink
Merge pull request #9 from vmarkovtsev/unicde
Browse files Browse the repository at this point in the history
Fix the unicode reading errors
  • Loading branch information
juanjux authored Jul 10, 2017
2 parents 2c60b24 + 91c88e0 commit bba4ad6
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions bblfsh/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ def __init__(self, endpoint):
self._channel = grpc.insecure_channel(endpoint)
self._stub = ProtocolServiceStub(self._channel)

def parse_uast(self, filename, language=None, contents=None, timeout=None):
def parse_uast(self, filename, language=None, contents=None, timeout=None,
unicode_errors="ignore"):
"""
Queries the Babelfish server and receives the UAST for the specified
file.
Expand All @@ -40,14 +41,16 @@ def parse_uast(self, filename, language=None, contents=None, timeout=None):
:param contents: The contents of the file. IF None, it is read from \
filename.
:param timeout: The request timeout in seconds.
:param unicode_errors: This is passed to open() and changes the way \
Unicode read errors are handled.
:type filename: str
:type language: str
:type contents: str
:type timeout: float
:return: UAST object.
"""
if contents is None:
with open(filename) as fin:
with open(filename, errors=unicode_errors) as fin:
contents = fin.read()
request = ParseUASTRequest(filename=os.path.basename(filename),
content=contents,
Expand Down

0 comments on commit bba4ad6

Please sign in to comment.