in api-reference-examples/python/te-tag-query/TETagQuery.py [0:0]
def handle(self, args, options):
options["dryRun"] = False
options["descriptorIDsFromStdin"] = 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 == "-N":
options["descriptorIDsFromStdin"] = True
elif option == "-n":
if len(args) < 1:
self.usage(1)
postParams[names["descriptor_id"]] = args[0]
args = args[1:]
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["descriptorIDsFromStdin"]:
if postParams.get(names["descriptor_id"], None) != None:
eprint(
"%s %s: only one of -N and -n 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["descriptor_id"]] = line.rstrip()
self.copySingle(
postParams,
options["verbose"],
options["showURLs"],
options["dryRun"],
)
else:
if postParams.get(names["descriptor_id"], None) == None:
eprint(
"%s %s: only one of -N and -n must be supplied."
% (self.progName, self.verbName)
)
sys.exit(1)
self.copySingle(
postParams, options["verbose"], options["showURLs"], options["dryRun"]
)