Skip to content

Commit

Permalink
v3.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
impratikjaiswal committed Jan 1, 2024
1 parent 2096dd8 commit 9b92796
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 41 deletions.
2 changes: 1 addition & 1 deletion python_helpers/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@

from incremental import Version

__version__ = Version("python_helpers", 3, 0, 0)
__version__ = Version("python_helpers", 3, 0, 1)
__all__ = ["__version__"]
4 changes: 4 additions & 0 deletions python_helpers/ph_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down Expand Up @@ -224,3 +226,5 @@ class PhConstants:
'https://ipv6.icanhazip.com/',
'https://v6.ident.me/',
]

STR_SELECT_OPTION = '-- Select --'
4 changes: 4 additions & 0 deletions python_helpers/ph_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -66,6 +68,8 @@ class PhKeys:
RUN_TIME = 'run_time'

#
PROCESS = 'process'

SAMPLE = 'sample'
SAMPLE_1 = 'sample_1'
SAMPLE_2 = 'sample_2'
Expand Down
36 changes: 24 additions & 12 deletions python_helpers/ph_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
Expand All @@ -199,15 +203,21 @@ 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:
# Check if sub-objects are Iterable
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):
Expand Down Expand Up @@ -1478,19 +1488,21 @@ 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):
obj_list = [cls_to_explore(obj).name for obj in obj_list]
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)
Expand Down Expand Up @@ -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
56 changes: 28 additions & 28 deletions python_helpers/test/log/pycharm.log
Original file line number Diff line number Diff line change
Expand Up @@ -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
--------------------------------------------------------------------------------
Expand All @@ -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 -----------------------------------------------
Expand All @@ -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
--------------------------------------------------------------------------------
Expand All @@ -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
--------------------------------------------------------------------------------
Expand All @@ -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
--------------------------------------------------------------------------------
Expand Down Expand Up @@ -833,7 +833,7 @@ zoneinfo._common: <module 'zoneinfo._common' from 'D:\\ProgramFiles\\Python39\\l
_zoneinfo: <module '_zoneinfo' from 'D:\\ProgramFiles\\Python39\\DLLs\\_zoneinfo.pyd'>
zoneinfo: <module 'zoneinfo' from 'D:\\ProgramFiles\\Python39\\lib\\zoneinfo\\__init__.py'>
six: <module 'six' from 'D:\\Other\\Github_Self\\pythonHelpers\\venv\\lib\\site-packages\\six.py'>
six.moves: <module 'six.moves' (<six._SixMetaPathImporter object at 0x0000027B2167A220>)>
six.moves: <module 'six.moves' (<six._SixMetaPathImporter object at 0x0000024A1D557520>)>
dateutil.tz._common: <module 'dateutil.tz._common' from 'D:\\Other\\Github_Self\\pythonHelpers\\venv\\lib\\site-packages\\dateutil\\tz\\_common.py'>
dateutil.tz._factories: <module 'dateutil.tz._factories' from 'D:\\Other\\Github_Self\\pythonHelpers\\venv\\lib\\site-packages\\dateutil\\tz\\_factories.py'>
ctypes.wintypes: <module 'ctypes.wintypes' from 'D:\\ProgramFiles\\Python39\\lib\\ctypes\\wintypes.py'>
Expand Down Expand Up @@ -1166,19 +1166,19 @@ email.feedparser: <module 'email.feedparser' from 'D:\\ProgramFiles\\Python39\\l
email.parser: <module 'email.parser' from 'D:\\ProgramFiles\\Python39\\lib\\email\\parser.py'>
pkg_resources.extern: <module 'pkg_resources.extern' from 'D:\\Other\\Github_Self\\pythonHelpers\\venv\\lib\\site-packages\\pkg_resources\\extern\\__init__.py'>
pkg_resources._vendor: <module 'pkg_resources._vendor' from 'D:\\Other\\Github_Self\\pythonHelpers\\venv\\lib\\site-packages\\pkg_resources\\_vendor\\__init__.py'>
pkg_resources._vendor.appdirs: <module 'pkg_resources.extern.appdirs' (<pkg_resources.extern.VendorImporter object at 0x0000027B22C1CE80>)>
pkg_resources.extern.appdirs: <module 'pkg_resources.extern.appdirs' (<pkg_resources.extern.VendorImporter object at 0x0000027B22C1CE80>)>
pkg_resources._vendor.appdirs: <module 'pkg_resources.extern.appdirs' (<pkg_resources.extern.VendorImporter object at 0x0000024A1EB0F1C0>)>
pkg_resources.extern.appdirs: <module 'pkg_resources.extern.appdirs' (<pkg_resources.extern.VendorImporter object at 0x0000024A1EB0F1C0>)>
pkg_resources._vendor.packaging.__about__: <module 'pkg_resources._vendor.packaging.__about__' from 'D:\\Other\\Github_Self\\pythonHelpers\\venv\\lib\\site-packages\\pkg_resources\\_vendor\\packaging\\__about__.py'>
pkg_resources._vendor.packaging: <module 'pkg_resources.extern.packaging' (<pkg_resources.extern.VendorImporter object at 0x0000027B22C1CE80>)>
pkg_resources.extern.packaging: <module 'pkg_resources.extern.packaging' (<pkg_resources.extern.VendorImporter object at 0x0000027B22C1CE80>)>
pkg_resources._vendor.packaging: <module 'pkg_resources.extern.packaging' (<pkg_resources.extern.VendorImporter object at 0x0000024A1EB0F1C0>)>
pkg_resources.extern.packaging: <module 'pkg_resources.extern.packaging' (<pkg_resources.extern.VendorImporter object at 0x0000024A1EB0F1C0>)>
pkg_resources.extern.packaging._structures: <module 'pkg_resources.extern.packaging._structures' from 'D:\\Other\\Github_Self\\pythonHelpers\\venv\\lib\\site-packages\\pkg_resources\\_vendor\\packaging\\_structures.py'>
pkg_resources.extern.packaging._typing: <module 'pkg_resources.extern.packaging._typing' from 'D:\\Other\\Github_Self\\pythonHelpers\\venv\\lib\\site-packages\\pkg_resources\\_vendor\\packaging\\_typing.py'>
pkg_resources.extern.packaging.version: <module 'pkg_resources.extern.packaging.version' from 'D:\\Other\\Github_Self\\pythonHelpers\\venv\\lib\\site-packages\\pkg_resources\\_vendor\\packaging\\version.py'>
pkg_resources.extern.packaging._compat: <module 'pkg_resources.extern.packaging._compat' from 'D:\\Other\\Github_Self\\pythonHelpers\\venv\\lib\\site-packages\\pkg_resources\\_vendor\\packaging\\_compat.py'>
pkg_resources.extern.packaging.utils: <module 'pkg_resources.extern.packaging.utils' from 'D:\\Other\\Github_Self\\pythonHelpers\\venv\\lib\\site-packages\\pkg_resources\\_vendor\\packaging\\utils.py'>
pkg_resources.extern.packaging.specifiers: <module 'pkg_resources.extern.packaging.specifiers' from 'D:\\Other\\Github_Self\\pythonHelpers\\venv\\lib\\site-packages\\pkg_resources\\_vendor\\packaging\\specifiers.py'>
pkg_resources._vendor.pyparsing: <module 'pkg_resources.extern.pyparsing' (<pkg_resources.extern.VendorImporter object at 0x0000027B22C1CE80>)>
pkg_resources.extern.pyparsing: <module 'pkg_resources.extern.pyparsing' (<pkg_resources.extern.VendorImporter object at 0x0000027B22C1CE80>)>
pkg_resources._vendor.pyparsing: <module 'pkg_resources.extern.pyparsing' (<pkg_resources.extern.VendorImporter object at 0x0000024A1EB0F1C0>)>
pkg_resources.extern.pyparsing: <module 'pkg_resources.extern.pyparsing' (<pkg_resources.extern.VendorImporter object at 0x0000024A1EB0F1C0>)>
pkg_resources.extern.packaging.markers: <module 'pkg_resources.extern.packaging.markers' from 'D:\\Other\\Github_Self\\pythonHelpers\\venv\\lib\\site-packages\\pkg_resources\\_vendor\\packaging\\markers.py'>
pkg_resources.extern.packaging.requirements: <module 'pkg_resources.extern.packaging.requirements' from 'D:\\Other\\Github_Self\\pythonHelpers\\venv\\lib\\site-packages\\pkg_resources\\_vendor\\packaging\\requirements.py'>
pkg_resources: <module 'pkg_resources' from 'D:\\Other\\Github_Self\\pythonHelpers\\venv\\lib\\site-packages\\pkg_resources\\__init__.py'>
Expand Down Expand Up @@ -1660,7 +1660,7 @@ zoneinfo._common: <module 'zoneinfo._common' from 'D:\\ProgramFiles\\Python39\\l
_zoneinfo: <module '_zoneinfo' from 'D:\\ProgramFiles\\Python39\\DLLs\\_zoneinfo.pyd'>
zoneinfo: <module 'zoneinfo' from 'D:\\ProgramFiles\\Python39\\lib\\zoneinfo\\__init__.py'>
six: <module 'six' from 'D:\\Other\\Github_Self\\pythonHelpers\\venv\\lib\\site-packages\\six.py'>
six.moves: <module 'six.moves' (<six._SixMetaPathImporter object at 0x0000027B2167A220>)>
six.moves: <module 'six.moves' (<six._SixMetaPathImporter object at 0x0000024A1D557520>)>
dateutil.tz._common: <module 'dateutil.tz._common' from 'D:\\Other\\Github_Self\\pythonHelpers\\venv\\lib\\site-packages\\dateutil\\tz\\_common.py'>
dateutil.tz._factories: <module 'dateutil.tz._factories' from 'D:\\Other\\Github_Self\\pythonHelpers\\venv\\lib\\site-packages\\dateutil\\tz\\_factories.py'>
ctypes.wintypes: <module 'ctypes.wintypes' from 'D:\\ProgramFiles\\Python39\\lib\\ctypes\\wintypes.py'>
Expand Down Expand Up @@ -1993,19 +1993,19 @@ email.feedparser: <module 'email.feedparser' from 'D:\\ProgramFiles\\Python39\\l
email.parser: <module 'email.parser' from 'D:\\ProgramFiles\\Python39\\lib\\email\\parser.py'>
pkg_resources.extern: <module 'pkg_resources.extern' from 'D:\\Other\\Github_Self\\pythonHelpers\\venv\\lib\\site-packages\\pkg_resources\\extern\\__init__.py'>
pkg_resources._vendor: <module 'pkg_resources._vendor' from 'D:\\Other\\Github_Self\\pythonHelpers\\venv\\lib\\site-packages\\pkg_resources\\_vendor\\__init__.py'>
pkg_resources._vendor.appdirs: <module 'pkg_resources.extern.appdirs' (<pkg_resources.extern.VendorImporter object at 0x0000027B22C1CE80>)>
pkg_resources.extern.appdirs: <module 'pkg_resources.extern.appdirs' (<pkg_resources.extern.VendorImporter object at 0x0000027B22C1CE80>)>
pkg_resources._vendor.appdirs: <module 'pkg_resources.extern.appdirs' (<pkg_resources.extern.VendorImporter object at 0x0000024A1EB0F1C0>)>
pkg_resources.extern.appdirs: <module 'pkg_resources.extern.appdirs' (<pkg_resources.extern.VendorImporter object at 0x0000024A1EB0F1C0>)>
pkg_resources._vendor.packaging.__about__: <module 'pkg_resources._vendor.packaging.__about__' from 'D:\\Other\\Github_Self\\pythonHelpers\\venv\\lib\\site-packages\\pkg_resources\\_vendor\\packaging\\__about__.py'>
pkg_resources._vendor.packaging: <module 'pkg_resources.extern.packaging' (<pkg_resources.extern.VendorImporter object at 0x0000027B22C1CE80>)>
pkg_resources.extern.packaging: <module 'pkg_resources.extern.packaging' (<pkg_resources.extern.VendorImporter object at 0x0000027B22C1CE80>)>
pkg_resources._vendor.packaging: <module 'pkg_resources.extern.packaging' (<pkg_resources.extern.VendorImporter object at 0x0000024A1EB0F1C0>)>
pkg_resources.extern.packaging: <module 'pkg_resources.extern.packaging' (<pkg_resources.extern.VendorImporter object at 0x0000024A1EB0F1C0>)>
pkg_resources.extern.packaging._structures: <module 'pkg_resources.extern.packaging._structures' from 'D:\\Other\\Github_Self\\pythonHelpers\\venv\\lib\\site-packages\\pkg_resources\\_vendor\\packaging\\_structures.py'>
pkg_resources.extern.packaging._typing: <module 'pkg_resources.extern.packaging._typing' from 'D:\\Other\\Github_Self\\pythonHelpers\\venv\\lib\\site-packages\\pkg_resources\\_vendor\\packaging\\_typing.py'>
pkg_resources.extern.packaging.version: <module 'pkg_resources.extern.packaging.version' from 'D:\\Other\\Github_Self\\pythonHelpers\\venv\\lib\\site-packages\\pkg_resources\\_vendor\\packaging\\version.py'>
pkg_resources.extern.packaging._compat: <module 'pkg_resources.extern.packaging._compat' from 'D:\\Other\\Github_Self\\pythonHelpers\\venv\\lib\\site-packages\\pkg_resources\\_vendor\\packaging\\_compat.py'>
pkg_resources.extern.packaging.utils: <module 'pkg_resources.extern.packaging.utils' from 'D:\\Other\\Github_Self\\pythonHelpers\\venv\\lib\\site-packages\\pkg_resources\\_vendor\\packaging\\utils.py'>
pkg_resources.extern.packaging.specifiers: <module 'pkg_resources.extern.packaging.specifiers' from 'D:\\Other\\Github_Self\\pythonHelpers\\venv\\lib\\site-packages\\pkg_resources\\_vendor\\packaging\\specifiers.py'>
pkg_resources._vendor.pyparsing: <module 'pkg_resources.extern.pyparsing' (<pkg_resources.extern.VendorImporter object at 0x0000027B22C1CE80>)>
pkg_resources.extern.pyparsing: <module 'pkg_resources.extern.pyparsing' (<pkg_resources.extern.VendorImporter object at 0x0000027B22C1CE80>)>
pkg_resources._vendor.pyparsing: <module 'pkg_resources.extern.pyparsing' (<pkg_resources.extern.VendorImporter object at 0x0000024A1EB0F1C0>)>
pkg_resources.extern.pyparsing: <module 'pkg_resources.extern.pyparsing' (<pkg_resources.extern.VendorImporter object at 0x0000024A1EB0F1C0>)>
pkg_resources.extern.packaging.markers: <module 'pkg_resources.extern.packaging.markers' from 'D:\\Other\\Github_Self\\pythonHelpers\\venv\\lib\\site-packages\\pkg_resources\\_vendor\\packaging\\markers.py'>
pkg_resources.extern.packaging.requirements: <module 'pkg_resources.extern.packaging.requirements' from 'D:\\Other\\Github_Self\\pythonHelpers\\venv\\lib\\site-packages\\pkg_resources\\_vendor\\packaging\\requirements.py'>
pkg_resources: <module 'pkg_resources' from 'D:\\Other\\Github_Self\\pythonHelpers\\venv\\lib\\site-packages\\pkg_resources\\__init__.py'>
Expand Down

0 comments on commit 9b92796

Please sign in to comment.