@@ -952,6 +952,38 @@ def generate_docs(docs_path, domains):
952952 f .write (domain .generate_sphinx ())
953953
954954
955+ def patchCDP (domains ):
956+ '''Patch up CDP errors. It's easier to patch that here than it is to modify the generator code.'''
957+
958+ # 1. DOM includes an erroneous $ref that refers to itself.
959+ # 2. Page includes an event with an extraneous backtick in the description.
960+ # 3. Network.requestWillBeSent.redirectHasExtraInfo is not marked as optional but it is not present in all events
961+ # 4. Network.responseReceived.hasExtraInfo is not marked as optional but it is not present in all events
962+ for domain in domains :
963+ if domain .domain == 'DOM' :
964+ for cmd in domain .commands :
965+ if cmd .name == 'resolveNode' :
966+ # Patch 1
967+ cmd .parameters [1 ].ref = 'BackendNodeId'
968+ elif domain .domain == 'Page' :
969+ for event in domain .events :
970+ if event .name == 'screencastVisibilityChanged' :
971+ # Patch 2
972+ event .description = event .description .replace ('`' , '' )
973+ elif domain .domain == 'Network' :
974+ for event in domain .events :
975+ if event .name == 'requestWillBeSent' :
976+ for param in event .parameters :
977+ if param .name == 'redirectHasExtraInfo' :
978+ # Patch 3
979+ param .optional = True
980+ if event .name == 'responseReceived' :
981+ for param in event .parameters :
982+ if param .name == 'hasExtraInfo' :
983+ # Patch 4
984+ param .optional = True
985+
986+
955987def main ():
956988 ''' Main entry point. '''
957989 here = Path (__file__ ).parent .resolve ()
@@ -974,21 +1006,7 @@ def main():
9741006 domains .extend (parse (json_path , output_path ))
9751007 domains .sort (key = operator .attrgetter ('domain' ))
9761008
977- # Patch up CDP errors. It's easier to patch that here than it is to modify
978- # the generator code.
979- # 1. DOM includes an erroneous $ref that refers to itself.
980- # 2. Page includes an event with an extraneous backtick in the description.
981- for domain in domains :
982- if domain .domain == 'DOM' :
983- for cmd in domain .commands :
984- if cmd .name == 'resolveNode' :
985- # Patch 1
986- cmd .parameters [1 ].ref = 'BackendNodeId'
987- elif domain .domain == 'Page' :
988- for event in domain .events :
989- if event .name == 'screencastVisibilityChanged' :
990- # Patch 2
991- event .description = event .description .replace ('`' , '' )
1009+ patchCDP (domains )
9921010
9931011 for domain in domains :
9941012 logger .info ('Generating module: %s → %s.py' , domain .domain ,
0 commit comments