Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ExeBy/exe_root.../opt/saltstac.../salt/bin
File: jp.py
#!/bin/sh
[0] Fix | Delete
"exec" "$$(dirname $$(readlink -f $$0))/python3" "$$0" "$$@"
[1] Fix | Delete
[2] Fix | Delete
import sys
[3] Fix | Delete
import json
[4] Fix | Delete
import argparse
[5] Fix | Delete
from pprint import pformat
[6] Fix | Delete
[7] Fix | Delete
import jmespath
[8] Fix | Delete
from jmespath import exceptions
[9] Fix | Delete
[10] Fix | Delete
[11] Fix | Delete
def main():
[12] Fix | Delete
parser = argparse.ArgumentParser()
[13] Fix | Delete
parser.add_argument('expression')
[14] Fix | Delete
parser.add_argument('-f', '--filename',
[15] Fix | Delete
help=('The filename containing the input data. '
[16] Fix | Delete
'If a filename is not given then data is '
[17] Fix | Delete
'read from stdin.'))
[18] Fix | Delete
parser.add_argument('--ast', action='store_true',
[19] Fix | Delete
help=('Pretty print the AST, do not search the data.'))
[20] Fix | Delete
args = parser.parse_args()
[21] Fix | Delete
expression = args.expression
[22] Fix | Delete
if args.ast:
[23] Fix | Delete
# Only print the AST
[24] Fix | Delete
expression = jmespath.compile(args.expression)
[25] Fix | Delete
sys.stdout.write(pformat(expression.parsed))
[26] Fix | Delete
sys.stdout.write('\n')
[27] Fix | Delete
return 0
[28] Fix | Delete
if args.filename:
[29] Fix | Delete
with open(args.filename, 'r') as f:
[30] Fix | Delete
data = json.load(f)
[31] Fix | Delete
else:
[32] Fix | Delete
data = sys.stdin.read()
[33] Fix | Delete
data = json.loads(data)
[34] Fix | Delete
try:
[35] Fix | Delete
sys.stdout.write(json.dumps(
[36] Fix | Delete
jmespath.search(expression, data), indent=4, ensure_ascii=False))
[37] Fix | Delete
sys.stdout.write('\n')
[38] Fix | Delete
except exceptions.ArityError as e:
[39] Fix | Delete
sys.stderr.write("invalid-arity: %s\n" % e)
[40] Fix | Delete
return 1
[41] Fix | Delete
except exceptions.JMESPathTypeError as e:
[42] Fix | Delete
sys.stderr.write("invalid-type: %s\n" % e)
[43] Fix | Delete
return 1
[44] Fix | Delete
except exceptions.UnknownFunctionError as e:
[45] Fix | Delete
sys.stderr.write("unknown-function: %s\n" % e)
[46] Fix | Delete
return 1
[47] Fix | Delete
except exceptions.ParseError as e:
[48] Fix | Delete
sys.stderr.write("syntax-error: %s\n" % e)
[49] Fix | Delete
return 1
[50] Fix | Delete
[51] Fix | Delete
[52] Fix | Delete
if __name__ == '__main__':
[53] Fix | Delete
sys.exit(main())
[54] Fix | Delete
[55] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function