Sun, 31 Dec 2017 16:52:09 +0100
Updated copyright for 2018.
5977
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
1 | # -*- coding: utf-8 -*- |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
2 | |
6048
82ad8ec9548c
Updated copyright for 2018.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5977
diff
changeset
|
3 | # Copyright (c) 2017 - 2018 Detlev Offenbach <detlev@die-offenbachs.de> |
5977
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
4 | # |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
5 | |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
6 | """ |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
7 | Parse a ProtoBuf protocol file and retrieve messages, enums, services and |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
8 | rpc methods. |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
9 | |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
10 | It is based on the Python class browser found in this package. |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
11 | """ |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
12 | |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
13 | from __future__ import unicode_literals |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
14 | |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
15 | import re |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
16 | |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
17 | import Utilities |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
18 | import Utilities.ClassBrowsers as ClassBrowsers |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
19 | from . import ClbrBaseClasses |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
20 | |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
21 | SUPPORTED_TYPES = [ClassBrowsers.PROTO_SOURCE] |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
22 | |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
23 | _getnext = re.compile( |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
24 | r""" |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
25 | (?P<String> |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
26 | " [^"\\\n]* (?: \\. [^"\\\n]*)* " |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
27 | ) |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
28 | |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
29 | | (?P<Comment> |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
30 | ^ [ \t]* // .*? $ |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
31 | | |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
32 | ^ [ \t]* /\* .*? \*/ |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
33 | ) |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
34 | |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
35 | | (?P<Message> |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
36 | ^ |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
37 | (?P<MessageIndent> [ \t]* ) |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
38 | message [ \t]+ |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
39 | (?P<MessageName> [a-zA-Z_] [a-zA-Z0-9_]* ) |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
40 | [ \t]* { |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
41 | ) |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
42 | |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
43 | | (?P<Enum> |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
44 | ^ |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
45 | (?P<EnumIndent> [ \t]* ) |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
46 | enum [ \t]+ |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
47 | (?P<EnumName> [a-zA-Z_] [a-zA-Z0-9_]* ) |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
48 | [ \t]* { |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
49 | ) |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
50 | |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
51 | | (?P<Service> |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
52 | ^ |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
53 | (?P<ServiceIndent> [ \t]* ) |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
54 | service [ \t]+ |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
55 | (?P<ServiceName> [a-zA-Z_] [a-zA-Z0-9_]* ) |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
56 | [ \t]* { |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
57 | ) |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
58 | |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
59 | | (?P<Method> |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
60 | ^ |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
61 | (?P<MethodIndent> [ \t]* ) |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
62 | rpc [ \t]+ |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
63 | (?P<MethodName> [a-zA-Z_] [a-zA-Z0-9_]* ) |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
64 | [ \t]* |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
65 | \( |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
66 | (?P<MethodSignature> [^)]+? ) |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
67 | \) |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
68 | [ \t]+ |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
69 | returns |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
70 | [ \t]* |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
71 | \( |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
72 | (?P<MethodReturn> [^)]+? ) |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
73 | \) |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
74 | [ \t]* |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
75 | ) |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
76 | |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
77 | | (?P<Begin> |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
78 | [ \t]* { |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
79 | ) |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
80 | |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
81 | | (?P<End> |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
82 | [ \t]* } [ \t]* ;? |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
83 | )""", |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
84 | re.VERBOSE | re.DOTALL | re.MULTILINE).search |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
85 | |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
86 | # function to replace comments |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
87 | _commentsub = re.compile(r"""//[^\n]*\n|//[^\n]*$""").sub |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
88 | # function to normalize whitespace |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
89 | _normalize = re.compile(r"""[ \t]{2,}""").sub |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
90 | |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
91 | _modules = {} # cache of modules we've seen |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
92 | |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
93 | |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
94 | class VisibilityMixin(ClbrBaseClasses.ClbrVisibilityMixinBase): |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
95 | """ |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
96 | Mixin class implementing the notion of visibility. |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
97 | """ |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
98 | def __init__(self): |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
99 | """ |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
100 | Constructor |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
101 | """ |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
102 | self.setPublic() |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
103 | |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
104 | |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
105 | class Message(ClbrBaseClasses.Module, VisibilityMixin): |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
106 | """ |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
107 | Class to represent a ProtoBuf Message. |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
108 | """ |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
109 | def __init__(self, module, name, file, lineno): |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
110 | """ |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
111 | Constructor |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
112 | |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
113 | @param module name of the module containing this message |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
114 | @type str |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
115 | @param name name of this message |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
116 | @type str |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
117 | @param file filename containing this message |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
118 | @type str |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
119 | @param lineno linenumber of the message definition |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
120 | @type int |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
121 | """ |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
122 | ClbrBaseClasses.Module.__init__(self, module, name, file, lineno) |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
123 | VisibilityMixin.__init__(self) |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
124 | |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
125 | |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
126 | class Enum(ClbrBaseClasses.Enum, VisibilityMixin): |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
127 | """ |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
128 | Class to represent a ProtoBuf Enum. |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
129 | """ |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
130 | def __init__(self, module, name, file, lineno): |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
131 | """ |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
132 | Constructor |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
133 | |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
134 | @param module name of the module containing this enum |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
135 | @type str |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
136 | @param name name of this enum |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
137 | @type str |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
138 | @param file filename containing this enum |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
139 | @type str |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
140 | @param lineno linenumber of the message enum |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
141 | @type int |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
142 | """ |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
143 | ClbrBaseClasses.Enum.__init__(self, module, name, file, lineno) |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
144 | VisibilityMixin.__init__(self) |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
145 | |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
146 | |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
147 | class Service(ClbrBaseClasses.Class, VisibilityMixin): |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
148 | """ |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
149 | Class to represent a ProtoBuf Service. |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
150 | """ |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
151 | def __init__(self, module, name, file, lineno): |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
152 | """ |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
153 | Constructor |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
154 | |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
155 | @param module name of the module containing this service |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
156 | @type str |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
157 | @param name name of this service |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
158 | @type str |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
159 | @param file filename containing this service |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
160 | @type str |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
161 | @param lineno linenumber of the service definition |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
162 | @type int |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
163 | """ |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
164 | ClbrBaseClasses.Class.__init__(self, module, name, None, file, |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
165 | lineno) |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
166 | VisibilityMixin.__init__(self) |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
167 | |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
168 | |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
169 | class ServiceMethod(ClbrBaseClasses.Function, VisibilityMixin): |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
170 | """ |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
171 | Class to represent a ProtoBuf Service Method. |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
172 | """ |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
173 | def __init__(self, name, file, lineno, signature, returns): |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
174 | """ |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
175 | Constructor |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
176 | |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
177 | @param name name of this service method |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
178 | @type str |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
179 | @param file filename containing this service method |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
180 | @type str |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
181 | @param lineno linenumber of the service method definition |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
182 | @type int |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
183 | @param signature parameter list of the service method |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
184 | @type str |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
185 | @param returns return type of the service method |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
186 | @type str |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
187 | """ |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
188 | ClbrBaseClasses.Function.__init__(self, None, name, file, lineno, |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
189 | signature, |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
190 | annotation="-> {0}".format(returns)) |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
191 | VisibilityMixin.__init__(self) |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
192 | |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
193 | |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
194 | def readmodule_ex(module, path=None): |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
195 | """ |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
196 | Read a ProtoBuf protocol file and return a dictionary of messages, enums, |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
197 | services and rpc methods. |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
198 | |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
199 | @param module name of the ProtoBuf protocol file |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
200 | @type str |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
201 | @param path path the file should be searched in |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
202 | @type list of str |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
203 | @return the resulting dictionary |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
204 | @rtype dict |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
205 | """ |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
206 | global _modules |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
207 | |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
208 | dictionary = {} |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
209 | |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
210 | if module in _modules: |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
211 | # we've seen this file before... |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
212 | return _modules[module] |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
213 | |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
214 | # search the path for the file |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
215 | f = None |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
216 | fullpath = [] if path is None else path[:] |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
217 | f, file, (suff, mode, type) = ClassBrowsers.find_module(module, fullpath) |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
218 | if f: |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
219 | f.close() |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
220 | if type not in SUPPORTED_TYPES: |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
221 | # not ProtoBuf protocol source, can't do anything with this module |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
222 | _modules[module] = dictionary |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
223 | return dictionary |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
224 | |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
225 | _modules[module] = dictionary |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
226 | classstack = [] # stack of (class, indent) pairs |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
227 | indent = 0 |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
228 | try: |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
229 | src = Utilities.readEncodedFile(file)[0] |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
230 | except (UnicodeError, IOError): |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
231 | # can't do anything with this module |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
232 | _modules[module] = dictionary |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
233 | return dictionary |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
234 | |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
235 | lineno, last_lineno_pos = 1, 0 |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
236 | lastGlobalEntry = None |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
237 | cur_obj = None |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
238 | i = 0 |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
239 | while True: |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
240 | m = _getnext(src, i) |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
241 | if not m: |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
242 | break |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
243 | start, i = m.span() |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
244 | |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
245 | if m.start("Method") >= 0: |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
246 | # found a method definition or function |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
247 | thisindent = indent |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
248 | meth_name = m.group("MethodName") |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
249 | meth_sig = m.group("MethodSignature") |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
250 | meth_sig = meth_sig and meth_sig.replace('\\\n', '') or '' |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
251 | meth_sig = _commentsub('', meth_sig) |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
252 | meth_sig = _normalize(' ', meth_sig) |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
253 | meth_return = m.group("MethodReturn") |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
254 | meth_return = meth_return and meth_return.replace('\\\n', '') or '' |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
255 | meth_return = _commentsub('', meth_return) |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
256 | meth_return = _normalize(' ', meth_return) |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
257 | lineno = lineno + src.count('\n', last_lineno_pos, start) |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
258 | last_lineno_pos = start |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
259 | # close all interfaces/modules indented at least as much |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
260 | while classstack and \ |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
261 | classstack[-1][1] >= thisindent: |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
262 | if classstack[-1][0] is not None: |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
263 | # record the end line |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
264 | classstack[-1][0].setEndLine(lineno - 1) |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
265 | del classstack[-1] |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
266 | if classstack: |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
267 | # it's an interface/module method |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
268 | cur_class = classstack[-1][0] |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
269 | if isinstance(cur_class, Service): |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
270 | # it's a method |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
271 | f = ServiceMethod(meth_name, file, lineno, meth_sig, |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
272 | meth_return) |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
273 | cur_class._addmethod(meth_name, f) |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
274 | # else it's a nested def |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
275 | else: |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
276 | f = None |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
277 | else: |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
278 | # the file is incorrect, ignore the entry |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
279 | continue |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
280 | if not classstack: |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
281 | if lastGlobalEntry: |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
282 | lastGlobalEntry.setEndLine(lineno - 1) |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
283 | lastGlobalEntry = f |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
284 | if cur_obj and isinstance(cur_obj, ServiceMethod): |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
285 | cur_obj.setEndLine(lineno - 1) |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
286 | cur_obj = f |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
287 | classstack.append((f, thisindent)) # Marker for nested fns |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
288 | |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
289 | elif m.start("String") >= 0: |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
290 | pass |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
291 | |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
292 | elif m.start("Comment") >= 0: |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
293 | pass |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
294 | |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
295 | elif m.start("Message") >= 0: |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
296 | # we found a message definition |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
297 | thisindent = indent |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
298 | indent += 1 |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
299 | # close all messages/services indented at least as much |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
300 | while classstack and \ |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
301 | classstack[-1][1] >= thisindent: |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
302 | if classstack[-1][0] is not None: |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
303 | # record the end line |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
304 | classstack[-1][0].setEndLine(lineno - 1) |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
305 | del classstack[-1] |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
306 | lineno = lineno + src.count('\n', last_lineno_pos, start) |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
307 | last_lineno_pos = start |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
308 | message_name = m.group("MessageName") |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
309 | # remember this message |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
310 | cur_class = Message(module, message_name, file, lineno) |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
311 | if not classstack: |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
312 | dictionary[message_name] = cur_class |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
313 | else: |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
314 | msg = classstack[-1][0] |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
315 | msg._addclass(message_name, cur_class) |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
316 | if not classstack: |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
317 | if lastGlobalEntry: |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
318 | lastGlobalEntry.setEndLine(lineno - 1) |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
319 | lastGlobalEntry = cur_class |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
320 | cur_obj = cur_class |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
321 | classstack.append((cur_class, thisindent)) |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
322 | |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
323 | elif m.start("Enum") >= 0: |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
324 | # we found a message definition |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
325 | thisindent = indent |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
326 | indent += 1 |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
327 | # close all messages/services indented at least as much |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
328 | while classstack and \ |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
329 | classstack[-1][1] >= thisindent: |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
330 | if classstack[-1][0] is not None: |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
331 | # record the end line |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
332 | classstack[-1][0].setEndLine(lineno - 1) |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
333 | del classstack[-1] |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
334 | lineno = lineno + src.count('\n', last_lineno_pos, start) |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
335 | last_lineno_pos = start |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
336 | enum_name = m.group("EnumName") |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
337 | # remember this Enum |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
338 | cur_class = Enum(module, enum_name, file, lineno) |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
339 | if not classstack: |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
340 | dictionary[enum_name] = cur_class |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
341 | else: |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
342 | enum = classstack[-1][0] |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
343 | enum._addclass(enum_name, cur_class) |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
344 | if not classstack: |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
345 | if lastGlobalEntry: |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
346 | lastGlobalEntry.setEndLine(lineno - 1) |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
347 | lastGlobalEntry = cur_class |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
348 | cur_obj = cur_class |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
349 | classstack.append((cur_class, thisindent)) |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
350 | |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
351 | elif m.start("Service") >= 0: |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
352 | # we found a message definition |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
353 | thisindent = indent |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
354 | indent += 1 |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
355 | # close all messages/services indented at least as much |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
356 | while classstack and \ |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
357 | classstack[-1][1] >= thisindent: |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
358 | if classstack[-1][0] is not None: |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
359 | # record the end line |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
360 | classstack[-1][0].setEndLine(lineno - 1) |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
361 | del classstack[-1] |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
362 | lineno = lineno + src.count('\n', last_lineno_pos, start) |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
363 | last_lineno_pos = start |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
364 | service_name = m.group("ServiceName") |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
365 | # remember this Service |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
366 | cur_class = Service(module, service_name, file, lineno) |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
367 | if not classstack: |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
368 | dictionary[service_name] = cur_class |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
369 | else: |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
370 | service = classstack[-1][0] |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
371 | service._addclass(service_name, cur_class) |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
372 | if not classstack: |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
373 | if lastGlobalEntry: |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
374 | lastGlobalEntry.setEndLine(lineno - 1) |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
375 | lastGlobalEntry = cur_class |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
376 | cur_obj = cur_class |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
377 | classstack.append((cur_class, thisindent)) |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
378 | |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
379 | elif m.start("Begin") >= 0: |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
380 | # a begin of a block we are not interested in |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
381 | indent += 1 |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
382 | |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
383 | elif m.start("End") >= 0: |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
384 | # an end of a block |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
385 | indent -= 1 |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
386 | |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
387 | else: |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
388 | assert 0, "regexp _getnext found something unexpected" |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
389 | |
8a0ec75b0f73
Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
390 | return dictionary |