kmisc 2.1.118__tar.gz → 2.1.119__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: kmisc
3
- Version: 2.1.118
3
+ Version: 2.1.119
4
4
  Summary: Enginering useful library
5
5
  Home-page: https://github.com/kagepark/kmisc
6
6
  Author: Kage Park
@@ -1973,30 +1973,35 @@ def XML2Dict(root,path=[],sub=0,ignore_value=['\n']):
1973
1973
  root=tree.getroot()
1974
1974
  except:
1975
1975
  return False
1976
+ def ignore(a,b):
1977
+ if isinstance(b,tuple) and a not in b:
1978
+ return True
1979
+ elif isinstance(b,set) and a in b:
1980
+ return True
1981
+ elif not isinstance(b,(tuple,set)) and b != '*' and a != b:
1982
+ return True
1983
+ return False
1976
1984
 
1977
1985
  attr_root=root.attrib
1978
1986
  root_tag=attr_root.get('name',root.tag)
1979
- out={root_tag:attr_root}
1987
+ #Current Path (root)
1988
+ if path and len(path) > sub:
1989
+ if ignore(root_tag,path[sub]): return {}
1990
+ out={root_tag:{}}
1991
+ for i in attr_root:
1992
+ if path and len(path) > sub+1:
1993
+ if ignore(i,path[sub+1]): continue
1994
+ out[root_tag][i]=attr_root[i]
1980
1995
  d_root=out[root_tag]
1981
- new_sub=sub+1
1982
1996
  for x in root:
1983
1997
  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
-
1998
+ #Sub Path
1996
1999
  # for <Subtitle> ... </Subtitle>
1997
2000
  # for <Text> ... </Text>
1998
2001
  attr_x=x.attrib
1999
2002
  x_tag=attr_x.get('name',attr_x.get('id',x.tag)) #<tag name=xxx id=xxx> ... </tag>
2003
+ if path and len(path) > sub+1:
2004
+ if ignore(x_tag,path[sub+1]): continue
2000
2005
  #Special Tag
2001
2006
  if x_tag == 'Subtitle': #Subtitle
2002
2007
  if x_tag not in d_root:
@@ -2025,18 +2030,26 @@ def XML2Dict(root,path=[],sub=0,ignore_value=['\n']):
2025
2030
  continue
2026
2031
  d_root[x_tag][-1]['data']=x_data
2027
2032
  else: #Normal case
2028
- d_root[x_tag]=attr_x # {...}
2033
+ #Sub's sub
2034
+ #d_root[x_tag]=attr_x # {...}
2035
+ d_root[x_tag]={}
2036
+ for i in attr_x:
2037
+ if path and len(path) > sub+1:
2038
+ if ignore(i,path[sub+1]): continue
2039
+ d_root[x_tag][i]=attr_x[i]
2040
+
2029
2041
  x_data=x.text # <>text</> put at "data" key's value
2030
2042
  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
2043
+ if len(sub_data) == 1:
2044
+ sub_key=next(iter(sub_data))
2045
+ if sub_data[sub_key]:
2046
+ for i in sub_data[sub_key]:
2047
+ d_root[x_tag][i]=sub_data[sub_key][i]
2048
+ if isinstance(x_data,str):
2049
+ _x_=x_data.strip()
2050
+ if _x_ == '\n' or not _x_ or _x_ in ignore_value:
2051
+ continue
2052
+ d_root[x_tag]['data']=x_data
2040
2053
  return out
2041
2054
 
2042
2055
  def findXML(xmlfile,find_name=None,find_path=None,default=None,out='xmlobj',get_opt=None,find_all=False):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: kmisc
3
- Version: 2.1.118
3
+ Version: 2.1.119
4
4
  Summary: Enginering useful library
5
5
  Home-page: https://github.com/kagepark/kmisc
6
6
  Author: Kage Park
File without changes
File without changes
File without changes
File without changes
File without changes