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

Commit bba4ad6

Browse files
authored
Merge pull request #9 from vmarkovtsev/unicde
Fix the unicode reading errors
2 parents 2c60b24 + 91c88e0 commit bba4ad6

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

bblfsh/client.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ def __init__(self, endpoint):
2727
self._channel = grpc.insecure_channel(endpoint)
2828
self._stub = ProtocolServiceStub(self._channel)
2929

30-
def parse_uast(self, filename, language=None, contents=None, timeout=None):
30+
def parse_uast(self, filename, language=None, contents=None, timeout=None,
31+
unicode_errors="ignore"):
3132
"""
3233
Queries the Babelfish server and receives the UAST for the specified
3334
file.
@@ -40,14 +41,16 @@ def parse_uast(self, filename, language=None, contents=None, timeout=None):
4041
:param contents: The contents of the file. IF None, it is read from \
4142
filename.
4243
:param timeout: The request timeout in seconds.
44+
:param unicode_errors: This is passed to open() and changes the way \
45+
Unicode read errors are handled.
4346
:type filename: str
4447
:type language: str
4548
:type contents: str
4649
:type timeout: float
4750
:return: UAST object.
4851
"""
4952
if contents is None:
50-
with open(filename) as fin:
53+
with open(filename, errors=unicode_errors) as fin:
5154
contents = fin.read()
5255
request = ParseUASTRequest(filename=os.path.basename(filename),
5356
content=contents,

0 commit comments

Comments
 (0)