Skip to content

Commit 3a398bd

Browse files
author
lmc
committed
feature_20_21: Allow reading XML from stdin, provide raw mode ouput as
json
1 parent b82bcba commit 3a398bd

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ authors = [
1616

1717
description = "Generate xpath expressions from XML document."
1818
readme = "README.md"
19-
license = {text = "GPL-3.0"}
19+
license = "GPL-3.0"
2020
keywords = ["xpath", "xml"]
2121
classifiers = [
2222
"Development Status :: 5 - Production/Stable",

src/xml2xpath/xml2xpath.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,14 @@ def parse_mixed_ns(tree: etree._ElementTree,
220220

221221

222222
def get_json_response(xmap, nsmap, mode):
223+
'''
224+
Return a json string as
225+
{"xpath": { ... }.
226+
"namespaces": { ... }}
227+
:param xmap:
228+
:param nsmap:
229+
:param mode:
230+
'''
223231
indent = None
224232
raw_json = {}
225233
raw_json['xpath'] = xmap
@@ -361,6 +369,10 @@ def parse(file: str, *,
361369
raise(e)
362370

363371
def main():
372+
if len(sys.argv) == 1:
373+
print(f"ERROR: No arguments passed.\nRun with -h for help.", file=sys.stderr)
374+
sys.exit(1)
375+
364376
if sys.argv[1] in ["-h", "--help"]:
365377
usage()
366378
sys.exit()
@@ -374,7 +386,7 @@ def main():
374386
no_banners = False
375387
warns = None
376388

377-
if not path.isfile(file) and file != '-':
389+
if file != '-' and not path.isfile(file):
378390
print(f"[Errno {errno.ENOENT}] {strerror(errno.ENOENT)}", file=sys.stderr)
379391
sys.exit(errno.ENOENT)
380392

0 commit comments

Comments
 (0)