src/eric7/Utilities/ClassBrowsers/protoclbr.py

Mon, 07 Nov 2022 17:19:58 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Mon, 07 Nov 2022 17:19:58 +0100
branch
eric7
changeset 9482
a2bc06a54d9d
parent 9473
3f23dbf37dbe
child 9490
77b8d3a635b7
permissions
-rw-r--r--

Corrected/acknowledged some bad import style and removed some obsolete code.

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
8881
54e42bc2437a Updated copyright for 2022.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8312
diff changeset
3 # Copyright (c) 2017 - 2022 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 import re
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14
9413
80c06d472826 Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
15 from eric7 import Utilities
80c06d472826 Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
16 from eric7.Utilities import ClassBrowsers
9473
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9413
diff changeset
17
5977
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 from . import ClbrBaseClasses
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 SUPPORTED_TYPES = [ClassBrowsers.PROTO_SOURCE]
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
21
5977
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 _getnext = re.compile(
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 r"""
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 (?P<String>
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 " [^"\\\n]* (?: \\. [^"\\\n]*)* "
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 )
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 | (?P<Comment>
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 ^ [ \t]* // .*? $
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 |
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 ^ [ \t]* /\* .*? \*/
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 )
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 | (?P<Message>
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 ^
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 (?P<MessageIndent> [ \t]* )
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 message [ \t]+
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 (?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
39 [ \t]* {
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 )
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 | (?P<Enum>
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 ^
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 (?P<EnumIndent> [ \t]* )
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 enum [ \t]+
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 (?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
47 [ \t]* {
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 )
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 | (?P<Service>
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 ^
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 (?P<ServiceIndent> [ \t]* )
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 service [ \t]+
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 (?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
55 [ \t]* {
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 )
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 | (?P<Method>
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 ^
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 (?P<MethodIndent> [ \t]* )
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 rpc [ \t]+
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 (?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
63 [ \t]*
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 \(
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 (?P<MethodSignature> [^)]+? )
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 \)
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 [ \t]+
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 returns
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 [ \t]*
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 \(
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 (?P<MethodReturn> [^)]+? )
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 \)
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 [ \t]*
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 )
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 | (?P<Begin>
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 [ \t]* {
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 )
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 | (?P<End>
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 [ \t]* } [ \t]* ;?
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 )""",
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
83 re.VERBOSE | re.DOTALL | re.MULTILINE,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
84 ).search
5977
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
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
91 _modules = {} # cache of modules we've seen
5977
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 """
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
98
5977
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99 def __init__(self):
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 """
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101 Constructor
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102 """
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103 self.setPublic()
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
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106 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
107 """
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 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
109 """
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
110
5977
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111 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
112 """
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113 Constructor
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
114
5977
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115 @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
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 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
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 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
120 @type str
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121 @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
122 @type int
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123 """
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124 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
125 VisibilityMixin.__init__(self)
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126
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 Enum(ClbrBaseClasses.Enum, VisibilityMixin):
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 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
131 """
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
132
5977
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
133 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
134 """
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
135 Constructor
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
136
5977
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
137 @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
138 @type str
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
139 @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
140 @type str
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
141 @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
142 @type str
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
143 @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
144 @type int
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 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
147 VisibilityMixin.__init__(self)
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
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
150 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
151 """
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
152 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
153 """
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
154
5977
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
155 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
156 """
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
157 Constructor
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
158
5977
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
159 @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
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 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
162 @type str
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
163 @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
164 @type str
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
165 @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
166 @type int
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
167 """
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
168 ClbrBaseClasses.Class.__init__(self, module, name, None, file, lineno)
5977
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
169 VisibilityMixin.__init__(self)
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
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
172 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
173 """
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
174 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
175 """
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
176
5977
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
177 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
178 """
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
179 Constructor
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
180
5977
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
181 @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
182 @type str
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
183 @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
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 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
186 @type int
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
187 @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
188 @type str
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
189 @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
190 @type str
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
191 """
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
192 ClbrBaseClasses.Function.__init__(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
193 self,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
194 None,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
195 name,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
196 file,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
197 lineno,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
198 signature,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
199 annotation="-> {0}".format(returns),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
200 )
5977
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
201 VisibilityMixin.__init__(self)
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
202
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
203
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
204 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
205 """
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
206 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
207 services and rpc methods.
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
208
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
209 @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
210 @type str
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
211 @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
212 @type list of str
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
213 @return the resulting dictionary
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
214 @rtype dict
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
215 """
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
216 global _modules
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
217
5977
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
218 if module in _modules:
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
219 # 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
220 return _modules[module]
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
221
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
222 # 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
223 f = None
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
224 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
225 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
226 if f:
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
227 f.close()
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
228 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
229 # not ProtoBuf protocol source, can't do anything with this module
7690
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
230 _modules[module] = {}
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
231 return {}
5977
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
232
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
233 try:
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
234 src = Utilities.readEncodedFile(file)[0]
7836
2f0d208b8137 Changed code to not use the OSError aliases (IOError, EnvironmentError, socket.error and select.error) anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7781
diff changeset
235 except (UnicodeError, OSError):
5977
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
236 # can't do anything with this module
7690
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
237 _modules[module] = {}
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
238 return {}
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
239
7690
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
240 _modules[module] = scan(src, file, module)
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
241 return _modules[module]
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
242
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
243
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
244 def scan(src, file, module):
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
245 """
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
246 Public method to scan the given source text.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
247
7690
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
248 @param src source text to be scanned
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
249 @type str
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
250 @param file file name associated with the source text
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
251 @type str
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
252 @param module module name associated with the source text
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
253 @type str
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
254 @return dictionary containing the extracted data
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
255 @rtype dict
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
256 """
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
257
7699
d338c533f5f0 Class browsers: improved endline detection for the Python, IDL and ProtoBuf source code browsers and the Python module parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7695
diff changeset
258 def calculateEndline(lineno, lines):
d338c533f5f0 Class browsers: improved endline detection for the Python, IDL and ProtoBuf source code browsers and the Python module parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7695
diff changeset
259 """
d338c533f5f0 Class browsers: improved endline detection for the Python, IDL and ProtoBuf source code browsers and the Python module parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7695
diff changeset
260 Function to calculate the end line.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
261
7699
d338c533f5f0 Class browsers: improved endline detection for the Python, IDL and ProtoBuf source code browsers and the Python module parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7695
diff changeset
262 @param lineno line number to start at (one based)
d338c533f5f0 Class browsers: improved endline detection for the Python, IDL and ProtoBuf source code browsers and the Python module parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7695
diff changeset
263 @type int
d338c533f5f0 Class browsers: improved endline detection for the Python, IDL and ProtoBuf source code browsers and the Python module parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7695
diff changeset
264 @param lines list of source lines
d338c533f5f0 Class browsers: improved endline detection for the Python, IDL and ProtoBuf source code browsers and the Python module parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7695
diff changeset
265 @type list of str
d338c533f5f0 Class browsers: improved endline detection for the Python, IDL and ProtoBuf source code browsers and the Python module parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7695
diff changeset
266 @return end line (one based)
d338c533f5f0 Class browsers: improved endline detection for the Python, IDL and ProtoBuf source code browsers and the Python module parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7695
diff changeset
267 @rtype int
d338c533f5f0 Class browsers: improved endline detection for the Python, IDL and ProtoBuf source code browsers and the Python module parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7695
diff changeset
268 """
d338c533f5f0 Class browsers: improved endline detection for the Python, IDL and ProtoBuf source code browsers and the Python module parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7695
diff changeset
269 # convert lineno to be zero based
d338c533f5f0 Class browsers: improved endline detection for the Python, IDL and ProtoBuf source code browsers and the Python module parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7695
diff changeset
270 lineno -= 1
d338c533f5f0 Class browsers: improved endline detection for the Python, IDL and ProtoBuf source code browsers and the Python module parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7695
diff changeset
271 # 1. search for opening brace '{'
7706
0c6d32ec64f1 Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7699
diff changeset
272 while lineno < len(lines) and "{" not in lines[lineno]:
7699
d338c533f5f0 Class browsers: improved endline detection for the Python, IDL and ProtoBuf source code browsers and the Python module parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7695
diff changeset
273 lineno += 1
d338c533f5f0 Class browsers: improved endline detection for the Python, IDL and ProtoBuf source code browsers and the Python module parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7695
diff changeset
274 depth = lines[lineno].count("{") - lines[lineno].count("}")
d338c533f5f0 Class browsers: improved endline detection for the Python, IDL and ProtoBuf source code browsers and the Python module parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7695
diff changeset
275 # 2. search for ending line, i.e. matching closing brace '}'
d338c533f5f0 Class browsers: improved endline detection for the Python, IDL and ProtoBuf source code browsers and the Python module parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7695
diff changeset
276 while depth > 0 and lineno < len(lines) - 1:
d338c533f5f0 Class browsers: improved endline detection for the Python, IDL and ProtoBuf source code browsers and the Python module parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7695
diff changeset
277 lineno += 1
d338c533f5f0 Class browsers: improved endline detection for the Python, IDL and ProtoBuf source code browsers and the Python module parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7695
diff changeset
278 depth += lines[lineno].count("{") - lines[lineno].count("}")
d338c533f5f0 Class browsers: improved endline detection for the Python, IDL and ProtoBuf source code browsers and the Python module parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7695
diff changeset
279 if depth == 0:
d338c533f5f0 Class browsers: improved endline detection for the Python, IDL and ProtoBuf source code browsers and the Python module parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7695
diff changeset
280 # found a matching brace
d338c533f5f0 Class browsers: improved endline detection for the Python, IDL and ProtoBuf source code browsers and the Python module parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7695
diff changeset
281 return lineno + 1
d338c533f5f0 Class browsers: improved endline detection for the Python, IDL and ProtoBuf source code browsers and the Python module parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7695
diff changeset
282 else:
d338c533f5f0 Class browsers: improved endline detection for the Python, IDL and ProtoBuf source code browsers and the Python module parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7695
diff changeset
283 # nothing found
d338c533f5f0 Class browsers: improved endline detection for the Python, IDL and ProtoBuf source code browsers and the Python module parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7695
diff changeset
284 return -1
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
285
7676
0f67b4562d98 ClassBrowsers: added code to treat source texts like Python (universal newline).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7628
diff changeset
286 # convert eol markers the Python style
0f67b4562d98 ClassBrowsers: added code to treat source texts like Python (universal newline).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7628
diff changeset
287 src = src.replace("\r\n", "\n").replace("\r", "\n")
7699
d338c533f5f0 Class browsers: improved endline detection for the Python, IDL and ProtoBuf source code browsers and the Python module parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7695
diff changeset
288 srcLines = src.splitlines()
5977
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
289
7690
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
290 dictionary = {}
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
291
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
292 classstack = [] # stack of (class, indent) pairs
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
293 indent = 0
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
294
5977
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
295 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
296 i = 0
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
297 while True:
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
298 m = _getnext(src, i)
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
299 if not m:
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
300 break
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
301 start, i = m.span()
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
302
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
303 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
304 # 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
305 thisindent = indent
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
306 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
307 meth_sig = m.group("MethodSignature")
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
308 meth_sig = meth_sig and meth_sig.replace("\\\n", "") or ""
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
309 meth_sig = _commentsub("", meth_sig)
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
310 meth_sig = _normalize(" ", meth_sig)
5977
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
311 meth_return = m.group("MethodReturn")
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
312 meth_return = meth_return and meth_return.replace("\\\n", "") or ""
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
313 meth_return = _commentsub("", meth_return)
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
314 meth_return = _normalize(" ", meth_return)
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
315 lineno += src.count("\n", last_lineno_pos, start)
5977
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
316 last_lineno_pos = start
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
317 # close all interfaces/modules indented at least as much
7259
7c017076c12e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
318 while classstack and classstack[-1][1] >= thisindent:
5977
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
319 del classstack[-1]
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
320 if classstack:
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
321 # 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
322 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
323 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
324 # it's a method
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
325 f = ServiceMethod(meth_name, file, lineno, meth_sig, meth_return)
5977
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
326 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
327 # 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
328 else:
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
329 f = None
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
330 else:
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
331 # 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
332 continue
7699
d338c533f5f0 Class browsers: improved endline detection for the Python, IDL and ProtoBuf source code browsers and the Python module parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7695
diff changeset
333 if f:
d338c533f5f0 Class browsers: improved endline detection for the Python, IDL and ProtoBuf source code browsers and the Python module parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7695
diff changeset
334 endline = calculateEndline(lineno, srcLines)
d338c533f5f0 Class browsers: improved endline detection for the Python, IDL and ProtoBuf source code browsers and the Python module parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7695
diff changeset
335 f.setEndLine(endline)
5977
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
336 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
337
8228
772103b14c18 Applied some more code simplifications suggested by the new Simplify checker (Y114: use logical or for multiple if).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8217
diff changeset
338 elif m.start("String") >= 0 or m.start("Comment") >= 0:
5977
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
339 pass
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
340
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
341 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
342 # 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
343 thisindent = indent
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
344 indent += 1
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
345 lineno += src.count("\n", last_lineno_pos, start)
7695
032a0586a349 protoclbr: fixed an issue caused by an unitialized variable.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7690
diff changeset
346 last_lineno_pos = start
032a0586a349 protoclbr: fixed an issue caused by an unitialized variable.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7690
diff changeset
347 message_name = m.group("MessageName")
5977
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
348 # close all messages/services indented at least as much
7259
7c017076c12e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
349 while classstack and classstack[-1][1] >= thisindent:
5977
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
350 del classstack[-1]
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
351 # remember this message
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
352 cur_class = Message(module, message_name, file, lineno)
7699
d338c533f5f0 Class browsers: improved endline detection for the Python, IDL and ProtoBuf source code browsers and the Python module parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7695
diff changeset
353 endline = calculateEndline(lineno, srcLines)
d338c533f5f0 Class browsers: improved endline detection for the Python, IDL and ProtoBuf source code browsers and the Python module parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7695
diff changeset
354 cur_class.setEndLine(endline)
5977
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
355 if not classstack:
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
356 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
357 else:
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
358 msg = classstack[-1][0]
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
359 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
360 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
361
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
362 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
363 # 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
364 thisindent = indent
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
365 indent += 1
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
366 # close all messages/services indented at least as much
7259
7c017076c12e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
367 while classstack and classstack[-1][1] >= thisindent:
5977
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
368 del classstack[-1]
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
369 lineno += src.count("\n", last_lineno_pos, start)
5977
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
370 last_lineno_pos = start
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
371 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
372 # remember this Enum
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
373 cur_class = Enum(module, enum_name, file, lineno)
7699
d338c533f5f0 Class browsers: improved endline detection for the Python, IDL and ProtoBuf source code browsers and the Python module parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7695
diff changeset
374 endline = calculateEndline(lineno, srcLines)
d338c533f5f0 Class browsers: improved endline detection for the Python, IDL and ProtoBuf source code browsers and the Python module parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7695
diff changeset
375 cur_class.setEndLine(endline)
5977
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
376 if not classstack:
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
377 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
378 else:
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
379 enum = classstack[-1][0]
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
380 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
381 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
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("Service") >= 0:
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
384 # 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
385 thisindent = indent
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
386 indent += 1
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
387 # close all messages/services indented at least as much
7259
7c017076c12e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
388 while classstack and classstack[-1][1] >= thisindent:
5977
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
389 del classstack[-1]
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
390 lineno += src.count("\n", last_lineno_pos, start)
5977
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
391 last_lineno_pos = start
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
392 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
393 # remember this Service
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
394 cur_class = Service(module, service_name, file, lineno)
7699
d338c533f5f0 Class browsers: improved endline detection for the Python, IDL and ProtoBuf source code browsers and the Python module parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7695
diff changeset
395 endline = calculateEndline(lineno, srcLines)
d338c533f5f0 Class browsers: improved endline detection for the Python, IDL and ProtoBuf source code browsers and the Python module parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7695
diff changeset
396 cur_class.setEndLine(endline)
5977
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
397 if not classstack:
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
398 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
399 else:
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
400 service = classstack[-1][0]
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
401 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
402 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
403
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
404 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
405 # 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
406 indent += 1
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
407
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
408 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
409 # 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
410 indent -= 1
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
411
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
412 return dictionary

eric ide

mercurial