Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
seleniumhq
GitHub Repository: seleniumhq/selenium
Path: blob/trunk/common/devtools/convert_protocol_to_json.py
2884 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(
16
description=("Converts from .pdl to .json by invoking the pdl Python module.")
17
)
18
parser.add_argument(
19
"--map_binary_to_string",
20
type=bool,
21
help=(
22
"If set, binary in the .pdl is mapped to a "
23
"string in .json. Client code will have to "
24
"base64 decode the string to get the payload."
25
),
26
)
27
parser.add_argument("pdl_file", help="The .pdl input file to parse.")
28
parser.add_argument("json_file", help="The .json output file write.")
29
args = parser.parse_args(argv)
30
file_name = os.path.normpath(args.pdl_file)
31
input_file = open(file_name, "r")
32
pdl_string = input_file.read()
33
protocol = pdl.loads(pdl_string, file_name, args.map_binary_to_string)
34
input_file.close()
35
36
output_file = open(os.path.normpath(args.json_file), "w")
37
json.dump(protocol, output_file, indent=4, separators=(",", ": "))
38
output_file.close()
39
40
41
if __name__ == "__main__":
42
sys.exit(main(sys.argv[1:]))
43
44