MCPcopy Index your code
hub / github.com/nodejs/node / Protocol

Class Protocol

deps/inspector_protocol/code_generator.py:365–608  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

363
364
365class Protocol(object):
366
367 def __init__(self, config):
368 self.config = config
369 self.json_api = {"domains": []}
370 self.source_set = set()
371 self.imported_domains = []
372 self.exported_domains = []
373 self.generate_domains = self.read_protocol_file(config.protocol.path)
374
375 if config.protocol.options:
376 self.generate_domains = [rule.domain for rule in config.protocol.options]
377 self.exported_domains = [rule.domain for rule in config.protocol.options
378 if hasattr(rule, "exported")]
379
380 if config.imported:
381 self.imported_domains = self.read_protocol_file(config.imported.path)
382 if config.imported.options:
383 self.imported_domains = [rule.domain
384 for rule in config.imported.options]
385
386 self.patch_full_qualified_refs()
387 self.create_type_definitions()
388 self.generate_used_types()
389
390 def read_protocol_file(self, file_name):
391 input_file = open(file_name, "r")
392 parsed_json = pdl.loads(input_file.read(), file_name, False,
393 self.source_set)
394 input_file.close()
395 version = '%s.%s' % (parsed_json["version"]["major"],
396 parsed_json["version"]["minor"])
397 domains = []
398 for domain in parsed_json["domains"]:
399 domains.append(domain["domain"])
400 domain["version"] = version
401 self.json_api["domains"] += parsed_json["domains"]
402 return domains
403
404 def patch_full_qualified_refs(self):
405 def patch_full_qualified_refs_in_domain(json, domain_name):
406 if isinstance(json, list):
407 for item in json:
408 patch_full_qualified_refs_in_domain(item, domain_name)
409 if not isinstance(json, dict):
410 return
411 for key in json:
412 if key == "type" and json[key] == "string":
413 json[key] = domain_name + ".string"
414 if key != "$ref":
415 patch_full_qualified_refs_in_domain(json[key], domain_name)
416 continue
417 if json["$ref"].find(".") == -1:
418 json["$ref"] = domain_name + "." + json["$ref"]
419 return
420
421 for domain in self.json_api["domains"]:
422 patch_full_qualified_refs_in_domain(domain, domain["domain"])

Callers 1

mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…