buildz 0.3.1__tar.gz → 0.3.3__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.
Files changed (78) hide show
  1. buildz-0.3.3/MANIFEST.in +2 -0
  2. {buildz-0.3.1/buildz.egg-info → buildz-0.3.3}/PKG-INFO +1 -1
  3. buildz-0.3.3/buildz/dj.txt +0 -0
  4. {buildz-0.3.1 → buildz-0.3.3}/buildz/xconfz/fc_item.py +2 -34
  5. {buildz-0.3.1 → buildz-0.3.3}/buildz/xconfz/fc_set.py +1 -50
  6. {buildz-0.3.1 → buildz-0.3.3}/buildz/xconfz/mg_fmt.py +1 -1
  7. buildz-0.3.3/buildz/xf/loader/base.py +50 -0
  8. buildz-0.3.3/buildz/xf/loader/buffer.py +85 -0
  9. buildz-0.3.3/buildz/xf/loader/deal/listz.py +19 -0
  10. buildz-0.3.3/buildz/xf/loader/deal/lr.py +70 -0
  11. buildz-0.3.3/buildz/xf/loader/deal/mapz.py +22 -0
  12. buildz-0.3.3/buildz/xf/loader/deal/nextz.py +22 -0
  13. buildz-0.3.3/buildz/xf/loader/deal/reval.py +37 -0
  14. buildz-0.3.3/buildz/xf/loader/deal/setz.py +35 -0
  15. buildz-0.3.3/buildz/xf/loader/deal/spc.py +19 -0
  16. buildz-0.3.3/buildz/xf/loader/deal/spt.py +39 -0
  17. buildz-0.3.3/buildz/xf/loader/deal/strz.py +72 -0
  18. buildz-0.3.3/buildz/xf/loader/exp.py +12 -0
  19. buildz-0.3.3/buildz/xf/loader/item.py +48 -0
  20. buildz-0.3.3/buildz/xf/loader/mg.py +60 -0
  21. buildz-0.3.3/buildz/xf/loader/pos.py +51 -0
  22. buildz-0.3.3/buildz/xf/writer/base.py +39 -0
  23. buildz-0.3.3/buildz/xf/writer/conf.py +56 -0
  24. buildz-0.3.3/buildz/xf/writer/deal/jsonval.py +22 -0
  25. buildz-0.3.3/buildz/xf/writer/deal/listz.py +39 -0
  26. buildz-0.3.3/buildz/xf/writer/deal/mapz.py +42 -0
  27. buildz-0.3.3/buildz/xf/writer/deal/reval.py +25 -0
  28. buildz-0.3.3/buildz/xf/writer/deal/strz.py +50 -0
  29. buildz-0.3.3/buildz/xf/writer/itemz.py +42 -0
  30. buildz-0.3.3/buildz/xf/writer/mg.py +60 -0
  31. {buildz-0.3.1 → buildz-0.3.3/buildz.egg-info}/PKG-INFO +1 -1
  32. {buildz-0.3.1 → buildz-0.3.3}/buildz.egg-info/SOURCES.txt +26 -1
  33. {buildz-0.3.1 → buildz-0.3.3}/setup.py +1 -1
  34. buildz-0.3.1/MANIFEST.in +0 -2
  35. {buildz-0.3.1 → buildz-0.3.3}/LICENSE +0 -0
  36. {buildz-0.3.1 → buildz-0.3.3}/README.md +0 -0
  37. {buildz-0.3.1 → buildz-0.3.3}/buildz/__init__.py +0 -0
  38. {buildz-0.3.1 → buildz-0.3.3}/buildz/__main__.py +0 -0
  39. {buildz-0.3.1 → buildz-0.3.3}/buildz/base.py +0 -0
  40. {buildz-0.3.1 → buildz-0.3.3}/buildz/build.py +0 -0
  41. {buildz-0.3.1 → buildz-0.3.3}/buildz/confz.py +0 -0
  42. {buildz-0.3.1 → buildz-0.3.3}/buildz/demo/demo.confz +0 -0
  43. {buildz-0.3.1 → buildz-0.3.3}/buildz/demo/demo.py +0 -0
  44. {buildz-0.3.1 → buildz-0.3.3}/buildz/demo/run.confz +0 -0
  45. {buildz-0.3.1 → buildz-0.3.3}/buildz/demo/test.confz +0 -0
  46. {buildz-0.3.1 → buildz-0.3.3}/buildz/demo/test.py +0 -0
  47. {buildz-0.3.1 → buildz-0.3.3}/buildz/demo/testc.py +0 -0
  48. {buildz-0.3.1 → buildz-0.3.3}/buildz/demo/testf.py +0 -0
  49. {buildz-0.3.1 → buildz-0.3.3}/buildz/demo/testz.py +0 -0
  50. {buildz-0.3.1 → buildz-0.3.3}/buildz/demo/value.confz +0 -0
  51. {buildz-0.3.1 → buildz-0.3.3}/buildz/demo/x.py +0 -0
  52. {buildz-0.3.1 → buildz-0.3.3}/buildz/keys.py +0 -0
  53. {buildz-0.3.1 → buildz-0.3.3}/buildz/test_loader copy.py +0 -0
  54. {buildz-0.3.1 → buildz-0.3.3}/buildz/test_loader.py +0 -0
  55. {buildz-0.3.1 → buildz-0.3.3}/buildz/test_writer.py +0 -0
  56. {buildz-0.3.1 → buildz-0.3.3}/buildz/tools.py +0 -0
  57. {buildz-0.3.1 → buildz-0.3.3}/buildz/xconfz/__init__.py +0 -0
  58. {buildz-0.3.1 → buildz-0.3.3}/buildz/xconfz/base.py +0 -0
  59. {buildz-0.3.1 → buildz-0.3.3}/buildz/xconfz/buff.py +0 -0
  60. {buildz-0.3.1 → buildz-0.3.3}/buildz/xconfz/fc.py +0 -0
  61. {buildz-0.3.1 → buildz-0.3.3}/buildz/xconfz/fc_list.py +0 -0
  62. {buildz-0.3.1 → buildz-0.3.3}/buildz/xconfz/fc_map.py +0 -0
  63. {buildz-0.3.1 → buildz-0.3.3}/buildz/xconfz/fc_str.py +0 -0
  64. {buildz-0.3.1 → buildz-0.3.3}/buildz/xconfz/fc_type.py +0 -0
  65. {buildz-0.3.1 → buildz-0.3.3}/buildz/xconfz/file.py +0 -0
  66. {buildz-0.3.1 → buildz-0.3.3}/buildz/xconfz/fmt_base.py +0 -0
  67. {buildz-0.3.1 → buildz-0.3.3}/buildz/xconfz/fmt_str.py +0 -0
  68. {buildz-0.3.1 → buildz-0.3.3}/buildz/xconfz/fmt_type.py +0 -0
  69. {buildz-0.3.1 → buildz-0.3.3}/buildz/xconfz/mg.py +0 -0
  70. {buildz-0.3.1 → buildz-0.3.3}/buildz/xf/__init__.py +0 -0
  71. {buildz-0.3.1 → buildz-0.3.3}/buildz/xf/file.py +0 -0
  72. {buildz-0.3.1 → buildz-0.3.3}/buildz/xf/mapz.py +0 -0
  73. {buildz-0.3.1 → buildz-0.3.3}/buildz/xf/read.py +0 -0
  74. {buildz-0.3.1 → buildz-0.3.3}/buildz/xf/test_write.py +0 -0
  75. {buildz-0.3.1 → buildz-0.3.3}/buildz/xf/write.py +0 -0
  76. {buildz-0.3.1 → buildz-0.3.3}/buildz.egg-info/dependency_links.txt +0 -0
  77. {buildz-0.3.1 → buildz-0.3.3}/buildz.egg-info/top_level.txt +0 -0
  78. {buildz-0.3.1 → buildz-0.3.3}/setup.cfg +0 -0
@@ -0,0 +1,2 @@
1
+ include README.md
2
+ recursive-include buildz *
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: buildz
3
- Version: 0.3.1
3
+ Version: 0.3.3
4
4
  Summary: a json-like file format's read and write code by python, and codes to read and product object from configure file in such format
5
5
  Home-page: https://github.com/buildCodeZ/buildz
6
6
  Author: Zzz
File without changes
@@ -1,5 +1,6 @@
1
1
  #coding=utf-8
2
2
  from buildz.xconfz.base import *
3
+
3
4
  from buildz.xconfz.fmt_base import *
4
5
 
5
6
  """
@@ -37,7 +38,7 @@ pass
37
38
  """
38
39
  分割符判断
39
40
  """
40
- class ItemsDeal(BaseDeal):
41
+ class ItemDeal(BaseDeal):
41
42
  def find(self, buff):
42
43
  for spt in self.spts:
43
44
  if self.check_curr(buff, spt):
@@ -74,39 +75,6 @@ class ItemsDeal(BaseDeal):
74
75
  return False
75
76
 
76
77
  pass
77
- class ItemDeal(BaseDeal):
78
- def __init__(self, spt):
79
- self.spt= spt
80
- def init(self, reg):
81
- self.k_spt = reg(self.spt, spt = True)
82
- def prev(self, buff, queue):
83
- find = self.check_curr(buff, self.spt)
84
- if find is None:
85
- return False
86
- lf = len(find)
87
- rm = buff.remain().strip()
88
- pos = buff.pos_remain()
89
- c_pos = buff.pos_curr()
90
- _val = None
91
- if len(queue)>0:
92
- _val = queue[-1].val
93
- if len(queue)==0 or len(rm)>0 or Key.is_inst(_val) and _val.p.spt==True:
94
- #print("val:[{rm}]".format(rm=rm))
95
- queue.append(Item(rm, pos))
96
- queue.append(Item(self.k_spt, c_pos, find))
97
- buff.deal2curr(lf)
98
- return True
99
- def deal(self, queue, stack):
100
- if len(queue)==0:
101
- return False
102
- it = queue[0]
103
- if self.k_spt(it.val):
104
- queue.pop(0)
105
- return True
106
- return False
107
-
108
- pass
109
-
110
78
 
111
79
  '''
112
80
  数据生成格式化字符串
@@ -8,7 +8,7 @@ class TypeSet:
8
8
  return str(self)
9
9
 
10
10
  pass
11
- class SetsDeal(BaseDeal):
11
+ class SetDeal(BaseDeal):
12
12
  Type = TypeSet()
13
13
  def __str__(self):
14
14
  return "@@SetDeal"
@@ -39,55 +39,6 @@ class SetsDeal(BaseDeal):
39
39
  queue.append(Item(self.k_spt, c_pos, find, SetDeal.Type))
40
40
  buff.deal2curr(lf)
41
41
  return True
42
- def deal(self, queue, stack):
43
- if len(stack)<3:
44
- return False
45
- if self.k_spt(stack[-2].val):
46
- if len(queue)>0:
47
- val = queue[0]
48
- if val.type == SetDeal.Type:
49
- return False
50
- val = stack[-1]
51
- if Key.is_inst(val.val):
52
- return False
53
- val = stack.pop(-1)
54
- tmp = stack.pop(-1)
55
- key = stack.pop(-1)
56
- kv = KeyVal(key.val,val.val)
57
- item = Item(kv, key.pos)
58
- stack.append(item)
59
- return True
60
- return False
61
-
62
- pass
63
- class SetDeal(BaseDeal):
64
- Type = TypeSet()
65
- def __str__(self):
66
- return "@@SetDeal"
67
- def __repr__(self):
68
- return str(self)
69
- def find(self, buff):
70
- for spt in self.spts:
71
- if self.check_curr(buff, spt):
72
- return spt
73
- return None
74
- def __init__(self, spt):
75
- self.spt = spt
76
- def init(self, reg):
77
- self.k_spt = reg(k, spt = True)
78
- def prev(self, buff, queue):
79
- find = self.find(buff)
80
- if find is None:
81
- return False
82
- lf = len(find)
83
- rm = buff.remain().strip()
84
- pos = buff.pos_remain()
85
- c_pos = buff.pos_curr()
86
- if len(queue)==0 or len(rm)>0:
87
- queue.append(Item(rm, pos))
88
- queue.append(Item(self.k_spt, c_pos, find, SetDeal.Type))
89
- buff.deal2curr(lf)
90
- return True
91
42
  def deal(self, queue, stack):
92
43
  if len(stack)<3:
93
44
  return False
@@ -80,7 +80,7 @@ class JsonFormat(BaseFormat):
80
80
  value = node.value
81
81
  if value is None:
82
82
  return None
83
- return json.dumps(node.value)
83
+ return json.dumps(node.value, ensure_ascii=False)
84
84
 
85
85
  pass
86
86
  def build_format(bts = False, size = 4, format = False, simple = 1, simple_size = 1, loads = None, as_json =False, t_single = True):
@@ -0,0 +1,50 @@
1
+
2
+ class BaseDeal:
3
+ def sp(self):
4
+ return super(self.__class__, self)
5
+ def regist(self, mgs):
6
+ if self._id is None:
7
+ self._id = mgs.regist()
8
+ def id(self):
9
+ return self._id
10
+ def same(self, s, target):
11
+ return self.like(s, target) == target
12
+ def like(self, s, target):
13
+ if type(target) ==type(s):
14
+ return s
15
+ if type(s)==str:
16
+ return s.encode()
17
+ return s.decode()
18
+ def __str__(self):
19
+ return "BaseDeal"
20
+ def __repr__(self):
21
+ return str(self)
22
+ def __init__(self, *argv, **maps):
23
+ self._id = None
24
+ self.init(*argv, **maps)
25
+ def init(self, *argv, **maps):
26
+ pass
27
+ def prev(self, buffer, queue, pos):
28
+ """
29
+ input:
30
+ buffer: 1,读取字符串/字节,没有pop的时候,会保留读取的数据据, buffer.read(size=1, pop = False), buffer.pop_read(size=1)
31
+ 2,缓存, buffer.add(chars), buffer.lget(size=1): chars, buffer.rget(size=1): chars
32
+ buffer.lpop(size=1):None, buffer.rpop(size=1)
33
+ queue: 存放生成节点的队列, queue=list<obj>
34
+ pos: 位置计算: pos.update(chars), pos.get(index=0|index<=0): return [row, column]
35
+ output:
36
+ bool: 是否进行了处理
37
+ """
38
+ return False
39
+ def deal(self, queue, stack):
40
+ """
41
+ input:
42
+ queue: 节点输入队列
43
+ stack: 存放生成结果的栈
44
+ output:
45
+ bool: 是否进行了处理
46
+ """
47
+ return False
48
+
49
+ pass
50
+
@@ -0,0 +1,85 @@
1
+
2
+ class BufferInput:
3
+ def __init__(self, buf):
4
+ self.buf = buf
5
+ def __call__(self, size=1):
6
+ s = self.buf[:size]
7
+ self.buf = self.buf[size:]
8
+ return s
9
+
10
+ pass
11
+
12
+ class Buffer:
13
+ def read(self, size = 1, pop = 0):
14
+ if self.s_read is None:
15
+ self.s_read = self.input(1)
16
+ l = len(self.s_read)
17
+ if l<size:
18
+ self.s_read += self.input(size-l)
19
+ rst = self.s_read[:size]
20
+ if pop:
21
+ self.s_read = self.s_read[size:]
22
+ if self.buffer is None:
23
+ self.buffer = self.s_read[:0]
24
+ return rst
25
+ def pop_read(self, size=1):
26
+ self.s_read = self.s_read[size:]
27
+ def init(self):
28
+ self.buffer = None
29
+ self.s_read = None
30
+ def __init__(self, input):
31
+ self.input = input
32
+ self.init()
33
+ def add(self, arr):
34
+ if self.buffer is None:
35
+ self.buffer = arr
36
+ else:
37
+ self.buffer += arr
38
+ def size(self):
39
+ if self.buffer is None:
40
+ return 0
41
+ return len(self.buffer)
42
+ def full(self, size = 0, right = 1):
43
+ if right:
44
+ return self.rfull(size)
45
+ return self.lfull(size)
46
+ def clean(self):
47
+ self.buffer = self.buffer[:0]
48
+ def get(self, size=1, right=1):
49
+ if right:
50
+ return self.rget(size)
51
+ return self.lget(size)
52
+ def pop(self, size=1, right=1):
53
+ if right:
54
+ return self.rpop(size)
55
+ return self.lpop(size)
56
+ def lfull(self, size = 0):
57
+ if self.buffer is None:
58
+ return self.buffer
59
+ if size == 0:
60
+ return self.buffer
61
+ return self.buffer[size:]
62
+ def rfull(self, size = 0):
63
+ if self.buffer is None:
64
+ return self.buffer
65
+ if size == 0:
66
+ return self.buffer
67
+ return self.buffer[:-size]
68
+ def lget(self, size=1):
69
+ if self.buffer is None:
70
+ return self.buffer
71
+ return self.buffer[:size]
72
+ def rget(self, size=1):
73
+ if self.buffer is None:
74
+ return self.buffer
75
+ return self.buffer[-size:]
76
+ def lpop(self, size = 1):
77
+ if self.buffer is None:
78
+ return self.buffer
79
+ self.buffer = self.buffer[size:]
80
+ def rpop(self, size=1):
81
+ if self.buffer is None:
82
+ return self.buffer
83
+ self.buffer = self.buffer[:-size]
84
+
85
+ pass
@@ -0,0 +1,19 @@
1
+ from .. import base
2
+ from .. import item
3
+ from .. import exp
4
+ from . import lr
5
+ class ListDeal(lr.LRDeal):
6
+ """
7
+ 分隔符,有分隔符后将缓存的数据当作字符串
8
+ """
9
+ def init(self, left, right):
10
+ self.sp().init(left, right, 'list')
11
+ def build(self, arr, l_item):
12
+ rst = []
13
+ for _item in arr:
14
+ if not _item.check(is_val = 1):
15
+ raise exp.FormatExp("format error find in list:", _item.pos, _item.val)
16
+ rst.append(_item.val)
17
+ return item.DealItem(rst, l_item.pos, self.id(), is_val = 1, is_list = 1)
18
+
19
+ pass
@@ -0,0 +1,70 @@
1
+ from .. import base
2
+ from .. import item
3
+ from .. import exp
4
+ class LRDeal(base.BaseDeal):
5
+ """
6
+ 分隔符,有分隔符后将缓存的数据当作字符串
7
+ """
8
+ def init(self, left, right, name= "lr"):
9
+ self.left = left
10
+ self.right = right
11
+ self.ll = len(left)
12
+ self.lr = len(right)
13
+ self.name = name
14
+ def build(self, arr, l_item):
15
+ # implement this
16
+ return item.DealItem(arr, l_item.pos, self.id())
17
+ def err(self, s):
18
+ return s.replace("<lr>", self.name)
19
+ def prev(self, buffer, queue, pos):
20
+ cl = buffer.read(self.ll)
21
+ cr = buffer.read(self.lr)
22
+ if not self.same(self.left, cl) and not self.same(self.right, cr):
23
+ return False
24
+ if self.same(self.left, cl):
25
+ buffer.pop_read(self.ll)
26
+ rm = buffer.full()
27
+ if len(rm.strip())>0:
28
+ pos.update(rm)
29
+ raise exp.FormatExp(self.err("unexcept char before <lr> left symbol"), pos.get(), rm)
30
+ pos.update(cl)
31
+ queue.append(item.PrevItem(cl, pos.get(), self.id(), left = 1))
32
+ else:
33
+ buffer.pop_read(self.lr)
34
+ rm = buffer.full()
35
+ buffer.clean()
36
+ pos.update(rm)
37
+ # 这里对扩展不太好,需要注意
38
+ if len(rm.strip())>0 or len(queue)==0 or queue[-1].none(is_val = 1,type=self.id(), right=1,allow_empty=0):
39
+ queue.append(item.PrevItem(rm, pos.get(), is_val=1))
40
+ pos.update(cr)
41
+ queue.append(item.PrevItem(cr, pos.get(), self.id(), right = 1))
42
+ return True
43
+ def deal(self, queue, stack):
44
+ if len(queue)==0:
45
+ return False
46
+ _item = queue[0]
47
+ if not _item.check(type=self.id()):
48
+ return False
49
+ if not _item.check(left=1) and not _item.check(right=1):
50
+ return False
51
+ queue.pop(0)
52
+ if _item.check(left = 1):
53
+ stack.append(_item)
54
+ return True
55
+ rst = []
56
+ l_item = None
57
+ while len(stack)>0:
58
+ item_i = stack.pop(-1)
59
+ if item_i.check(type = self.id()) and item_i.check(left=1):
60
+ l_item = item_i
61
+ break
62
+ rst.append(item_i)
63
+ if l_item is None:
64
+ raise exp.FormatExp(self.err("find <lr> right symbal while not left symbal found"), _item.pos, _item.val)
65
+ rst.reverse()
66
+ rst = self.build(rst, l_item)
67
+ stack.append(rst)
68
+ return True
69
+
70
+ pass
@@ -0,0 +1,22 @@
1
+ from .. import base
2
+ from .. import item
3
+ from .. import exp
4
+ from . import lr
5
+ class MapDeal(lr.LRDeal):
6
+ """
7
+ 分隔符,有分隔符后将缓存的数据当作字符串
8
+ """
9
+ def init(self, left, right):
10
+ self.sp().init(left, right, "map")
11
+ def build(self, arr, l_item):
12
+ rst = []
13
+ for _item in arr:
14
+ if not _item.check(is_keyval = 1):
15
+ print(arr)
16
+ print("error _item:", _item)
17
+ raise exp.FormatExp("an not key-val item find in map", _item.pos, _item.val)
18
+ rst.append(_item.val)
19
+ maps = {k[0]:k[1] for k in rst}
20
+ return item.DealItem(maps, l_item.pos, self.id(), is_val = 1, is_map = 1)
21
+
22
+ pass
@@ -0,0 +1,22 @@
1
+ from .. import base
2
+
3
+
4
+ class PrevNextDeal(base.BaseDeal):
5
+ """
6
+ 读取下一个字符放缓存里,应放最低优先级
7
+ """
8
+ def prev(self, buffer, queue, pos):
9
+ c = buffer.read(1,1)
10
+ if c is None or len(c)==0:
11
+ return False
12
+ buffer.add(c)
13
+ #pos.update(c)
14
+ return True
15
+ def deal(self, queue, stack):
16
+ if len(queue)==0:
17
+ return False
18
+ obj = queue.pop(0)
19
+ stack.append(obj)
20
+ return True
21
+
22
+ pass
@@ -0,0 +1,37 @@
1
+ from .. import base
2
+ from .. import item
3
+ from .. import exp
4
+ from . import lr
5
+ import re
6
+ class ValDeal(base.BaseDeal):
7
+ """
8
+ 正则表达式匹配
9
+ """
10
+ def init(self, pt, fc):
11
+ st = self.like("^", pt)
12
+ ed = self.like("$", pt)
13
+ if pt[0]!=st:
14
+ pt = st+pt
15
+ if pt[-1]!=ed:
16
+ pt = pt+ed
17
+ self.pt = pt
18
+ self.fc = fc
19
+ def deal(self, queue, stack):
20
+ if len(queue)==0:
21
+ return False
22
+ _item = queue[0]
23
+ if not _item.check(is_val=1, type = None):
24
+ return False
25
+ val = _item.val
26
+ if type(val) not in [bytes, str]:
27
+ return False
28
+ pt = self.like(self.pt, val)
29
+ if re.match(pt, val) is None:
30
+ return False
31
+ val = self.fc(val)
32
+ queue.pop(0)
33
+ out_item = item.DealItem(val, _item.pos, self.id(), is_val = 1)
34
+ stack.append(out_item)
35
+ return True
36
+
37
+ pass
@@ -0,0 +1,35 @@
1
+ from .. import base
2
+ from .. import item
3
+ from .. import exp
4
+ from . import spt
5
+ class SetDeal(spt.PrevSptDeal):
6
+ """
7
+ Map里的key-val读取
8
+ """
9
+ def init(self, spt):
10
+ self.sp().init(spt, True)
11
+ def deal(self, queue, stack):
12
+ if len(stack)<3:
13
+ return False
14
+ if not stack[-1].check(is_val=1):
15
+ return False
16
+ if not stack[-3].check(is_val=1):
17
+ return False
18
+ if not stack[-2].check(type=self.id()):
19
+ return False
20
+ if stack[-2].check(is_keyval=1):
21
+ return False
22
+ val = stack.pop(-1)
23
+ spt = stack.pop(-1)
24
+ key = stack.pop(-1)
25
+ if not key.check(is_val=1):
26
+ print("key:", key)
27
+ raise exp.FormatExp("not an usable key in key-val paris", key.pos, key.val)
28
+ if not val.check(is_val=1):
29
+ print("vak:", val)
30
+ raise exp.FormatExp("not an usable val in key-val paris", val.pos, val.val)
31
+ rst = [key.val, val.val]
32
+ stack.append(item.DealItem(rst, key.pos, self.id(), is_keyval = 1))
33
+ return True
34
+
35
+ pass
@@ -0,0 +1,19 @@
1
+ from .. import base
2
+
3
+
4
+ class PrevSpcDeal(base.BaseDeal):
5
+ """
6
+ 去掉左空格
7
+ """
8
+ def prev(self, buffer, queue, pos):
9
+ if buffer.size()>0:
10
+ return False
11
+ c = buffer.read()
12
+ if len(c)==0:
13
+ return False
14
+ if len(c.strip())==0:
15
+ buffer.pop_read()
16
+ return True
17
+ return False
18
+
19
+ pass
@@ -0,0 +1,39 @@
1
+ from .. import base
2
+ from .. import item
3
+
4
+ class PrevSptDeal(base.BaseDeal):
5
+ """
6
+ 分隔符,有分隔符后将缓存的数据当作字符串
7
+ """
8
+ def init(self, spt, allow_empty = False):
9
+ self.spt = spt
10
+ self.allow_empty = allow_empty
11
+ self.l = len(spt)
12
+ def prev(self, buffer, queue, pos):
13
+ c = buffer.read(self.l)
14
+ if not self.same(c, self.spt):
15
+ return False
16
+ buffer.pop_read(self.l)
17
+ data = buffer.full()
18
+ buffer.clean()
19
+ crr = pos.get()
20
+ pos.update(data)
21
+ pos.update(c)
22
+ data = data.strip()
23
+ if len(data)==0 and not self.allow_empty:
24
+ return True
25
+ if len(data)==0:
26
+ if len(queue)>0 and queue[-1].check(is_val = 1):
27
+ return True
28
+ obj = item.PrevItem(data, crr, is_val = 1, src='spt')
29
+ queue.append(obj)
30
+ queue.append(item.PrevItem(self.spt, pos.get(), self.id(), src='spt', allow_empty = self.allow_empty))
31
+ return True
32
+ def deal(self, queue, stack):
33
+ bl = False
34
+ while len(queue)>0 and queue[0].check(type = self.id()):
35
+ queue.pop(0)
36
+ bl = True
37
+ return bl
38
+
39
+ pass
@@ -0,0 +1,72 @@
1
+ from .. import base
2
+ from .. import item
3
+ from .. import exp
4
+ import json
5
+ class PrevStrDeal(base.BaseDeal):
6
+ def init(self, left = '"', right= '"', single_line = False, note = False, translate = False):
7
+ self.left = left
8
+ self.right = right
9
+ self.ll = len(left)
10
+ self.lr = len(right)
11
+ self.single_line = single_line
12
+ self.note = note
13
+ self.translate = translate
14
+ def do_translate(self, s):
15
+ """
16
+ 取巧直接调用json
17
+ """
18
+ qt = self.like('"',s)
19
+ ql = self.like("\\", s)
20
+ et = self.like("\n", s)
21
+ s = s.replace(qt, ql+qt)
22
+ arr = s.split(et)
23
+ outs = [json.loads(qt+k+qt) for k in arr]
24
+ outs = et.join(outs)
25
+ return outs
26
+ def prev(self, buffer, queue, pos):
27
+ cl = buffer.read(self.ll)
28
+ if not self.same(self.left, cl):
29
+ return False
30
+ buffer.pop_read(self.ll)
31
+ rm = buffer.full()
32
+ rm_pos = pos.get()
33
+ if len(rm.strip())>0 and not self.note:
34
+ print("left:", self.left, rm)
35
+ raise exp.FormatExp("unexcept char before string", pos.get(), rm)
36
+ pos.update(rm)
37
+ pos.update(cl)
38
+ buffer.clean()
39
+ tmp = cl[:0]
40
+ ctmp = tmp[:0]
41
+ while True:
42
+ if self.same(self.right, ctmp[-self.lr:]):
43
+ break
44
+ c = buffer.read(1,1)
45
+ if len(c)==0:
46
+ pos.update(tmp)
47
+ raise exp.FormatExp("unexcept file end while reading string", pos.get())
48
+ tmp += c
49
+ if self.same("\\", c) and self.translate:
50
+ c = buffer.read(1,1)
51
+ if len(c)==0:
52
+ pos.update(tmp)
53
+ raise exp.FormatExp("unexcept file end while reading string", pos.get())
54
+ tmp += c
55
+ continue
56
+ ctmp+=c
57
+ xtmp = tmp[:-self.lr]
58
+ if not self.note and self.single_line and xtmp.find(self.like("\n", xtmp))>=0:
59
+ print("left:",self.left, "right:", self.right)
60
+ raise exp.FormatExp("contain enter in single line string", pos.get(), tmp)
61
+ if self.translate:
62
+ xtmp = self.do_translate(xtmp)
63
+ curr_pos = pos.get()
64
+ pos.update(tmp)
65
+ if self.note:
66
+ if len(rm)>0:
67
+ queue.append(item.PrevItem(rm, rm_pos, is_val = 1, src='str'))
68
+ return True
69
+ queue.append(item.PrevItem(xtmp, curr_pos, self.id(), is_val = 1, src='str'))
70
+ return True
71
+
72
+ pass
@@ -0,0 +1,12 @@
1
+ '''
2
+ 格式化报错
3
+ '''
4
+ class FormatExp(Exception):
5
+ def __init__(self, err, data, s = ""):
6
+ if len(s)==0:
7
+ errs = "Error: {err}, line: {line}, index: {index}".format(err = err, line = data[0], index = data[1])
8
+ else:
9
+ errs = "Error: {err}, line: {line}, index: {index}, content: [{s}]".format(err = err, line = data[0], index = data[1], s = s)
10
+ super(FormatExp, self).__init__(errs)
11
+
12
+ pass
@@ -0,0 +1,48 @@
1
+
2
+ '''
3
+ 数据封装类
4
+ val是数据(字符)值
5
+ pos是字符在文件里的位置(第几行第几列)
6
+ remain和type?
7
+ '''
8
+ class PrevItem:
9
+ def __str__(self):
10
+ return "<prev_item val={val}, type = {type}, pos = {pos}, maps={maps}>".format(val = str(self.val), type = str(self.type), pos = str(self.pos), maps=self._maps)
11
+ def __repr__(self):
12
+ return str(self)
13
+ def none(self, **maps):
14
+ for k in maps:
15
+ v = maps[k]
16
+ if self.maps(k)==v:
17
+ return False
18
+ return True
19
+ def any(self, **maps):
20
+ for k in maps:
21
+ v = maps[k]
22
+ if self.maps(k)==v:
23
+ return True
24
+ return False
25
+ def check(self, **maps):
26
+ for k in maps:
27
+ v = maps[k]
28
+ if self.maps(k)!=v:
29
+ return False
30
+ return True
31
+ def maps(self, key):
32
+ if key not in self._maps:
33
+ if key == 'type':
34
+ return self.type
35
+ return None
36
+ return self._maps[key]
37
+ def __init__(self, val, pos, type = None, remain=None, **maps):
38
+ self.val= val
39
+ self.pos= pos
40
+ self.remain= remain
41
+ self._maps = maps
42
+ self.type = type
43
+
44
+ pass
45
+ class DealItem(PrevItem):
46
+ def __str__(self):
47
+ return "<deal_item val={val}, type = {type}, pos = {pos}, maps={maps}>".format(val = str(self.val), type = str(self.type), pos = str(self.pos), maps=self._maps)
48
+