in api-reference-examples/python/te-tag-query/TETagQuery.py [0:0]
def handle(self, args, options):
options["dryRun"] = False
options["indicatorTextFromStdin"] = False
postParams = {}
# Local keystroke-saver for this enum
names = TE.Net.POST_PARAM_NAMES
while True:
if len(args) == 0:
break
if args[0][0] != "-":
break
option = args[0]
args = args[1:]
if option == "-h":
self.usage(0)
elif option == "--help":
self.usage(0)
elif option == "--dry-run":
options["dryRun"] = True
elif option == "-I":
options["indicatorTextFromStdin"] = True
elif option == "-i" or option == "--indicator":
if len(args) < 1:
self.usage(1)
postParams[names["indicator"]] = args[0]
args = args[1:]
elif option == "-t" or option == "--type":
if len(args) < 1:
self.usage(1)
postParams[names["type"]] = args[0]
args = args[1:]
elif option == "--tags":
if len(args) < 1:
self.usage(1)
postParams[names["tags"]] = args[0]
args = args[1:]
else:
handled, args = self.commonPosterOptionCheck(option, args, postParams)
if not handled:
eprint(
"%s %s: unrecognized option %s"
% (self.progName, self.verbName, option)
)
sys.exit(1)
if len(args) > 0:
eprint(
'%s %s: extraneous argument(s) "%s"'
% (self.progName, self.verbName, " ".join(args))
)
sys.exit(1)
if options["indicatorTextFromStdin"]:
if postParams.get(names["indicator"], None) != None:
eprint(
"%s %s: only one of -I and -i must be supplied."
% (self.progName, self.verbName)
)
sys.exit(1)
while True:
# Python line-reader returns the trailing newlines so
# we need to right-strip the lines
line = sys.stdin.readline()
if line == "":
break
postParams[names["indicator"]] = line.rstrip()
self.submitSingle(
postParams,
options["verbose"],
options["showURLs"],
options["dryRun"],
)
else:
if postParams.get(names["indicator"], None) == None:
eprint(
"%s %s: only one of -I and -i must be supplied."
% (self.progName, self.verbName)
)
sys.exit(1)
self.submitSingle(
postParams, options["verbose"], options["showURLs"], options["dryRun"]
)