diff --git a/ChangeLog.txt b/ChangeLog.txt index f5533d6..c0eec27 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,5 +1,8 @@ ** Release Notes +1.5.62 + * protection against non-ASCII args + 1.5.61 * fixed changes in 1.5.60 diff --git a/pandaclient/Client.py b/pandaclient/Client.py index 5e82f75..7ba8cf7 100755 --- a/pandaclient/Client.py +++ b/pandaclient/Client.py @@ -1997,7 +1997,8 @@ def get_events_status(ids, verbose=False): def update_events(events, verbose=False): """Update events args: - events: a list of {'eventRangeID': ..., 'eventStatus': ..., 'errorCode': } + events: a list of {'eventRangeID': ..., 'eventStatus': ..., + 'errorCode': , 'errorDiag': } verbose: True to see verbose message returns: status code @@ -2012,7 +2013,8 @@ def update_events(events, verbose=False): curl.verbose = verbose # execute url = baseURLSSL + '/updateEventRanges' - data = {'eventRanges': json.dumps(events)} + data = {'eventRanges': json.dumps(events), + 'version': 2} status, output = curl.post(url, data, is_json=True) if status != 0: return EC_Failed, output diff --git a/pandaclient/Group_argparse.py b/pandaclient/Group_argparse.py index 35e6c98..76cc398 100644 --- a/pandaclient/Group_argparse.py +++ b/pandaclient/Group_argparse.py @@ -1,6 +1,22 @@ import argparse import sys from collections import OrderedDict +try: + unicode +except Exception: + unicode = str + + +# check string args if they can be encoded with utf-8 +class ActionWithUnicodeCheck(argparse.Action): + def __call__(self, parser, namespace, values, option_string=None): + if isinstance(values, (unicode, str)): + try: + values.encode() + except Exception: + parser.exit(1, message="ERROR: argument --{0} cannot be encoded with utf-8: '{1}'\n".format(self.dest, values)) + setattr(namespace, self.dest, values) + class GroupArgParser(argparse.ArgumentParser): def __init__(self, usage, conflict_handler): @@ -86,3 +102,10 @@ def __call__(self, parser, namespace, values, option_string=None): else: raise Exception("!!!ERROR!!! Unknown group name=%s" % values) sys.exit(0) + + +# factory method +def get_parser(usage, conflict_handler): + p = GroupArgParser(usage, conflict_handler) + p.register('action', 'store', ActionWithUnicodeCheck) + return p diff --git a/pandaclient/PandaToolsPkgInfo.py b/pandaclient/PandaToolsPkgInfo.py index c311bb2..94832fc 100644 --- a/pandaclient/PandaToolsPkgInfo.py +++ b/pandaclient/PandaToolsPkgInfo.py @@ -1 +1 @@ -release_version = "1.5.61" +release_version = "1.5.62" diff --git a/pandaclient/PathenaScript.py b/pandaclient/PathenaScript.py index d58fb9f..70d70df 100644 --- a/pandaclient/PathenaScript.py +++ b/pandaclient/PathenaScript.py @@ -5,7 +5,7 @@ import shutil import atexit import argparse -from pandaclient.Group_argparse import GroupArgParser +from pandaclient.Group_argparse import get_parser import random import pickle import json @@ -114,7 +114,7 @@ "-l" ] -optP = GroupArgParser(usage=usage, conflict_handler="resolve") +optP = get_parser(usage=usage, conflict_handler="resolve") optP.set_examples(examples) # define option groups diff --git a/pandaclient/PchainScript.py b/pandaclient/PchainScript.py index 7921d47..05b99eb 100644 --- a/pandaclient/PchainScript.py +++ b/pandaclient/PchainScript.py @@ -5,7 +5,7 @@ import shlex import atexit -from pandaclient.Group_argparse import GroupArgParser +from pandaclient.Group_argparse import get_parser from pandaclient import PLogger from pandaclient import PandaToolsPkgInfo from pandaclient import MiscUtils @@ -33,7 +33,7 @@ def main(): usage = """pchain [options] """ - optP = GroupArgParser(usage=usage, conflict_handler="resolve") + optP = get_parser(usage=usage, conflict_handler="resolve") group_output = optP.add_group('output', 'output dataset/files') group_config = optP.add_group('config', 'workflow configuration') diff --git a/pandaclient/PhpoScript.py b/pandaclient/PhpoScript.py index 6371726..6d63d56 100644 --- a/pandaclient/PhpoScript.py +++ b/pandaclient/PhpoScript.py @@ -5,7 +5,7 @@ import copy import atexit -from pandaclient.Group_argparse import GroupArgParser +from pandaclient.Group_argparse import get_parser from pandaclient import PLogger from pandaclient import PandaToolsPkgInfo from pandaclient import MiscUtils @@ -33,7 +33,7 @@ def main(get_taskparams=False, ext_args=None, dry_mode=False): usage = """phpo [options] """ - optP = GroupArgParser(usage=usage, conflict_handler="resolve") + optP = get_parser(usage=usage, conflict_handler="resolve") group_input = optP.add_group('input', 'input dataset(s)/files/format') group_output = optP.add_group('output', 'output dataset/files') diff --git a/pandaclient/PrunScript.py b/pandaclient/PrunScript.py index 575d0fd..cfba09d 100644 --- a/pandaclient/PrunScript.py +++ b/pandaclient/PrunScript.py @@ -6,7 +6,7 @@ import argparse import time -from pandaclient.Group_argparse import GroupArgParser +from pandaclient.Group_argparse import get_parser try: from urllib import quote except ImportError: @@ -83,7 +83,7 @@ def main(get_taskparams=False, ext_args=None, dry_mode=False): "--useSiteGroup" ] - optP = GroupArgParser(usage=usage, conflict_handler="resolve") + optP = get_parser(usage=usage, conflict_handler="resolve") optP.set_examples(examples) # command-line parameters