diff --git a/python_helpers/_version.py b/python_helpers/_version.py index 4ec1aad..6af5ba6 100644 --- a/python_helpers/_version.py +++ b/python_helpers/_version.py @@ -7,5 +7,5 @@ from incremental import Version -__version__ = Version("python_helpers", 3, 0, 0) +__version__ = Version("python_helpers", 3, 0, 1) __all__ = ["__version__"] diff --git a/python_helpers/ph_constants.py b/python_helpers/ph_constants.py index 7265203..73f1ca4 100644 --- a/python_helpers/ph_constants.py +++ b/python_helpers/ph_constants.py @@ -6,6 +6,8 @@ class PhConstants: STR_CURLY_BRACE_START = '{' STR_CURLY_BRACE_END = '}' + OFFSET_ZERO = 0 + OFFSET_ONE = 1 OFFSET_NAME_FOR_OUTPUT_FILE = 0 OFFSET_NAME_FOR_ASN_FILE = 1 KEYWORD_VARIABLE_DECLARATION_IN = ['var_In', 'var_in_list', 'var_in'] @@ -224,3 +226,5 @@ class PhConstants: 'https://ipv6.icanhazip.com/', 'https://v6.ident.me/', ] + + STR_SELECT_OPTION = '-- Select --' diff --git a/python_helpers/ph_keys.py b/python_helpers/ph_keys.py index ada8f56..377ec2d 100644 --- a/python_helpers/ph_keys.py +++ b/python_helpers/ph_keys.py @@ -25,6 +25,8 @@ class PhKeys: ASN1_ELEMENT = 'asn1_element' ASN1_SCHEMA = 'asn1_schema' ASN1_OBJECT = 'asn1_object' + ASN1_OBJECT_ALTERNATE = 'asn1_object_alternate' + FETCH_ASN1_OBJECTS_LIST = 'fetch_asn1_objects_list' INFO = 'info' @@ -66,6 +68,8 @@ class PhKeys: RUN_TIME = 'run_time' # + PROCESS = 'process' + SAMPLE = 'sample' SAMPLE_1 = 'sample_1' SAMPLE_2 = 'sample_2' diff --git a/python_helpers/ph_util.py b/python_helpers/ph_util.py index 6023859..f79ef74 100644 --- a/python_helpers/ph_util.py +++ b/python_helpers/ph_util.py @@ -170,7 +170,7 @@ def check_if_iter(cls, the_iter): return is_iter, the_iter @classmethod - def print_iter(cls, the_iter, header=None, log=None, list_as_str=None, depth_level=-1): + def print_iter(cls, the_iter, header=None, log=None, list_as_str=None, depth_level=-1, verbose=False): """ This function takes a positional argument called 'the_iter', which is any Python list (of, possibly, nested lists). Each data item in the provided list is (recursively) printed to the screen on its own line. @@ -188,7 +188,11 @@ def print_iter(cls, the_iter, header=None, log=None, list_as_str=None, depth_lev if header: header = f'{header}:' if (list_as_str and isinstance(the_iter, list)) or not is_iter: - print_or_log(' '.join(filter(None, [header, str(the_iter)]))) + each_item = ' '.join(filter(None, [header, str(the_iter)])) + if verbose: + print_or_log(f'{each_item}; type: {type(each_item)}, length: {len(str(each_item))}') + else: + print_or_log(f'{each_item}') return if header: print_or_log(header) @@ -199,7 +203,10 @@ def print_iter(cls, the_iter, header=None, log=None, list_as_str=None, depth_lev if depth_level == -1 and cls.check_if_iter(value)[0]: cls.print_iter(the_iter=value, header=str(key), log=log, list_as_str=list_as_str) else: - print_or_log(f'{str(key)}: {value}') + if verbose: + print_or_log(f'{str(key)}: {value}; type: {type(value)}, length: {len(str(value))}') + else: + print_or_log(f'{str(key)}: {value}') return # Other iterable Items for each_item in the_iter: @@ -207,7 +214,10 @@ def print_iter(cls, the_iter, header=None, log=None, list_as_str=None, depth_lev if depth_level == -1 and cls.check_if_iter(each_item)[0]: cls.print_iter(the_iter=each_item, log=log) continue - print_or_log(each_item) + if verbose: + print_or_log(f'{each_item}; type: {type(each_item)}, length: {len(str(each_item))}') + else: + print_or_log(f'{each_item}') @classmethod def print_separator(cls, character='-', count=80, main_text='', log=None, get_only=False): @@ -1478,10 +1488,11 @@ def __get_obj_list(cls_to_explore, obj_name_filter, obj_name_needed, obj_value_t obj_list = [obj for obj in obj_list if str(obj).startswith(obj_name_filter)] if obj_name_needed is not True: obj_list = [getattr(cls_to_explore, obj) for obj in obj_list] - if clean_name: - obj_list = cls.clean_names(obj_list) - if sort: - obj_list.sort() + if obj_name_needed: + if clean_name: + obj_list = cls.clean_names(obj_list) + if sort: + obj_list.sort() if len(obj_list) > 0 and isinstance(obj_list[0], list): obj_list = obj_list[0] if isinstance(cls_to_explore, enum.EnumMeta): @@ -1489,8 +1500,9 @@ def __get_obj_list(cls_to_explore, obj_name_filter, obj_name_needed, obj_value_t if obj_value_to_find is None: return obj_list for obj in obj_list: - if obj.value == obj_value_to_find: - return obj.name + if isinstance(obj, cls_to_explore): + if obj.value == obj_value_to_find: + return obj.name return '' data = __get_obj_list(cls_to_explore, obj_name_filter, obj_name_needed, obj_value_to_find, clean_name, sort) @@ -1746,8 +1758,8 @@ def get_directory_path(cls, path): @classmethod def generalise_list(cls, data_list, append_na=True, sort=True): new_data_list = data_list.copy() if data_list is not None else [] - if append_na: - new_data_list.append('') if sort: new_data_list.sort() + if append_na: + new_data_list.insert(PhConstants.OFFSET_ZERO, PhConstants.STR_SELECT_OPTION) return new_data_list diff --git a/python_helpers/test/log/pycharm.log b/python_helpers/test/log/pycharm.log index 8be283a..0880256 100644 --- a/python_helpers/test/log/pycharm.log +++ b/python_helpers/test/log/pycharm.log @@ -9,12 +9,12 @@ User Name is Pratik Jaiswal -------------------------------------------------------------------------------- User Account is impra -------------------------------------------------------------------------------- -Time Stamp is Saturday, Dec 30 2023, 22:49:49:434596, IST (GMT+0530) +Time Stamp is Monday, Jan 01 2024, 17:25:00:214309, IST (GMT+0530) -------------------------------------------------------------------------------- IPV4 is 49.37.241.88 -IPV6 is 2405:201:d005:d029:643c:75f:329f:48d6 +IPV6 is 2405:201:d005:d029:500e:fdc1:9fe9:1756 -------------------------------------------------------------------------------- -pythonHelpers version is v3.0.0 +pythonHelpers version is v3.0.1 -------------------------------------------------------------------------------- Test Tool version is v1.0.1 -------------------------------------------------------------------------------- @@ -27,12 +27,12 @@ User Name is Pratik Jaiswal -------------------------------------------------------------------------------- User Account is impra -------------------------------------------------------------------------------- -Time Stamp is Saturday, Dec 30 2023, 22:49:50:168474, IST (GMT+0530) +Time Stamp is Monday, Jan 01 2024, 17:25:00:898217, IST (GMT+0530) -------------------------------------------------------------------------------- IPV4 is 49.37.241.88 -IPV6 is 2405:201:d005:d029:643c:75f:329f:48d6 +IPV6 is 2405:201:d005:d029:500e:fdc1:9fe9:1756 -------------------------------------------------------------------------------- -pythonHelpers version is v3.0.0 +pythonHelpers version is v3.0.1 -------------------------------------------------------------------------------- Python version is v3.9.13 (tags/v3.9.13:6de2ca5, May 17 2022, 16:36:42) [MSC v.1929 64 bit (AMD64)] ------------------------------------------------ no_additional_info=True ----------------------------------------------- @@ -49,12 +49,12 @@ User Name is Pratik Jaiswal -------------------------------------------------------------------------------- User Account is impra -------------------------------------------------------------------------------- -Time Stamp is Saturday, Dec 30 2023, 22:49:50:772589, IST (GMT+0530) +Time Stamp is Monday, Jan 01 2024, 17:25:01:476214, IST (GMT+0530) -------------------------------------------------------------------------------- IPV4 is 49.37.241.88 -IPV6 is 2405:201:d005:d029:643c:75f:329f:48d6 +IPV6 is 2405:201:d005:d029:500e:fdc1:9fe9:1756 -------------------------------------------------------------------------------- -pythonHelpers version is v3.0.0 +pythonHelpers version is v3.0.1 -------------------------------------------------------------------------------- Test Tool version is -------------------------------------------------------------------------------- @@ -68,12 +68,12 @@ User Name is Pratik Jaiswal -------------------------------------------------------------------------------- User Account is impra -------------------------------------------------------------------------------- -Time Stamp is Saturday, Dec 30 2023, 22:49:51:367860, IST (GMT+0530) +Time Stamp is Monday, Jan 01 2024, 17:25:02:045217, IST (GMT+0530) -------------------------------------------------------------------------------- IPV4 is 49.37.241.88 -IPV6 is 2405:201:d005:d029:643c:75f:329f:48d6 +IPV6 is 2405:201:d005:d029:500e:fdc1:9fe9:1756 -------------------------------------------------------------------------------- -pythonHelpers version is v3.0.0 +pythonHelpers version is v3.0.1 -------------------------------------------------------------------------------- Test Tool version is v1.0.1 -------------------------------------------------------------------------------- @@ -87,9 +87,9 @@ User Name is Pratik Jaiswal -------------------------------------------------------------------------------- User Account is impra -------------------------------------------------------------------------------- -Time Stamp is Saturday, Dec 30 2023, 22:49:51:948661, IST (GMT+0530) +Time Stamp is Monday, Jan 01 2024, 17:25:02:637176, IST (GMT+0530) -------------------------------------------------------------------------------- -pythonHelpers version is v3.0.0 +pythonHelpers version is v3.0.1 -------------------------------------------------------------------------------- Test Tool version is v1.0.1 -------------------------------------------------------------------------------- @@ -833,7 +833,7 @@ zoneinfo._common: zoneinfo: six: -six.moves: )> +six.moves: )> dateutil.tz._common: dateutil.tz._factories: ctypes.wintypes: @@ -1166,19 +1166,19 @@ email.feedparser: pkg_resources.extern: pkg_resources._vendor: -pkg_resources._vendor.appdirs: )> -pkg_resources.extern.appdirs: )> +pkg_resources._vendor.appdirs: )> +pkg_resources.extern.appdirs: )> pkg_resources._vendor.packaging.__about__: -pkg_resources._vendor.packaging: )> -pkg_resources.extern.packaging: )> +pkg_resources._vendor.packaging: )> +pkg_resources.extern.packaging: )> pkg_resources.extern.packaging._structures: pkg_resources.extern.packaging._typing: pkg_resources.extern.packaging.version: pkg_resources.extern.packaging._compat: pkg_resources.extern.packaging.utils: pkg_resources.extern.packaging.specifiers: -pkg_resources._vendor.pyparsing: )> -pkg_resources.extern.pyparsing: )> +pkg_resources._vendor.pyparsing: )> +pkg_resources.extern.pyparsing: )> pkg_resources.extern.packaging.markers: pkg_resources.extern.packaging.requirements: pkg_resources: @@ -1660,7 +1660,7 @@ zoneinfo._common: zoneinfo: six: -six.moves: )> +six.moves: )> dateutil.tz._common: dateutil.tz._factories: ctypes.wintypes: @@ -1993,19 +1993,19 @@ email.feedparser: pkg_resources.extern: pkg_resources._vendor: -pkg_resources._vendor.appdirs: )> -pkg_resources.extern.appdirs: )> +pkg_resources._vendor.appdirs: )> +pkg_resources.extern.appdirs: )> pkg_resources._vendor.packaging.__about__: -pkg_resources._vendor.packaging: )> -pkg_resources.extern.packaging: )> +pkg_resources._vendor.packaging: )> +pkg_resources.extern.packaging: )> pkg_resources.extern.packaging._structures: pkg_resources.extern.packaging._typing: pkg_resources.extern.packaging.version: pkg_resources.extern.packaging._compat: pkg_resources.extern.packaging.utils: pkg_resources.extern.packaging.specifiers: -pkg_resources._vendor.pyparsing: )> -pkg_resources.extern.pyparsing: )> +pkg_resources._vendor.pyparsing: )> +pkg_resources.extern.pyparsing: )> pkg_resources.extern.packaging.markers: pkg_resources.extern.packaging.requirements: pkg_resources: