# Path: libtaxii/scripts/poll_client.py
# class PollClient11Script(TaxiiScript):
#     parser_description = ('The TAXII 1.1 Poll Client sends a Poll Request to a TAXII Poll Service then, depending on'
#                           ' the provided command line arguments, writes the Content Blocks in the response to disk.'
#                           ' Various options for the Poll Request can be set on the command line.')
#     path = '/taxii-data'
# 
#     def get_arg_parser(self, *args, **kwargs):
#         parser = super(PollClient11Script, self).get_arg_parser(*args, **kwargs)
#         parser.add_argument("--collection",
#                             dest="collection",
#                             default="default",
#                             help="Data Collection to poll. Defaults to 'default'.")
#         parser.add_argument("--begin-timestamp",
#                             dest="begin_ts",
#                             default=None,
#                             help="The begin timestamp (format: YYYY-MM-DDTHH:MM:SS.ssssss+/-hh:mm) "
#                                  "for the poll request. Defaults to None.")
#         parser.add_argument("--end-timestamp",
#                             dest="end_ts",
#                             default=None,
#                             help="The end timestamp (format: YYYY-MM-DDTHH:MM:SS.ssssss+/-hh:mm) "
#                                  "for the poll request. Defaults to None.")
#         parser.add_argument("--subscription-id",
#                             dest="subscription_id",
#                             default=None,
#                             help="The Subscription ID for the poll request. Defaults to None.")
#         add_poll_response_args(parser)
#         return parser
# 
#     def create_request_message(self, args):
#         try:
#             if args.begin_ts:
#                 begin_ts = dateutil.parser.parse(args.begin_ts)
#                 if not begin_ts.tzinfo:
#                     raise ValueError
#             else:
#                 begin_ts = None
# 
#             if args.end_ts:
#                 end_ts = dateutil.parser.parse(args.end_ts)
#                 if not end_ts.tzinfo:
#                     raise ValueError
#             else:
#                 end_ts = None
#         except ValueError:
#             print("Unable to parse timestamp value. Timestamp should include both date and time "
#                   "information along with a timezone or UTC offset (e.g., YYYY-MM-DDTHH:MM:SS.ssssss+/-hh:mm). "
#                   "Aborting poll.")
#             sys.exit()
# 
#         create_kwargs = {'message_id': tm11.generate_message_id(),
#                          'collection_name': args.collection,
#                          'exclusive_begin_timestamp_label': begin_ts,
#                          'inclusive_end_timestamp_label': end_ts}
# 
#         if args.subscription_id:
#             create_kwargs['subscription_id'] = args.subscription_id
#         else:
#             create_kwargs['poll_parameters'] = tm11.PollRequest.PollParameters()
#         poll_req = tm11.PollRequest(**create_kwargs)
#         return poll_req
# 
#     def handle_response(self, response, args):
#         super(PollClient11Script, self).handle_response(response, args)
# 
#         if response.message_type == MSG_POLL_RESPONSE:
#             if response.more:
#                 print("This response has More=True, to request additional parts, use the following command:")
#                 print("  fulfillment_client --collection %s --result-id %s --result-part-number %s\r\n" %
#                       (response.collection_name, response.result_id, response.result_part_number + 1))
# 
#             self.write_cbs_from_poll_response_11(response, dest_dir=args.dest_dir, write_type_=args.write_type)


import libtaxii.taxii_default_query as tdq
from libtaxii.constants import *
from .poll_client import PollClient11Script
            param_value = getattr(args, parameter)  # Will either be a value or None

            if param_obj and not param_value:
                raise ValueError('The parameter "%s" is needed and was not specified. Specify using --%s <value>' %
                                 (parameter, parameter.replace('_', '-')))
            if param_value and not param_obj:
                raise ValueError('The parameter %s was specified and is not needed' % parameter)

            if param_obj:
                param_obj.verify(param_value)
                params[parameter] = param_value

        test = tdq.Test(capability_id=capability_module.capability_module_id,
                        relationship=relationship.name,
                        parameters=params)

        criterion = tdq.Criterion(target=args.target, test=test)
        criteria = tdq.Criteria(operator=OP_AND, criterion=[criterion])
        q = tdq.DefaultQuery(args.tev, criteria)
        msg.poll_parameters.query = q

        return msg



def main():
    script = QueryClient11Script()
    script()

if __name__ == "__main__":

# Path: libtaxii/scripts/poll_client.py
# class PollClient11Script(TaxiiScript):
#     parser_description = ('The TAXII 1.1 Poll Client sends a Poll Request to a TAXII Poll Service then, depending on'
#                           ' the provided command line arguments, writes the Content Blocks in the response to disk.'
#                           ' Various options for the Poll Request can be set on the command line.')
#     path = '/taxii-data'
# 
#     def get_arg_parser(self, *args, **kwargs):
#         parser = super(PollClient11Script, self).get_arg_parser(*args, **kwargs)
#         parser.add_argument("--collection",
#                             dest="collection",
#                             default="default",
#                             help="Data Collection to poll. Defaults to 'default'.")
#         parser.add_argument("--begin-timestamp",
#                             dest="begin_ts",
#                             default=None,
#                             help="The begin timestamp (format: YYYY-MM-DDTHH:MM:SS.ssssss+/-hh:mm) "
#                                  "for the poll request. Defaults to None.")
#         parser.add_argument("--end-timestamp",
#                             dest="end_ts",
#                             default=None,
#                             help="The end timestamp (format: YYYY-MM-DDTHH:MM:SS.ssssss+/-hh:mm) "
#                                  "for the poll request. Defaults to None.")
#         parser.add_argument("--subscription-id",
#                             dest="subscription_id",
#                             default=None,
#                             help="The Subscription ID for the poll request. Defaults to None.")
#         add_poll_response_args(parser)
#         return parser
# 
#     def create_request_message(self, args):
#         try:
#             if args.begin_ts:
#                 begin_ts = dateutil.parser.parse(args.begin_ts)
#                 if not begin_ts.tzinfo:
#                     raise ValueError
#             else:
#                 begin_ts = None
# 
#             if args.end_ts:
#                 end_ts = dateutil.parser.parse(args.end_ts)
#                 if not end_ts.tzinfo:
#                     raise ValueError
#             else:
#                 end_ts = None
#         except ValueError:
#             print("Unable to parse timestamp value. Timestamp should include both date and time "
#                   "information along with a timezone or UTC offset (e.g., YYYY-MM-DDTHH:MM:SS.ssssss+/-hh:mm). "
#                   "Aborting poll.")
#             sys.exit()
# 
#         create_kwargs = {'message_id': tm11.generate_message_id(),
#                          'collection_name': args.collection,
#                          'exclusive_begin_timestamp_label': begin_ts,
#                          'inclusive_end_timestamp_label': end_ts}
# 
#         if args.subscription_id:
#             create_kwargs['subscription_id'] = args.subscription_id
#         else:
#             create_kwargs['poll_parameters'] = tm11.PollRequest.PollParameters()
#         poll_req = tm11.PollRequest(**create_kwargs)
#         return poll_req
# 
#     def handle_response(self, response, args):
#         super(PollClient11Script, self).handle_response(response, args)
# 
#         if response.message_type == MSG_POLL_RESPONSE:
#             if response.more:
#                 print("This response has More=True, to request additional parts, use the following command:")
#                 print("  fulfillment_client --collection %s --result-id %s --result-part-number %s\r\n" %
#                       (response.collection_name, response.result_id, response.result_part_number + 1))
# 
#             self.write_cbs_from_poll_response_11(response, dest_dir=args.dest_dir, write_type_=args.write_type)


# Path: libtaxii/scripts/query_client.py
import libtaxii.taxii_default_query as tdq
from libtaxii.constants import *
from .poll_client import PollClient11Script

            param_value = getattr(args, parameter)  # Will either be a value or None

            if param_obj and not param_value:
                raise ValueError('The parameter "%s" is needed and was not specified. Specify using --%s <value>' %
                                 (parameter, parameter.replace('_', '-')))
            if param_value and not param_obj:
                raise ValueError('The parameter %s was specified and is not needed' % parameter)

            if param_obj:
                param_obj.verify(param_value)
                params[parameter] = param_value

        test = tdq.Test(capability_id=capability_module.capability_module_id,
                        relationship=relationship.name,
                        parameters=params)

        criterion = tdq.Criterion(target=args.target, test=test)
        criteria = tdq.Criteria(operator=OP_AND, criterion=[criterion])
        q = tdq.DefaultQuery(args.tev, criteria)
        msg.poll_parameters.query = q

        return msg



def main():
    script = QueryClient11Script()
    script()

if __name__ == "__main__":

    main()