kmisc 2.1.102__py3-none-any.whl → 2.1.103__py3-none-any.whl
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/__init__.py +80 -40
- {kmisc-2.1.102.dist-info → kmisc-2.1.103.dist-info}/METADATA +1 -1
- kmisc-2.1.103.dist-info/RECORD +6 -0
- kmisc-2.1.102.dist-info/RECORD +0 -6
- {kmisc-2.1.102.dist-info → kmisc-2.1.103.dist-info}/LICENSE +0 -0
- {kmisc-2.1.102.dist-info → kmisc-2.1.103.dist-info}/WHEEL +0 -0
- {kmisc-2.1.102.dist-info → kmisc-2.1.103.dist-info}/top_level.txt +0 -0
kmisc/__init__.py
CHANGED
@@ -1859,8 +1859,8 @@ def cut_string(string,max_len=None,sub_len=None,new_line='\n',front_space=False,
|
|
1859
1859
|
def FirstKey(src,default=None):
|
1860
1860
|
return Next(src,default=default)
|
1861
1861
|
|
1862
|
-
def code_error(log_msg=None):
|
1863
|
-
return ExceptMessage(msg=log_msg)
|
1862
|
+
def code_error(log_msg=None,**opts):
|
1863
|
+
return ExceptMessage(msg=log_msg,default=opts.get('default'))
|
1864
1864
|
|
1865
1865
|
def DirName(src,default=None):
|
1866
1866
|
dirname=Path(src,default=default)
|
@@ -1932,7 +1932,7 @@ def Keys(src,find=None,start=None,end=None,sym='\n',default=[],word=False,patter
|
|
1932
1932
|
return rt
|
1933
1933
|
return default
|
1934
1934
|
|
1935
|
-
def findXML(xmlfile,find_name=None,find_path=None,default=None,out='xmlobj',get_opt=None):
|
1935
|
+
def findXML(xmlfile,find_name=None,find_path=None,default=None,out='xmlobj',get_opt=None,find_all=False):
|
1936
1936
|
#<Menu name="Security">
|
1937
1937
|
# <Setting name="Administrator Password" type="Password">
|
1938
1938
|
# <Information>
|
@@ -1942,6 +1942,9 @@ def findXML(xmlfile,find_name=None,find_path=None,default=None,out='xmlobj',get_
|
|
1942
1942
|
#</Menu>
|
1943
1943
|
#findXML(cfg_file,find_name='Administrator Password',find_path='./Information/HasPassword',out='data'))
|
1944
1944
|
# => False
|
1945
|
+
# find_name : for finding XML root with maching data of tag name 'name'
|
1946
|
+
# find_path : it searching item keys(ex: Setting/Information/HasPassword) from found XML root
|
1947
|
+
# get_opt : tag name (ex: name, type)
|
1945
1948
|
if os.path.isfile(xmlfile):
|
1946
1949
|
try:
|
1947
1950
|
tree=ET.parse(xmlfile)
|
@@ -1953,53 +1956,90 @@ def findXML(xmlfile,find_name=None,find_path=None,default=None,out='xmlobj',get_
|
|
1953
1956
|
root=ET.fromstring(xmlfile)
|
1954
1957
|
except:
|
1955
1958
|
return default
|
1956
|
-
def
|
1959
|
+
def find_root(tr,find_name):
|
1957
1960
|
for x in tr:
|
1958
1961
|
if x.attrib.get('name') == find_name:
|
1959
1962
|
return x,x.tag
|
1960
|
-
rt,pp=
|
1963
|
+
rt,pp=find_root(x,find_name)
|
1961
1964
|
if rt:
|
1962
1965
|
return rt,'{}/{}'.format(x.tag,pp)
|
1963
1966
|
return None,None
|
1964
|
-
|
1967
|
+
def find_item(tr,find_path):
|
1968
|
+
for x in tr:
|
1969
|
+
if x.tag == find_path[0]:
|
1970
|
+
if find_path[1:]:
|
1971
|
+
a,p=find_item(x,find_path[1:])
|
1972
|
+
if a is not None:
|
1973
|
+
return a,'{}/{}'.format(find_path[0],p)
|
1974
|
+
else:
|
1975
|
+
return x,find_path[0]
|
1976
|
+
return None,None
|
1977
|
+
def find_all_items(tr,find_path):
|
1978
|
+
out=[]
|
1979
|
+
for i in tr:
|
1980
|
+
a=i.findall(find_path)
|
1981
|
+
if a:
|
1982
|
+
out=out+a
|
1983
|
+
o=find_all_items(i,find_path)
|
1984
|
+
if o:
|
1985
|
+
out=out+o
|
1986
|
+
return out
|
1987
|
+
found_root=None,None
|
1988
|
+
#find XML root with name tag information or root's tag name
|
1965
1989
|
if find_name:
|
1966
|
-
|
1967
|
-
|
1968
|
-
|
1969
|
-
|
1970
|
-
|
1971
|
-
|
1972
|
-
|
1973
|
-
|
1974
|
-
rt=[]
|
1975
|
-
if out in ['tag','name']:
|
1976
|
-
for ii in found_result:
|
1977
|
-
rt.append(ii.tag)
|
1978
|
-
elif out in ['text','data']:
|
1979
|
-
for ii in found_result:
|
1990
|
+
found_root=find_root(root,find_name)
|
1991
|
+
if found_root[0] is None: found_root=root,None
|
1992
|
+
if find_all:
|
1993
|
+
o=[]
|
1994
|
+
for i in find_all_items(found_root[0],find_path):
|
1995
|
+
if IsIn(out,['tag','name']):
|
1996
|
+
o.append(i.tag)
|
1997
|
+
elif IsIn(out,['text','data','value']):
|
1980
1998
|
if get_opt:
|
1981
|
-
|
1999
|
+
o.append(i.get(get_opt,default))
|
1982
2000
|
else:
|
1983
|
-
|
1984
|
-
|
1985
|
-
|
1986
|
-
|
1987
|
-
|
1988
|
-
|
1989
|
-
else:
|
1990
|
-
return found_result
|
2001
|
+
o.append(i.text)
|
2002
|
+
elif IsIn(out,['attrib','att','attr']):
|
2003
|
+
o.append(i.attrib)
|
2004
|
+
else:
|
2005
|
+
o.append(i)
|
2006
|
+
return o
|
1991
2007
|
else:
|
1992
|
-
|
1993
|
-
|
1994
|
-
|
1995
|
-
|
1996
|
-
|
1997
|
-
|
1998
|
-
|
1999
|
-
|
2000
|
-
|
2001
|
-
|
2002
|
-
|
2008
|
+
# Searching path from found root or original root
|
2009
|
+
if find_path and isinstance(find_path,str):
|
2010
|
+
if find_path[0] == '/': find_path=find_path[1:]
|
2011
|
+
#ex: root.findall('./Menu/Setting/[@name="Administrator Password"]/Information/HasPassword'):
|
2012
|
+
found_path=find_item(found_root[0],find_path.split('/'))
|
2013
|
+
# <element>.tag: name, .text: data, .attrib: dict
|
2014
|
+
if found_path[0] is not None:
|
2015
|
+
if IsIn(out,['tag','name']):
|
2016
|
+
return found_path[0].tag
|
2017
|
+
elif IsIn(out,['text','data','value']):
|
2018
|
+
if get_opt:
|
2019
|
+
return found_path[0].get(get_opt,default)
|
2020
|
+
return found_path[0].text
|
2021
|
+
elif IsIn(out,['attrib','att','attr']):
|
2022
|
+
return found_path[0].attrib
|
2023
|
+
elif IsIn(out,['path','key','keys']):
|
2024
|
+
print('>>',found_root[1],':',found_path[1])
|
2025
|
+
if found_root[1] is None:
|
2026
|
+
return found_path[1]
|
2027
|
+
return os.path.join(found_root[1],found_path[1])
|
2028
|
+
return found_root[0]
|
2029
|
+
else:
|
2030
|
+
if found_root[0] is not None:
|
2031
|
+
if IsIn(out,['tag','name']):
|
2032
|
+
return found_root[0].tag
|
2033
|
+
elif IsIn(out,['text','data','value']):
|
2034
|
+
if get_opt:
|
2035
|
+
return found_root[0].get(get_opt,default)
|
2036
|
+
else:
|
2037
|
+
return found_root[0].text
|
2038
|
+
elif IsIn(out,['attrib','att','attr']):
|
2039
|
+
return found_root[0].attrib
|
2040
|
+
elif IsIn(out,['path','key','keys']):
|
2041
|
+
return found_root[1]
|
2042
|
+
return found_root[0]
|
2003
2043
|
return default
|
2004
2044
|
|
2005
2045
|
def Compress(data,mode='lz4'):
|
@@ -0,0 +1,6 @@
|
|
1
|
+
kmisc/__init__.py,sha256=M_qZMlje0d2XVnaVKiReSbfllci2Wxs0NVQpKf8aMvA,135036
|
2
|
+
kmisc-2.1.103.dist-info/LICENSE,sha256=mn9ekhb34HJxsrVhcxrLXJUzy55T62zg-Gh9Ro0mVJI,1066
|
3
|
+
kmisc-2.1.103.dist-info/METADATA,sha256=ELQ4-WtZLBetUCuzzOt3EwQDxh2MsjWH0H28tJTKw70,5503
|
4
|
+
kmisc-2.1.103.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
|
5
|
+
kmisc-2.1.103.dist-info/top_level.txt,sha256=wvdHf5aQTqcGYvxk-F9E_BMWLMhlwC8INBmwO-V6_X4,6
|
6
|
+
kmisc-2.1.103.dist-info/RECORD,,
|
kmisc-2.1.102.dist-info/RECORD
DELETED
@@ -1,6 +0,0 @@
|
|
1
|
-
kmisc/__init__.py,sha256=gpYi_z41Sl5sCjQCMkLfDFeDXpbhIK5L9g8h4_5IrL0,133022
|
2
|
-
kmisc-2.1.102.dist-info/LICENSE,sha256=mn9ekhb34HJxsrVhcxrLXJUzy55T62zg-Gh9Ro0mVJI,1066
|
3
|
-
kmisc-2.1.102.dist-info/METADATA,sha256=SPMp-mWR3Yet1Lxuxb9SeLbGk9y_Br7piWDLPcHTVJw,5503
|
4
|
-
kmisc-2.1.102.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
|
5
|
-
kmisc-2.1.102.dist-info/top_level.txt,sha256=wvdHf5aQTqcGYvxk-F9E_BMWLMhlwC8INBmwO-V6_X4,6
|
6
|
-
kmisc-2.1.102.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|