byzh-core 0.0.1__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.
@@ -0,0 +1,321 @@
1
+ import copy
2
+ import math
3
+ import os
4
+ from pathlib import Path
5
+ from typing import List, Tuple, Union
6
+ Seq = Union[List, Tuple]
7
+ try:
8
+ from wcwidth import wcswidth
9
+ except ImportError:
10
+ raise ImportError("[table] 请先安装wcwidth库: pip install wcwidth")
11
+
12
+ class MyDict:
13
+ def __init__(self, init_dict = None):
14
+ self.dict = dict()
15
+ if type(init_dict) is dict:
16
+ self.dict = init_dict.copy()
17
+ if type(init_dict) is MyDict:
18
+ self.dict = init_dict.dict.copy()
19
+
20
+
21
+ def update(self, other_dict):
22
+ self.dict.update(other_dict)
23
+
24
+ def items(self):
25
+ return self.dict.items()
26
+ def keys(self):
27
+ return self.dict.keys()
28
+ def values(self):
29
+ return self.dict.values()
30
+ def copy(self):
31
+ return MyDict(self.dict.copy())
32
+ def __getitem__(self, item):
33
+ return self.dict[str(item)]
34
+
35
+ def __setitem__(self, key, value):
36
+ key, value = str(key), str(value)
37
+
38
+ if key not in self.dict.keys():
39
+ self.dict.update({key: ''})
40
+
41
+ self.dict[key] = value
42
+
43
+ class BAutoTable:
44
+ def __init__(self, x_name='x', y_name='y'):
45
+ self.x_sidebars = []
46
+ self.y_sidebars = []
47
+ self.x_name = x_name
48
+ self.y_name = y_name
49
+ self.dict = dict()
50
+ self._widths = dict()
51
+
52
+ def set(self, x_sidebar, y_sidebar, content):
53
+ x_sidebar, y_sidebar, content = str(x_sidebar), str(y_sidebar), str(content)
54
+ self[x_sidebar][y_sidebar] = str(content)
55
+
56
+ def get_str(self, x_sidebar, y_sidebar):
57
+ return self[x_sidebar][y_sidebar]
58
+ def get_int(self, x_sidebar, y_sidebar):
59
+ return int(self[x_sidebar][y_sidebar])
60
+ def get_float(self, x_sidebar, y_sidebar):
61
+ return float(self[x_sidebar][y_sidebar])
62
+ def get_bool(self, x_sidebar, y_sidebar):
63
+ temp = self[x_sidebar][y_sidebar]
64
+ if temp == "True" or temp == "1":
65
+ return True
66
+ else:
67
+ return False
68
+ def items(self):
69
+ '''
70
+ (key1, key2, value)
71
+ '''
72
+ result = [(x, y, self.dict[x][y]) for x in self.x_sidebars for y in self.y_sidebars]
73
+ return result
74
+ def copy_row(self, old_row:str, new_row:str):
75
+ old_row, new_row = str(old_row), str(new_row)
76
+ self[new_row] = self[old_row]
77
+ def read_txt(self, path):
78
+ with open(path, 'r') as f:
79
+ lines = f.readlines()
80
+ lines = [x.strip() for x in lines if x.startswith('|')]
81
+
82
+ temp = []
83
+ for string in lines:
84
+ elements = string.split('|')[1:-1]
85
+ elements = [x.strip() for x in elements]
86
+ temp.append(elements)
87
+
88
+ x_name, y_name = temp[0][0].split(' \\ ') if ('\\' in temp[0][0]) else ("x", "y")
89
+ x_keys = [var[0] for var in temp[1:]]
90
+ y_keys = temp[0][1:]
91
+
92
+ self.x_sidebars = []
93
+ self.y_sidebars = []
94
+ self.x_name = x_name
95
+ self.y_name = y_name
96
+ self.dict = dict()
97
+ self._widths = dict()
98
+
99
+ for i, x_element in enumerate(x_keys):
100
+ y_dict = MyDict()
101
+ for j, y_element in enumerate(y_keys):
102
+ y_dict.update({y_element: temp[i+1][j+1]})
103
+ self.dict.update({x_element: y_dict})
104
+ self._update_sidebars()
105
+
106
+ def to_txt(self, path):
107
+ '''
108
+ 将表格内容写入文件
109
+ :param path:
110
+ :return:
111
+ '''
112
+ dir = Path(path).resolve().parent
113
+ os.makedirs(dir, exist_ok=True)
114
+ with open(path, 'w') as f:
115
+ f.write(self.get_table_by_str())
116
+
117
+ def update_txt(self, path):
118
+ '''
119
+ 更新表格内容\n
120
+ 如果文件不存在,则创建文件
121
+ :param path:
122
+ :return:
123
+ '''
124
+ # 是否存在该文件
125
+ if not os.path.exists(path):
126
+ self.to_txt(path)
127
+ else:
128
+ new_dict = self.dict
129
+ self.read_txt(path)
130
+ origin_dict = self.dict
131
+ self.dict = self._merge_2d_dicts(origin_dict, new_dict)
132
+ self._update_sidebars()
133
+
134
+ self.to_txt(path)
135
+
136
+
137
+
138
+ def get_table_by_strs(self) -> List[str]:
139
+ results = self._create_prefix()
140
+
141
+ self._update_widths()
142
+
143
+ str_dash = ''
144
+ str_head = ''
145
+ for y in self.y_sidebars:
146
+ pre_space, suf_space = self._get_prefix_suffix(y, self._widths[y], ' ')
147
+ pre_dash, suf_dash = self._get_prefix_suffix('-', self._widths[y], '-')
148
+ str_head += ' ' + pre_space + y + suf_space + ' |'
149
+ str_dash += '-' + pre_dash + '-' + suf_dash + '-+'
150
+ results[0] += str_dash
151
+ results[1] += str_head
152
+ results[2] += str_dash
153
+
154
+ offset = 3
155
+ for index, y_dicts in enumerate(self.dict.values()):
156
+ for key in self.y_sidebars:
157
+ value = y_dicts[key] if key in y_dicts.keys() else ''
158
+ pre_space, suf_space = self._get_prefix_suffix(value, self._widths[key], ' ')
159
+ str_content = ' ' + pre_space + value + suf_space + ' |'
160
+ results[index+offset] += str_content
161
+
162
+ results[-1] += str_dash
163
+
164
+ return results
165
+
166
+ def get_table_by_str(self) -> str:
167
+ result = ""
168
+ strs = self.get_table_by_strs()
169
+ for x in strs[:-1]:
170
+ result += x + '\n'
171
+ result += strs[-1]
172
+
173
+ return result
174
+ def print_table(self):
175
+ print(self.get_table_by_str())
176
+
177
+ def _merge_2d_dicts(self, origin_dict, new_dict):
178
+ """
179
+ 合并两个二维字典。
180
+ 如果两个字典的相同键存在重叠的子键,则 new_dict 的值覆盖 origin_dict。
181
+ """
182
+ merged_dict = {key: value.copy() for key, value in origin_dict.items()} # 复制 origin_dict 避免修改原数据
183
+ for key, sub_dict in new_dict.items():
184
+ if key in merged_dict.keys():
185
+ merged_dict[key].update(sub_dict) # 合并子字典
186
+ else:
187
+ merged_dict[key] = sub_dict # 直接添加新键
188
+
189
+ return merged_dict
190
+ def _update_sidebars(self):
191
+ self.x_sidebars = list(self.dict.keys())
192
+
193
+ temp = []
194
+ for dict_y in self.dict.values():
195
+ for key in dict_y.keys():
196
+ if key not in temp:
197
+ temp.append(key)
198
+ self.y_sidebars = temp
199
+
200
+ def _create_prefix(self):
201
+ '''
202
+ 得到
203
+ +-------+
204
+ | x \ y |
205
+ +-------+
206
+ | 1 |
207
+ | 2 |
208
+ | 3 |
209
+ +-------+
210
+ '''
211
+ results = []
212
+
213
+ title = self.x_name + " \ " + self.y_name
214
+ self._update_sidebars()
215
+ n = self._get_maxlength_from_list(self.x_sidebars)
216
+ length = max(n, self._get_width(title))
217
+
218
+ pre_dash, suf_dash = self._get_prefix_suffix("-", length, '-')
219
+ str_dash = "+-" + pre_dash + "-" + suf_dash + "-+"
220
+ results.append(str_dash)
221
+
222
+ pre_space, suf_space = self._get_prefix_suffix(title, length, ' ')
223
+ str_index = "| " + pre_space + title + suf_space + " |"
224
+ results.append(str_index)
225
+ results.append(str_dash)
226
+
227
+ for x in self.x_sidebars:
228
+ pre_space, suf_space = self._get_prefix_suffix(x, length, ' ')
229
+ str_number = "| " + pre_space + x + suf_space + " |"
230
+ results.append(str_number)
231
+ results.append(str_dash)
232
+
233
+ return results
234
+
235
+ def _get_prefix_suffix(self, string, length, charactor=' '):
236
+ prefix = ''
237
+ suffix = ''
238
+ str_len = self._get_width(string)
239
+
240
+ delta = length - str_len
241
+ if delta < 0:
242
+ assert "string的宽度比length宽"
243
+ elif delta == 0:
244
+ pass
245
+ else:
246
+ prefix = charactor * math.floor(delta / 2)
247
+ suffix = charactor * math.ceil(delta / 2)
248
+
249
+ return prefix, suffix
250
+
251
+ def _get_maxlength_from_list(self, lst: List[str]) -> int:
252
+ temp = [self._get_width(x) for x in lst]
253
+ if len(temp) == 0:
254
+ return 0
255
+ else:
256
+ return max(temp)
257
+
258
+ def _update_widths(self):
259
+ temp = {key: self._get_width(key) for key in self.y_sidebars}
260
+
261
+ # for dict_y in self.dict.values():
262
+ # for key, value in dict_y.items():
263
+ # width = self._get_width(value)
264
+ # if width > temp[key]:
265
+ # temp[key] = width
266
+
267
+ matrix = self._get_width_matrix()
268
+ for i in range(len(matrix)):
269
+ for j in range(len(matrix[0])):
270
+ if matrix[i][j] > temp[self.y_sidebars[j]]:
271
+ temp[self.y_sidebars[j]] = matrix[i][j]
272
+
273
+ self._widths = temp
274
+ def _get_width_matrix(self):
275
+ results = [[0 for _ in self.y_sidebars] for _ in self.x_sidebars]
276
+ for x, dict_y in self.dict.items():
277
+ for y, value in dict_y.items():
278
+ results[self.x_sidebars.index(x)][self.y_sidebars.index(y)] = self._get_width(value)
279
+ return results
280
+
281
+ def __repr__(self):
282
+ print(self._widths)
283
+ def _get_width(self, string):
284
+ return wcswidth(string)
285
+
286
+ def __len__(self):
287
+ return len(self.x_sidebars) * len(self.y_sidebars)
288
+ def __contains__(self, item):
289
+ for x in self.x_sidebars:
290
+ for y in self.y_sidebars:
291
+ if str(item) == self.dict[x][y]:
292
+ return True
293
+ return False
294
+ def __str__(self):
295
+ return self.get_table_by_str()
296
+
297
+ def __getitem__(self, index):
298
+ index = str(index)
299
+
300
+ if index not in self.dict.keys():
301
+ self.dict.update({index: MyDict()})
302
+ self._update_sidebars()
303
+ return self.dict[index]
304
+
305
+ return self.dict[index]
306
+ def __setitem__(self, index, value:MyDict|dict):
307
+ index, value = str(index), MyDict(value)
308
+ self.dict.update({index: value})
309
+
310
+ if __name__ == '__main__':
311
+ my_table = BAutoTable("x", "y")
312
+
313
+ my_table[1][3] = 123
314
+ my_table[2][2] = 123
315
+ my_table["awa"]["12133"] = 123
316
+ my_table.copy_row('awa', 'qwq')
317
+ my_table['qwq'][12133] = 333
318
+
319
+ # my_table.read_txt(r'E:\byzh_workingplace\byzh-rc-to-pypi\awa.txt')
320
+ print(my_table)
321
+ repr(my_table)
@@ -0,0 +1,175 @@
1
+ import copy
2
+ import math
3
+ from typing import List, Tuple, Union
4
+ Seq = Union[List, Tuple]
5
+ try:
6
+ from wcwidth import wcswidth
7
+ except ImportError:
8
+ print("[text table] 请先安装wcwidth库: pip install wcwidth")
9
+
10
+ class B_RowTable:
11
+ def __init__(self, head: Seq):
12
+ self.head = self._seq2strlist(head)
13
+ self.rows = []
14
+ self._widths = []
15
+ self._update_widths(self.head)
16
+
17
+ def append(self, sequence: Seq):
18
+ assert len(sequence) == len(self.head), "添加的 序列元素个数 与 head元素个数 不一致"
19
+ self.rows.append(self._seq2strlist(sequence))
20
+ def insert(self, index, sequence: Seq):
21
+ assert len(sequence) == len(self.head), "插入的 序列元素个数 与 head元素个数 不一致"
22
+ self.rows.insert(index, self._seq2strlist(sequence))
23
+ def remove(self, sequence: Seq):
24
+ self.rows.remove(self._seq2strlist(sequence))
25
+ def pop(self, index=-1):
26
+ return self.rows.pop(index)
27
+
28
+ def get_table_by_strs(self) -> List[str]:
29
+ results = self._create_prefix()
30
+
31
+ for x in self.rows:
32
+ self._update_widths(x)
33
+
34
+ str_dash = ''
35
+ str_head = ''
36
+ for i, x in enumerate(self.head):
37
+ pre_space, suf_space = self._get_prefix_suffix(x, self._widths[i], ' ')
38
+ pre_dash, suf_dash = self._get_prefix_suffix('-', self._widths[i], '-')
39
+ str_head += ' ' + pre_space + x + suf_space + ' |'
40
+ str_dash += '-' + pre_dash + '-' + suf_dash + '-+'
41
+ results[0] += str_dash
42
+ results[1] += str_head
43
+ results[2] += str_dash
44
+
45
+ offset = 3
46
+ for i, row in enumerate(self.rows):
47
+ for j, x in enumerate(row):
48
+ pre_space, suf_space = self._get_prefix_suffix(x, self._widths[j], ' ')
49
+ str_content = ' ' + pre_space + x + suf_space + ' |'
50
+ results[i+offset] += str_content
51
+
52
+ results[-1] += str_dash
53
+
54
+ return results
55
+
56
+ def get_table_by_str(self) -> str:
57
+ result = ""
58
+ strs = self.get_table_by_strs()
59
+ for x in strs[:-1]:
60
+ result += x + '\n'
61
+ result += strs[-1]
62
+
63
+ return result
64
+
65
+ def print_table(self):
66
+ print(self.get_table_by_str())
67
+
68
+ def _create_prefix(self):
69
+ '''
70
+ 得到
71
+ +-----+
72
+ | num |
73
+ +-----+
74
+ | 1 |
75
+ | 2 |
76
+ | 3 |
77
+ +-----+
78
+ '''
79
+ results = []
80
+ # 编号的位数
81
+ n = self._get_width(str(len(self.rows)))
82
+ length = max(n, self._get_width("index"))
83
+
84
+ pre_dash, suf_dash = self._get_prefix_suffix("-", length, '-')
85
+ str_dash = "+-" + pre_dash + "-" + suf_dash + "-+"
86
+ results.append(str_dash)
87
+
88
+ pre_space, suf_space = self._get_prefix_suffix("index", length, ' ')
89
+ str_index = "| " + pre_space + "index" + suf_space + " |"
90
+ results.append(str_index)
91
+ results.append(str_dash)
92
+
93
+ for i in range(len(self.rows)):
94
+ number = str(i)
95
+ pre_space, suf_space = self._get_prefix_suffix(number, length, ' ')
96
+ str_number = "| " + pre_space + number + suf_space + " |"
97
+ results.append(str_number)
98
+ results.append(str_dash)
99
+
100
+ return results
101
+
102
+ def _get_prefix_suffix(self, string, length, charactor=' '):
103
+ prefix = ''
104
+ suffix = ''
105
+ str_len = self._get_width(string)
106
+
107
+ delta = length - str_len
108
+ if delta < 0:
109
+ assert "string的宽度比length宽"
110
+ elif delta == 0:
111
+ pass
112
+ else:
113
+ prefix = charactor * math.floor(delta / 2)
114
+ suffix = charactor * math.ceil(delta / 2)
115
+
116
+ return prefix, suffix
117
+
118
+ def _update_widths(self, seq):
119
+ temps = []
120
+ for x in seq:
121
+ temps.append(self._get_width(x))
122
+
123
+ if len(self._widths) == 0:
124
+ self._widths = temps
125
+ else:
126
+ for i, x in enumerate(temps):
127
+ if x > self._widths[i]:
128
+ self._widths[i] = x
129
+
130
+ def _seq2strlist(self, seq):
131
+ seq = copy.deepcopy(list(seq))
132
+ for i, x in enumerate(seq):
133
+ seq[i] = str(x)
134
+
135
+ return seq
136
+
137
+ def _get_width(self, string):
138
+ return wcswidth(string)
139
+
140
+ def __len__(self):
141
+ return len(self.rows)
142
+ def __str__(self):
143
+ return self.get_table_by_str()
144
+ def __getitem__(self, index):
145
+ return self.rows[index]
146
+ def __setitem__(self, index, value):
147
+ self.rows[index] = self._seq2strlist(value)
148
+ def __contains__(self, item):
149
+ for row in self.rows:
150
+ for x in row:
151
+ if str(item) == x:
152
+ return True
153
+ return False
154
+
155
+ if __name__ == '__main__':
156
+ my_table = B_RowTable(['云编号', '名称', 'IP地址', 'aaaabbbbcccc'])
157
+ my_table.append(["server01", "服务器01", "172.16.0.1", 'aacc'])
158
+ my_table.append(["server02", "服务器02", "172.16.0.2", 'aacc'])
159
+ my_table.append(["server03", "服务器03", "172.16.0.3", 'aacc'])
160
+ my_table.append(["server04", "服务器04", "172.16.0.4", 'aacc'])
161
+ my_table.append(["server05", "服务器05", "172.16.0.5", 'aacc'])
162
+ my_table.append(["server06", "服务器06", "172.16.0.6", 'aacc'])
163
+ my_table.append(["server07", "服务器07", "172.16.0.7", 'aacc'])
164
+ my_table.append(["server08", "服务器08", "172.16.0.8", 'aacc'])
165
+ my_table.append(["server09", "服务器09", "172.16.0.9", 'aacc'])
166
+ my_table.append(["server10", "服务器10", "172.16.0.0", 'aacc'])
167
+ my_table.append(["server11", "服务器11", "172.16.0.1", 'aacc'])
168
+
169
+ my_table.remove(["server08", "服务器08", "172.16.0.8", 'aacc'])
170
+
171
+ my_table[4] = ["server99", "服务器99", "172.16.0.9", '99999']
172
+ print(my_table)
173
+ print(len(my_table))
174
+
175
+ print("服务器07" in my_table)
@@ -0,0 +1,211 @@
1
+ import copy
2
+ import math
3
+ from typing import List, Tuple, Union
4
+ Seq = Union[List, Tuple]
5
+ try:
6
+ from wcwidth import wcswidth
7
+ except ImportError:
8
+ print("[text table] 请先安装wcwidth库: pip install wcwidth")
9
+
10
+ class MyDict:
11
+ def __init__(self, init_dict:dict|None = None):
12
+ self.dict = init_dict if init_dict is not None else dict()
13
+
14
+ def update(self, other_dict):
15
+ self.dict.update(other_dict)
16
+
17
+ def items(self):
18
+ return self.dict.items()
19
+ def keys(self):
20
+ return self.dict.keys()
21
+ def values(self):
22
+ return self.dict.values()
23
+
24
+ def __getitem__(self, item):
25
+ return self.dict[str(item)]
26
+
27
+ def __setitem__(self, key, value):
28
+ self.dict[str(key)] = value
29
+
30
+ class B_XYTable:
31
+ def __init__(self, x_name, y_name, x_sidebars=[], y_sidebars=[]):
32
+ self.x_sidebars = self._seq2strlist(x_sidebars)
33
+ self.y_sidebars = self._seq2strlist(y_sidebars)
34
+ self.x_name = x_name
35
+ self.y_name = y_name
36
+ self.dict = self._create_dict(self.x_sidebars, self.y_sidebars)
37
+ self._widths = {x: 0 for x in self.y_sidebars}
38
+ self._update_widths(MyDict({y: y for y in self.y_sidebars}))
39
+
40
+ def set(self, x_sidebar, y_sidebar, content):
41
+ x_sidebar, y_sidebar, content = str(x_sidebar), str(y_sidebar), str(content)
42
+ assert x_sidebar in self.dict.keys(), "x_sidebar 与 不是指定好的属性"
43
+ assert y_sidebar in self.dict[x_sidebar].keys(), "y_sidebar 与 不是指定好的属性"
44
+ self.dict[x_sidebar][y_sidebar] = str(content)
45
+
46
+ def get(self, x_sidebar, y_sidebar):
47
+ return self.dict[x_sidebar][y_sidebar]
48
+ def items(self):
49
+ '''
50
+ (key1, key2, value)
51
+ '''
52
+ result = [(x, y, self.dict[x][y]) for x in self.x_sidebars for y in self.y_sidebars]
53
+ return result
54
+
55
+ def get_table_by_strs(self) -> List[str]:
56
+ results = self._create_prefix()
57
+
58
+ for x in self.dict.values():
59
+ self._update_widths(x)
60
+
61
+ str_dash = ''
62
+ str_head = ''
63
+ for y in self.y_sidebars:
64
+ pre_space, suf_space = self._get_prefix_suffix(y, self._widths[y], ' ')
65
+ pre_dash, suf_dash = self._get_prefix_suffix('-', self._widths[y], '-')
66
+ str_head += ' ' + pre_space + y + suf_space + ' |'
67
+ str_dash += '-' + pre_dash + '-' + suf_dash + '-+'
68
+ results[0] += str_dash
69
+ results[1] += str_head
70
+ results[2] += str_dash
71
+
72
+ offset = 3
73
+ for index, y_dicts in enumerate(self.dict.values()):
74
+ for key, value in y_dicts.items():
75
+ pre_space, suf_space = self._get_prefix_suffix(value, self._widths[key], ' ')
76
+ str_content = ' ' + pre_space + value + suf_space + ' |'
77
+ results[index+offset] += str_content
78
+
79
+ results[-1] += str_dash
80
+
81
+ return results
82
+
83
+ def get_table_by_str(self) -> str:
84
+ result = ""
85
+ strs = self.get_table_by_strs()
86
+ for x in strs[:-1]:
87
+ result += x + '\n'
88
+ result += strs[-1]
89
+
90
+ return result
91
+ def print_table(self):
92
+ print(self.get_table_by_str())
93
+
94
+ def _create_dict(self, seq1, seq2):
95
+ result = dict()
96
+ for x in seq1:
97
+ temp = MyDict()
98
+ for y in seq2:
99
+ temp.update({y: ''})
100
+ result.update({x: temp})
101
+
102
+ return result
103
+
104
+ def _create_prefix(self):
105
+ '''
106
+ 得到
107
+ +-------+
108
+ | x \ y |
109
+ +-------+
110
+ | 1 |
111
+ | 2 |
112
+ | 3 |
113
+ +-------+
114
+ '''
115
+ results = []
116
+
117
+ title = self.x_name + " \ " + self.y_name
118
+ n = self._get_maxlength_from_list(self.x_sidebars)
119
+ length = max(n, self._get_width(title))
120
+
121
+ pre_dash, suf_dash = self._get_prefix_suffix("-", length, '-')
122
+ str_dash = "+-" + pre_dash + "-" + suf_dash + "-+"
123
+ results.append(str_dash)
124
+
125
+ pre_space, suf_space = self._get_prefix_suffix(title, length, ' ')
126
+ str_index = "| " + pre_space + title + suf_space + " |"
127
+ results.append(str_index)
128
+ results.append(str_dash)
129
+
130
+ for x in self.x_sidebars:
131
+ pre_space, suf_space = self._get_prefix_suffix(x, length, ' ')
132
+ str_number = "| " + pre_space + x + suf_space + " |"
133
+ results.append(str_number)
134
+ results.append(str_dash)
135
+
136
+ return results
137
+
138
+ def _get_prefix_suffix(self, string, length, charactor=' '):
139
+ prefix = ''
140
+ suffix = ''
141
+ str_len = self._get_width(string)
142
+
143
+ delta = length - str_len
144
+ if delta < 0:
145
+ assert "string的宽度比length宽"
146
+ elif delta == 0:
147
+ pass
148
+ else:
149
+ prefix = charactor * math.floor(delta / 2)
150
+ suffix = charactor * math.ceil(delta / 2)
151
+
152
+ return prefix, suffix
153
+
154
+ def _get_maxlength_from_list(self, lst: List[str]) -> int:
155
+ temp = [self._get_width(x) for x in lst]
156
+ if len(temp) == 0:
157
+ return 0
158
+ else:
159
+ return max(temp)
160
+
161
+ def _update_widths(self, new_dict: MyDict):
162
+ temps = copy.deepcopy(self._widths)
163
+ for key, value in new_dict.items():
164
+ temps[key] = self._get_width(value)
165
+
166
+ if len(self._widths) == 0:
167
+ self._widths = temps
168
+ else:
169
+ for key, value in temps.items():
170
+ if value > self._widths[key]:
171
+ self._widths[key] = value
172
+
173
+ def _seq2strlist(self, seq):
174
+ seq = copy.deepcopy(list(seq))
175
+ for i, x in enumerate(seq):
176
+ seq[i] = str(x)
177
+
178
+ return seq
179
+
180
+ def _get_width(self, string):
181
+ return wcswidth(string)
182
+
183
+ def __len__(self):
184
+ return len(self.x_sidebars) * len(self.y_sidebars)
185
+ def __contains__(self, item):
186
+ for x in self.x_sidebars:
187
+ for y in self.y_sidebars:
188
+ if str(item) == self.dict[x][y]:
189
+ return True
190
+ return False
191
+ def __str__(self):
192
+ return self.get_table_by_str()
193
+
194
+ def __getitem__(self, index):
195
+ return self.dict[str(index)]
196
+ def __setitem__(self, index, value):
197
+ self.dict[index] = value
198
+ if __name__ == '__main__':
199
+ my_table = B_XYTable("x", "y", [123, 234], [345, 456])
200
+
201
+ my_table[123]['345'] = 'qwq'
202
+ my_table['123']['456'] = '456'
203
+ my_table.set(234, '345', "awwwa")
204
+ my_table.set('234', '456', "123")
205
+
206
+ print(my_table)
207
+ print(my_table[123][345])
208
+ for key1, key2, value in my_table.items():
209
+ print(key1, key2, value)
210
+
211
+ print('qwq' in my_table)
@@ -0,0 +1,3 @@
1
+ from .cmd import b_run_cmd, b_run_python
2
+
3
+ __all__ = ['b_run_cmd', 'b_run_python']