kmisc 2.1.116__tar.gz → 2.1.118__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {kmisc-2.1.116 → kmisc-2.1.118}/PKG-INFO +1 -1
- {kmisc-2.1.116 → kmisc-2.1.118}/kmisc/__init__.py +86 -1
- {kmisc-2.1.116 → kmisc-2.1.118}/kmisc.egg-info/PKG-INFO +1 -1
- {kmisc-2.1.116 → kmisc-2.1.118}/LICENSE +0 -0
- {kmisc-2.1.116 → kmisc-2.1.118}/README.md +0 -0
- {kmisc-2.1.116 → kmisc-2.1.118}/kmisc.egg-info/SOURCES.txt +0 -0
- {kmisc-2.1.116 → kmisc-2.1.118}/kmisc.egg-info/dependency_links.txt +0 -0
- {kmisc-2.1.116 → kmisc-2.1.118}/kmisc.egg-info/top_level.txt +0 -0
- {kmisc-2.1.116 → kmisc-2.1.118}/pyproject.toml +0 -0
- {kmisc-2.1.116 → kmisc-2.1.118}/setup.cfg +0 -0
- {kmisc-2.1.116 → kmisc-2.1.118}/setup.py +0 -0
@@ -1954,6 +1954,91 @@ def Keys(src,find=None,start=None,end=None,sym='\n',default=[],word=False,patter
|
|
1954
1954
|
return rt
|
1955
1955
|
return default
|
1956
1956
|
|
1957
|
+
def XML2Dict(root,path=[],sub=0,ignore_value=['\n']):
|
1958
|
+
#path: {a:{
|
1959
|
+
# b: {
|
1960
|
+
# c: {...},
|
1961
|
+
# d: {...},
|
1962
|
+
# e: {...},
|
1963
|
+
# f: {...},
|
1964
|
+
#path=['a','b',('c','d')] # 3rd is c and d only and others are ignore
|
1965
|
+
#if anything in the level b, but 3rd is c and d only and others are ignore
|
1966
|
+
#path=['a','*',('c','d')]
|
1967
|
+
#exclude 'c' and 'e' only at the 3rd level and others are ok in 3rd level
|
1968
|
+
#path=['a','*',{'c','e'}]
|
1969
|
+
if isinstance(root,str):
|
1970
|
+
if os.path.isfile(root):
|
1971
|
+
try:
|
1972
|
+
tree=ET.parse(root)
|
1973
|
+
root=tree.getroot()
|
1974
|
+
except:
|
1975
|
+
return False
|
1976
|
+
|
1977
|
+
attr_root=root.attrib
|
1978
|
+
root_tag=attr_root.get('name',root.tag)
|
1979
|
+
out={root_tag:attr_root}
|
1980
|
+
d_root=out[root_tag]
|
1981
|
+
new_sub=sub+1
|
1982
|
+
for x in root:
|
1983
|
+
if isinstance(x,str): continue
|
1984
|
+
if path:
|
1985
|
+
if len(path) <= sub: continue
|
1986
|
+
if isinstance(path[sub],tuple): #tuple then choose only same key
|
1987
|
+
if root_tag not in path[sub]:
|
1988
|
+
continue
|
1989
|
+
elif isinstance(path[sub],set): #set then ignore the choosed names, but others are ok
|
1990
|
+
if root_tag in path[sub]:
|
1991
|
+
continue
|
1992
|
+
else:
|
1993
|
+
if path[sub] != '*' and root_tag != path[sub]:
|
1994
|
+
continue
|
1995
|
+
|
1996
|
+
# for <Subtitle> ... </Subtitle>
|
1997
|
+
# for <Text> ... </Text>
|
1998
|
+
attr_x=x.attrib
|
1999
|
+
x_tag=attr_x.get('name',attr_x.get('id',x.tag)) #<tag name=xxx id=xxx> ... </tag>
|
2000
|
+
#Special Tag
|
2001
|
+
if x_tag == 'Subtitle': #Subtitle
|
2002
|
+
if x_tag not in d_root:
|
2003
|
+
d_root[x_tag]=[]
|
2004
|
+
d_root[x_tag].append([x.text])
|
2005
|
+
elif x_tag == 'Text': #Text
|
2006
|
+
if 'Subtitle' in d_root:
|
2007
|
+
d_root['Subtitle'][-1].append(x.text) # Adding Text string to Subtitle when exist Subtitle
|
2008
|
+
else:
|
2009
|
+
if x_tag not in d_root:
|
2010
|
+
d_root[x_tag]=[]
|
2011
|
+
d_root[x_tag].append(x.text) # Adding Text string to Subtitle when exist Subtitle
|
2012
|
+
elif x_tag == 'Option': #option case
|
2013
|
+
if x_tag not in d_root:
|
2014
|
+
d_root[x_tag]=[]
|
2015
|
+
d_root[x_tag].append(attr_x) # {...}
|
2016
|
+
x_data=x.text # <>text</> put at "data" key's value
|
2017
|
+
sub_data=XML2Dict(x,path=path,sub=sub+1,ignore_value=ignore_value)
|
2018
|
+
sub_key=next(iter(sub_data))
|
2019
|
+
if sub_data[sub_key]:
|
2020
|
+
for i in sub_data[sub_key]:
|
2021
|
+
d_root[x_tag][-1][i]=sub_data[sub_key][i]
|
2022
|
+
if isinstance(x_data,str):
|
2023
|
+
_x_=x_data.strip()
|
2024
|
+
if _x_ == '\n' or not _x_ or _x_ in ignore_value:
|
2025
|
+
continue
|
2026
|
+
d_root[x_tag][-1]['data']=x_data
|
2027
|
+
else: #Normal case
|
2028
|
+
d_root[x_tag]=attr_x # {...}
|
2029
|
+
x_data=x.text # <>text</> put at "data" key's value
|
2030
|
+
sub_data=XML2Dict(x,path=path,sub=sub+1,ignore_value=ignore_value)
|
2031
|
+
sub_key=next(iter(sub_data))
|
2032
|
+
if sub_data[sub_key]:
|
2033
|
+
for i in sub_data[sub_key]:
|
2034
|
+
d_root[x_tag][i]=sub_data[sub_key][i]
|
2035
|
+
if isinstance(x_data,str):
|
2036
|
+
_x_=x_data.strip()
|
2037
|
+
if _x_ == '\n' or not _x_ or _x_ in ignore_value:
|
2038
|
+
continue
|
2039
|
+
d_root[x_tag]['data']=x_data
|
2040
|
+
return out
|
2041
|
+
|
1957
2042
|
def findXML(xmlfile,find_name=None,find_path=None,default=None,out='xmlobj',get_opt=None,find_all=False):
|
1958
2043
|
#<Menu name="Security">
|
1959
2044
|
# <Setting name="Administrator Password" type="Password">
|
@@ -2783,7 +2868,7 @@ def kmp(mp={},func=None,name=None,timeout=0,quit=False,log_file=None,log_screen=
|
|
2783
2868
|
return rc
|
2784
2869
|
|
2785
2870
|
for n in [k for k in mp]:
|
2786
|
-
if isinstance(mp[
|
2871
|
+
if isinstance(mp[n],dict):
|
2787
2872
|
timeout=mp[n].get('timeout',0)
|
2788
2873
|
if quit is True or timeout > 0 and TIME().Int() > timeout:
|
2789
2874
|
if n != 'log':
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|