def handle()

in api-reference-examples/python/te-tag-query/TETagQuery.py [0:0]


    def handle(self, args):
        options = self.getDefaultOptions()
        subcommandHandlerFactory = SubcommandHandlerFactory()

        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 == "-l" or option == "--list-verbs":
                SubcommandHandlerFactory.listVerbs()
                sys.exit(0)

            elif option == "-v" or option == "--verbose":
                options["verbose"] = True
            elif option == "-q" or option == "--quiet":
                options["verbose"] = False
            elif option == "-s" or option == "--show-urls":
                options["showURLs"] = True
            elif option == "-a" or option == "--app-token-env-name":
                if len(args) < 1:
                    self.usage(1)
                options["accessTokenEnvName"] = args[0]
                args = args[1:]
            elif option == "-b" or option == "--base-te-url":
                if len(args) < 1:
                    self.usage(1)
                options["baseTEURL"] = args[0]
                args = args[1:]
            else:
                eprint("%s: unrecognized  option %s" % (self.progName, option))
                sys.exit(1)

        if len(args) < 1:
            self.usage(1)

        verbName = args[0]
        args = args[1:]

        # Endpoint setup common to all verbs
        # ThreatExchange::TENet::setAppTokenFromEnvName(options['accessTokenEnvName'])
        baseTEURL = options["baseTEURL"]
        if baseTEURL != None:
            TE.Net.setTEBaseURL(baseTEURL)
        if options["accessTokenEnvName"] != None:
            TE.Net.setAppTokenFromEnvName(options["accessTokenEnvName"])

        subcommandHandler = subcommandHandlerFactory.create(self.progName, verbName)
        if subcommandHandler is None:
            eprint("%s: unrecognized verb %s" % (self.progName, verbName))
            sys.exit(1)
        subcommandHandler.handle(args, options)