src/eric7/Utilities/ClassBrowsers/protoclbr.py

Tue, 18 Oct 2022 16:06:21 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Tue, 18 Oct 2022 16:06:21 +0200
branch
eric7
changeset 9413
80c06d472826
parent 9221
bf71ee032bb4
child 9473
3f23dbf37dbe
permissions
-rw-r--r--

Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.

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
5977
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 from . import ClbrBaseClasses
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 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
20
5977
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 _getnext = re.compile(
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 r"""
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 (?P<String>
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 " [^"\\\n]* (?: \\. [^"\\\n]*)* "
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 )
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 | (?P<Comment>
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 ^ [ \t]* // .*? $
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 |
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
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 | (?P<Message>
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<MessageIndent> [ \t]* )
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 message [ \t]+
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 (?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
38 [ \t]* {
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 )
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 | (?P<Enum>
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<EnumIndent> [ \t]* )
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 enum [ \t]+
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 (?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
46 [ \t]* {
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 )
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 | (?P<Service>
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<ServiceIndent> [ \t]* )
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 service [ \t]+
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 (?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
54 [ \t]* {
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 )
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 | (?P<Method>
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<MethodIndent> [ \t]* )
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 rpc [ \t]+
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 (?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
62 [ \t]*
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 \(
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 (?P<MethodSignature> [^)]+? )
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 [ \t]+
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 returns
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 \(
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 (?P<MethodReturn> [^)]+? )
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 [ \t]*
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
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 | (?P<Begin>
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 [ \t]* {
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 )
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 | (?P<End>
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 [ \t]* } [ \t]* ;?
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 )""",
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
82 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
83 ).search
5977
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 # function to replace comments
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 _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
87 # function to normalize whitespace
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 _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
89
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
90 _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
91
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 class VisibilityMixin(ClbrBaseClasses.ClbrVisibilityMixinBase):
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 """
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 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
96 """
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
97
5977
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 """
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
109
5977
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110 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
111 """
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
112 Constructor
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
113
5977
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114 @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
115 @type str
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116 @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
117 @type str
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
118 @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
119 @type str
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120 @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
121 @type int
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122 """
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123 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
124 VisibilityMixin.__init__(self)
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
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
127 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
128 """
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
129 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
130 """
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
131
5977
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
132 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
133 """
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
134 Constructor
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
135
5977
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
136 @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
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 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
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 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
141 @type str
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
142 @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
143 @type int
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
144 """
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
145 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
146 VisibilityMixin.__init__(self)
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
147
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 Service(ClbrBaseClasses.Class, VisibilityMixin):
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 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
152 """
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
153
5977
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
154 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
155 """
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
156 Constructor
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
157
5977
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
158 @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
159 @type str
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
160 @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
161 @type str
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
162 @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
163 @type str
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
164 @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
165 @type int
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
166 """
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
167 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
168 VisibilityMixin.__init__(self)
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
169
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 ServiceMethod(ClbrBaseClasses.Function, VisibilityMixin):
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 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
174 """
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
175
5977
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
176 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
177 """
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
178 Constructor
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
179
5977
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
180 @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
181 @type str
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
182 @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
183 @type str
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
184 @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
185 @type int
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
186 @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
187 @type str
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
188 @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
189 @type str
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
190 """
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
191 ClbrBaseClasses.Function.__init__(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
192 self,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
193 None,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
194 name,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
195 file,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
196 lineno,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
197 signature,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
198 annotation="-> {0}".format(returns),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
199 )
5977
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
200 VisibilityMixin.__init__(self)
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
201
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 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
204 """
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
205 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
206 services and rpc methods.
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 @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
209 @type str
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
210 @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
211 @type list of str
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
212 @return the resulting dictionary
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
213 @rtype dict
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
214 """
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
215 global _modules
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
216
5977
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
217 if module in _modules:
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
218 # 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
219 return _modules[module]
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
220
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
221 # 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
222 f = None
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
223 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
224 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
225 if f:
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
226 f.close()
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
227 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
228 # 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
229 _modules[module] = {}
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
230 return {}
5977
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
231
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
232 try:
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
233 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
234 except (UnicodeError, OSError):
5977
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
235 # 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
236 _modules[module] = {}
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
237 return {}
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
238
7690
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
239 _modules[module] = scan(src, file, module)
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
240 return _modules[module]
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
241
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 def scan(src, file, module):
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
244 """
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
245 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
246
7690
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
247 @param src source text to be scanned
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
248 @type str
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
249 @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
250 @type str
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
251 @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
252 @type str
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
253 @return dictionary containing the extracted data
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
254 @rtype dict
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
255 """
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
256
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
257 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
258 """
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 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
260
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
261 @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
262 @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
263 @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
264 @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
265 @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
266 @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
267 """
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 # 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
269 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
270 # 1. search for opening brace '{'
7706
0c6d32ec64f1 Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7699
diff changeset
271 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
272 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
273 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
274 # 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
275 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
276 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
277 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
278 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
279 # 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
280 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
281 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
282 # 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
283 return -1
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
284
7676
0f67b4562d98 ClassBrowsers: added code to treat source texts like Python (universal newline).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7628
diff changeset
285 # 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
286 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
287 srcLines = src.splitlines()
5977
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
288
7690
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
289 dictionary = {}
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
290
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
291 classstack = [] # stack of (class, indent) pairs
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
292 indent = 0
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
293
5977
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
294 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
295 i = 0
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
296 while True:
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
297 m = _getnext(src, i)
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
298 if not m:
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
299 break
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
300 start, i = m.span()
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
301
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
302 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
303 # 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
304 thisindent = indent
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
305 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
306 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
307 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
308 meth_sig = _commentsub("", meth_sig)
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
309 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
310 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
311 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
312 meth_return = _commentsub("", meth_return)
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
313 meth_return = _normalize(" ", meth_return)
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
314 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
315 last_lineno_pos = start
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
316 # 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
317 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
318 del classstack[-1]
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
319 if classstack:
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
320 # 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
321 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
322 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
323 # it's a method
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
324 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
325 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
326 # 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
327 else:
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
328 f = None
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
329 else:
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
330 # 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
331 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
332 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
333 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
334 f.setEndLine(endline)
5977
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
335 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
336
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
337 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
338 pass
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
339
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
340 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
341 # 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
342 thisindent = indent
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
343 indent += 1
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
344 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
345 last_lineno_pos = start
032a0586a349 protoclbr: fixed an issue caused by an unitialized variable.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7690
diff changeset
346 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
347 # 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
348 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
349 del classstack[-1]
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
350 # remember this message
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
351 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
352 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
353 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
354 if not classstack:
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
355 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
356 else:
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
357 msg = classstack[-1][0]
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
358 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
359 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
360
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
361 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
362 # 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
363 thisindent = indent
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
364 indent += 1
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
365 # 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
366 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
367 del classstack[-1]
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
368 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
369 last_lineno_pos = start
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
370 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
371 # remember this Enum
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
372 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
373 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
374 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
375 if not classstack:
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
376 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
377 else:
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
378 enum = classstack[-1][0]
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
379 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
380 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
381
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
382 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
383 # 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
384 thisindent = indent
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 # 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
387 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
388 del classstack[-1]
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
389 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
390 last_lineno_pos = start
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
391 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
392 # remember this Service
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
393 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
394 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
395 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
396 if not classstack:
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
397 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
398 else:
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
399 service = classstack[-1][0]
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
400 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
401 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
402
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
403 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
404 # 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
405 indent += 1
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
406
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
407 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
408 # 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
409 indent -= 1
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
410
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
411 return dictionary

eric ide

mercurial