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

Commit 854e2e6

Browse files
authored
Merge pull request #13 from juanjux/fix/protocol-naming
renamed SD api calls and parse_uast (to parse) module function
2 parents 8cfaf76 + a455b2c commit 854e2e6

9 files changed

Lines changed: 571 additions & 508 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ API
99
from bblfsh import BblfshClient
1010
1111
client = BblfshClient("0.0.0.0:9432")
12-
print(client.parse_uast("/path/to/file.py"))
12+
print(client.parse("/path/to/file.py"))
1313
```
1414

1515
Command line

bblfsh/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def main():
2727
if not args.disable_bblfsh_autorun:
2828
ensure_bblfsh_is_running()
2929
client = BblfshClient(args.endpoint)
30-
print(client.parse_uast(args.file, args.language))
30+
print(client.parse(args.file, args.language))
3131

3232

3333
if __name__ == "__main__":

bblfsh/client.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
sys.path.insert(0, os.path.join(os.path.dirname(__file__),
88
"github/com/bblfsh/sdk/protocol"))
99
sys.path.insert(0, os.path.dirname(__file__))
10-
from bblfsh.github.com.bblfsh.sdk.protocol.generated_pb2 import ParseUASTRequest
10+
from bblfsh.github.com.bblfsh.sdk.protocol.generated_pb2 import ParseRequest
1111
from bblfsh.github.com.bblfsh.sdk.protocol.generated_pb2_grpc import ProtocolServiceStub
1212

1313

@@ -27,7 +27,7 @@ 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(self, filename, language=None, contents=None, timeout=None,
3131
unicode_errors="ignore"):
3232
"""
3333
Queries the Babelfish server and receives the UAST for the specified
@@ -52,10 +52,10 @@ def parse_uast(self, filename, language=None, contents=None, timeout=None,
5252
if contents is None:
5353
with open(filename, errors=unicode_errors) as fin:
5454
contents = fin.read()
55-
request = ParseUASTRequest(filename=os.path.basename(filename),
55+
request = ParseRequest(filename=os.path.basename(filename),
5656
content=contents,
5757
language=self._scramble_language(language))
58-
response = self._stub.ParseUAST(request, timeout=timeout)
58+
response = self._stub.Parse(request, timeout=timeout)
5959
return response
6060

6161
@staticmethod

bblfsh/github/com/bblfsh/sdk/protocol/generated_pb2.py

Lines changed: 98 additions & 58 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bblfsh/github/com/bblfsh/sdk/protocol/generated_pb2_grpc.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ def __init__(self, channel):
1212
Args:
1313
channel: A grpc.Channel.
1414
"""
15-
self.ParseUAST = channel.unary_unary(
16-
'/github.com.bblfsh.sdk.protocol.ProtocolService/ParseUAST',
17-
request_serializer=generated__pb2.ParseUASTRequest.SerializeToString,
18-
response_deserializer=generated__pb2.ParseUASTResponse.FromString,
15+
self.Parse = channel.unary_unary(
16+
'/github.com.bblfsh.sdk.protocol.ProtocolService/Parse',
17+
request_serializer=generated__pb2.ParseRequest.SerializeToString,
18+
response_deserializer=generated__pb2.ParseResponse.FromString,
1919
)
2020

2121

2222
class ProtocolServiceServicer(object):
2323

24-
def ParseUAST(self, request, context):
25-
"""ParseUAST uses DefaultParser to process the given UAST parsing request.
24+
def Parse(self, request, context):
25+
"""Parse uses DefaultParser to process the given parsing request to get the UAST.
2626
"""
2727
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
2828
context.set_details('Method not implemented!')
@@ -31,10 +31,10 @@ def ParseUAST(self, request, context):
3131

3232
def add_ProtocolServiceServicer_to_server(servicer, server):
3333
rpc_method_handlers = {
34-
'ParseUAST': grpc.unary_unary_rpc_method_handler(
35-
servicer.ParseUAST,
36-
request_deserializer=generated__pb2.ParseUASTRequest.FromString,
37-
response_serializer=generated__pb2.ParseUASTResponse.SerializeToString,
34+
'Parse': grpc.unary_unary_rpc_method_handler(
35+
servicer.Parse,
36+
request_deserializer=generated__pb2.ParseRequest.FromString,
37+
response_serializer=generated__pb2.ParseResponse.SerializeToString,
3838
),
3939
}
4040
generic_handler = grpc.method_handlers_generic_handler(

bblfsh/github/com/bblfsh/sdk/uast/generated_pb2.py

Lines changed: 290 additions & 283 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bblfsh/test.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import docker
44

55
from bblfsh import BblfshClient
6-
from bblfsh.github.com.bblfsh.sdk.protocol.generated_pb2 import ParseUASTResponse
6+
from bblfsh.github.com.bblfsh.sdk.protocol.generated_pb2 import ParseResponse
77
from github.com.bblfsh.sdk.uast.generated_pb2 import Node
88
from bblfsh.launcher import ensure_bblfsh_is_running
99

@@ -26,24 +26,24 @@ def setUp(self):
2626
self.client = BblfshClient("0.0.0.0:9432")
2727

2828
def testUASTDefaultLanguage(self):
29-
uast = self.client.parse_uast(__file__)
29+
uast = self.client.parse(__file__)
3030
self._validate_uast(uast)
3131

3232
def testUASTPython(self):
33-
uast = self.client.parse_uast(__file__, language="Python")
33+
uast = self.client.parse(__file__, language="Python")
3434
self._validate_uast(uast)
3535

3636
def testUASTFileContents(self):
3737
with open(__file__) as fin:
3838
contents = fin.read()
39-
uast = self.client.parse_uast("file.py", contents=contents)
39+
uast = self.client.parse("file.py", contents=contents)
4040
self._validate_uast(uast)
4141

4242
def _validate_uast(self, uast):
4343
self.assertIsNotNone(uast)
4444
# self.assertIsInstance() does not work - must be some metaclass magic
4545
self.assertEqual(type(uast).DESCRIPTOR.full_name,
46-
ParseUASTResponse.DESCRIPTOR.full_name)
46+
ParseResponse.DESCRIPTOR.full_name)
4747
self.assertEqual(len(uast.errors), 0)
4848
self.assertIsInstance(uast.uast, Node)
4949

github.com/bblfsh/sdk/protocol/generated.proto

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,38 @@ option (gogoproto.protosizer_all) = true;
88
option (gogoproto.sizer_all) = false;
99
option go_package = "protocol";
1010

11-
// ParseUASTRequest is a request to parse a file and get its UAST.
12-
message ParseUASTRequest {
11+
// ParseRequest is a request to parse a file and get its UAST.
12+
message ParseRequest {
1313
option (gogoproto.goproto_getters) = false;
1414
option (gogoproto.typedecl) = false;
1515
string filename = 1;
1616
string language = 2;
1717
string content = 3;
18+
github.com.bblfsh.sdk.protocol.Encoding encoding = 4;
1819
}
1920

20-
// ParseUASTResponse is the reply to ParseUASTRequest.
21-
message ParseUASTResponse {
21+
// ParseResponse is the reply to ParseRequest.
22+
message ParseResponse {
2223
option (gogoproto.goproto_getters) = false;
2324
option (gogoproto.typedecl) = false;
2425
github.com.bblfsh.sdk.protocol.Status status = 1;
2526
repeated string errors = 2;
2627
github.com.bblfsh.sdk.uast.Node uast = 3 [(gogoproto.customname) = "UAST"];
2728
}
2829

30+
// Encoding is the encoding used for the content string. Currently only
31+
// UTF-8 or Base64 encodings are supported. You should use UTF-8 if you can
32+
// and Base64 as a fallback.
33+
enum Encoding {
34+
option (gogoproto.enumdecl) = false;
35+
option (gogoproto.goproto_enum_prefix) = false;
36+
option (gogoproto.goproto_enum_stringer) = false;
37+
// UTF8 encoding
38+
UTF8 = 0 [(gogoproto.enumvalue_customname) = "UTF8"];
39+
// Base64 encoding
40+
BASE64 = 1 [(gogoproto.enumvalue_customname) = "Base64"];
41+
}
42+
2943
// Status is the status of a response.
3044
enum Status {
3145
option (gogoproto.enumdecl) = false;
@@ -40,7 +54,7 @@ enum Status {
4054
}
4155

4256
service ProtocolService {
43-
// ParseUAST uses DefaultParser to process the given UAST parsing request.
44-
rpc ParseUAST (github.com.bblfsh.sdk.protocol.ParseUASTRequest) returns (github.com.bblfsh.sdk.protocol.ParseUASTResponse);
57+
// Parse uses DefaultParser to process the given parsing request to get the UAST.
58+
rpc Parse (github.com.bblfsh.sdk.protocol.ParseRequest) returns (github.com.bblfsh.sdk.protocol.ParseResponse);
4559
}
4660

0 commit comments

Comments
 (0)