Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
seleniumhq
GitHub Repository: seleniumhq/selenium
Path: blob/trunk/common/devtools/convert_protocol_to_json.py
4500 views
1
#!/usr/bin/env python
2
# Copyright 2017 The Chromium Authors. All rights reserved.
3
# Use of this source code is governed by a BSD-style license that can be
4
# found in the LICENSE file.
5
6
import argparse
7
import json
8
import os.path
9
import sys
10
11
import pdl
12
13
14
def main(argv):
15
parser = argparse.ArgumentParser(description=("Converts from .pdl to .json by invoking the pdl Python module."))
16
parser.add_argument(
17
"--map_binary_to_string",
18
type=bool,
19
help=(
20
"If set, binary in the .pdl is mapped to a "
21
"string in .json. Client code will have to "
22
"base64 decode the string to get the payload."
23
),
24
)
25
parser.add_argument("pdl_file", help="The .pdl input file to parse.")
26
parser.add_argument("json_file", help="The .json output file write.")
27
args = parser.parse_args(argv)
28
file_name = os.path.normpath(args.pdl_file)
29
with open(file_name) as input_file:
30
pdl_string = input_file.read()
31
32
protocol = pdl.loads(pdl_string, file_name, args.map_binary_to_string)
33
34
with open(os.path.normpath(args.json_file), "w") as output_file:
35
json.dump(protocol, output_file, indent=4, separators=(",", ": "))
36
37
38
if __name__ == "__main__":
39
sys.exit(main(sys.argv[1:]))
40
41