comparison libervia/backend/bridge/bridge_constructor/base_constructor.py @ 4270:0d7bb4df2343

Reformatted code base using black.
author Goffi <goffi@goffi.org>
date Wed, 19 Jun 2024 18:44:57 +0200
parents 4b842c1fb686
children
comparison
equal deleted inserted replaced
4269:64a85ce8be70 4270:0d7bb4df2343
75 return function 75 return function
76 76
77 def get_default(self, name): 77 def get_default(self, name):
78 """Return default values of a function in a dict 78 """Return default values of a function in a dict
79 @param name: Name of the function to get 79 @param name: Name of the function to get
80 @return: dict, each key is the integer param number (no key if no default value)""" 80 @return: dict, each key is the integer param number (no key if no default value)
81 """
81 default_dict = {} 82 default_dict = {}
82 def_re = re.compile(r"param_(\d+)_default") 83 def_re = re.compile(r"param_(\d+)_default")
83 84
84 for option in self.bridge_template.options(name): 85 for option in self.bridge_template.options(name):
85 match = def_re.match(option) 86 match = def_re.match(option)
107 return flags 108 return flags
108 109
109 def get_arguments_doc(self, name): 110 def get_arguments_doc(self, name):
110 """Return documentation of arguments 111 """Return documentation of arguments
111 @param name: Name of the function to get 112 @param name: Name of the function to get
112 @return: dict, each key is the integer param number (no key if no argument doc), value is a tuple (name, doc)""" 113 @return: dict, each key is the integer param number (no key if no argument doc), value is a tuple (name, doc)
114 """
113 doc_dict = {} 115 doc_dict = {}
114 option_re = re.compile(r"doc_param_(\d+)") 116 option_re = re.compile(r"doc_param_(\d+)")
115 value_re = re.compile(r"^(\w+): (.*)$", re.MULTILINE | re.DOTALL) 117 value_re = re.compile(r"^(\w+): (.*)$", re.MULTILINE | re.DOTALL)
116 for option in self.bridge_template.options(name): 118 for option in self.bridge_template.options(name):
117 if option == "doc_return": 119 if option == "doc_return":
143 """Generator which return individual arguments signatures from a global signature""" 145 """Generator which return individual arguments signatures from a global signature"""
144 start = 0 146 start = 0
145 i = 0 147 i = 0
146 148
147 while i < len(signature): 149 while i < len(signature):
148 if signature[i] not in ["b", "y", "n", "i", "x", "q", "u", "t", "d", "s", 150 if signature[i] not in [
149 "a"]: 151 "b",
152 "y",
153 "n",
154 "i",
155 "x",
156 "q",
157 "u",
158 "t",
159 "d",
160 "s",
161 "a",
162 ]:
150 raise ParseError("Unmanaged attribute type [%c]" % signature[i]) 163 raise ParseError("Unmanaged attribute type [%c]" % signature[i])
151 164
152 if signature[i] == "a": 165 if signature[i] == "a":
153 i += 1 166 i += 1
154 if ( 167 if (
291 self, "{}_completion_{}".format(side, function["type"]) 304 self, "{}_completion_{}".format(side, function["type"])
292 ) 305 )
293 extend_method(completion, function, default, arg_doc, async_) 306 extend_method(completion, function, default, arg_doc, async_)
294 307
295 for part, fmt in FORMATS.items(): 308 for part, fmt in FORMATS.items():
296 if (part.startswith(function["type"]) 309 if part.startswith(function["type"]) or part.startswith(
297 or part.startswith(f"async_{function['type']}")): 310 f"async_{function['type']}"
311 ):
298 parts[part.upper()].append(fmt.format(**completion)) 312 parts[part.upper()].append(fmt.format(**completion))
299 313
300 # at this point, signals_part, methods_part and direct_calls should be filled, 314 # at this point, signals_part, methods_part and direct_calls should be filled,
301 # we just have to place them in the right part of the template 315 # we just have to place them in the right part of the template
302 bridge = [] 316 bridge = []
348 try: 362 try:
349 if not os.path.exists(self.args.dest_dir): 363 if not os.path.exists(self.args.dest_dir):
350 os.mkdir(self.args.dest_dir) 364 os.mkdir(self.args.dest_dir)
351 full_path = os.path.join(self.args.dest_dir, filename) 365 full_path = os.path.join(self.args.dest_dir, filename)
352 if os.path.exists(full_path) and not self.args.force: 366 if os.path.exists(full_path) and not self.args.force:
353 print(( 367 print(
354 "The destination file [%s] already exists ! Use --force to overwrite it" 368 (
355 % full_path 369 "The destination file [%s] already exists ! Use --force to overwrite it"
356 )) 370 % full_path
371 )
372 )
357 try: 373 try:
358 with open(full_path, "w") as dest_file: 374 with open(full_path, "w") as dest_file:
359 dest_file.write("\n".join(file_buf)) 375 dest_file.write("\n".join(file_buf))
360 except IOError: 376 except IOError:
361 print(("Can't open destination file [%s]" % full_path)) 377 print(("Can't open destination file [%s]" % full_path))