BCBvcl4pyAPI 0.1.5__tar.gz → 0.1.7__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.
- bcbvcl4pyapi-0.1.7/LICENSE +20 -0
- bcbvcl4pyapi-0.1.7/PKG-INFO +46 -0
- bcbvcl4pyapi-0.1.7/README.md +14 -0
- {bcbvcl4pyapi-0.1.5 → bcbvcl4pyapi-0.1.7}/pyproject.toml +4 -1
- bcbvcl4pyapi-0.1.7/src/BCBvcl4pyAPI/AnsiStringAPI.py +174 -0
- bcbvcl4pyapi-0.1.7/src/BCBvcl4pyAPI/TIniFileAPI.py +107 -0
- bcbvcl4pyapi-0.1.7/src/BCBvcl4pyAPI/TMemoryStream.py +149 -0
- bcbvcl4pyapi-0.1.7/src/BCBvcl4pyAPI/__init__.py +9 -0
- bcbvcl4pyapi-0.1.7/src/BCBvcl4pyAPI.egg-info/PKG-INFO +46 -0
- bcbvcl4pyapi-0.1.7/src/BCBvcl4pyAPI.egg-info/SOURCES.txt +18 -0
- {bcbvcl4pyapi-0.1.5 → bcbvcl4pyapi-0.1.7/src}/BCBvcl4pyAPI.egg-info/top_level.txt +1 -0
- bcbvcl4pyapi-0.1.7/src/Example/PyListTest.py +25 -0
- bcbvcl4pyapi-0.1.7/src/Example/PyListTest2.py +19 -0
- bcbvcl4pyapi-0.1.7/src/Example/TestHyperList.py +38 -0
- bcbvcl4pyapi-0.1.5/BCBvcl4pyAPI/__init__.py +0 -4
- bcbvcl4pyapi-0.1.5/BCBvcl4pyAPI.egg-info/PKG-INFO +0 -13
- bcbvcl4pyapi-0.1.5/BCBvcl4pyAPI.egg-info/SOURCES.txt +0 -11
- bcbvcl4pyapi-0.1.5/PKG-INFO +0 -13
- bcbvcl4pyapi-0.1.5/README.md +0 -4
- {bcbvcl4pyapi-0.1.5 → bcbvcl4pyapi-0.1.7}/setup.cfg +0 -0
- {bcbvcl4pyapi-0.1.5 → bcbvcl4pyapi-0.1.7/src}/BCBvcl4pyAPI/BCBvcl4pyAPI.py +0 -0
- {bcbvcl4pyapi-0.1.5 → bcbvcl4pyapi-0.1.7/src}/BCBvcl4pyAPI/HyperDynamicArrayAPI.py +0 -0
- {bcbvcl4pyapi-0.1.5 → bcbvcl4pyapi-0.1.7/src}/BCBvcl4pyAPI.egg-info/dependency_links.txt +0 -0
- {bcbvcl4pyapi-0.1.5 → bcbvcl4pyapi-0.1.7/src}/BCBvcl4pyAPI.egg-info/requires.txt +0 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright (c) 2025 James Lin
|
|
2
|
+
|
|
3
|
+
All rights reserved.
|
|
4
|
+
|
|
5
|
+
Permission is granted for **personal, educational, or non-commercial use only**.
|
|
6
|
+
You **may NOT**:
|
|
7
|
+
|
|
8
|
+
1. Sell or otherwise commercially exploit this software or any part of it.
|
|
9
|
+
2. Reproduce, distribute, or sublicense this software for commercial purposes.
|
|
10
|
+
3. Modify or create derivative works for commercial purposes without explicit written permission from the copyright holder.
|
|
11
|
+
|
|
12
|
+
You **may**:
|
|
13
|
+
|
|
14
|
+
- Use the software for personal learning, research, or internal company evaluation (non-commercial).
|
|
15
|
+
- Share the software with attribution to the original author, as long as it is not for commercial gain.
|
|
16
|
+
|
|
17
|
+
**Disclaimer:**
|
|
18
|
+
This software is provided "AS IS", without any warranty of any kind, either expressed or implied,
|
|
19
|
+
including but not limited to the warranties of merchantability, fitness for a particular purpose, or non-infringement.
|
|
20
|
+
In no event shall the author be liable for any claim, damages, or other liability arising from, out of, or in connection with the software or its use.
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: BCBvcl4pyAPI
|
|
3
|
+
Version: 0.1.7
|
|
4
|
+
Summary: BCBvcl4pyAPI Python package
|
|
5
|
+
Author-email: James Lin <tylin123@ms27.hinet.net>
|
|
6
|
+
License: Copyright (c) 2025 James Lin
|
|
7
|
+
|
|
8
|
+
All rights reserved.
|
|
9
|
+
|
|
10
|
+
Permission is granted for **personal, educational, or non-commercial use only**.
|
|
11
|
+
You **may NOT**:
|
|
12
|
+
|
|
13
|
+
1. Sell or otherwise commercially exploit this software or any part of it.
|
|
14
|
+
2. Reproduce, distribute, or sublicense this software for commercial purposes.
|
|
15
|
+
3. Modify or create derivative works for commercial purposes without explicit written permission from the copyright holder.
|
|
16
|
+
|
|
17
|
+
You **may**:
|
|
18
|
+
|
|
19
|
+
- Use the software for personal learning, research, or internal company evaluation (non-commercial).
|
|
20
|
+
- Share the software with attribution to the original author, as long as it is not for commercial gain.
|
|
21
|
+
|
|
22
|
+
**Disclaimer:**
|
|
23
|
+
This software is provided "AS IS", without any warranty of any kind, either expressed or implied,
|
|
24
|
+
including but not limited to the warranties of merchantability, fitness for a particular purpose, or non-infringement.
|
|
25
|
+
In no event shall the author be liable for any claim, damages, or other liability arising from, out of, or in connection with the software or its use.
|
|
26
|
+
|
|
27
|
+
Project-URL: Homepage, https://mis.gotech.biz
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
License-File: LICENSE
|
|
30
|
+
Requires-Dist: pymysql
|
|
31
|
+
Dynamic: license-file
|
|
32
|
+
|
|
33
|
+
#BCBvcl4pyAPI
|
|
34
|
+
|
|
35
|
+
## History of version
|
|
36
|
+
Version 0.1.7: 2025/10/09<BR>
|
|
37
|
+
Add the TMemoryStream, TIniFiles class
|
|
38
|
+
|
|
39
|
+
Version 0.1.6: 2025/10/08<BR>
|
|
40
|
+
Add the AnsiString class
|
|
41
|
+
|
|
42
|
+
Version 0.1.5: 2025/09/20<BR>
|
|
43
|
+
Add the HyperDynamicArray class to provide large memory access functionality.<BR>
|
|
44
|
+
|
|
45
|
+
Version 0.1.3: 2025/09/19<BR>
|
|
46
|
+
Mainly fixed the issue where Packages could not be found after an update.<BR>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#BCBvcl4pyAPI
|
|
2
|
+
|
|
3
|
+
## History of version
|
|
4
|
+
Version 0.1.7: 2025/10/09<BR>
|
|
5
|
+
Add the TMemoryStream, TIniFiles class
|
|
6
|
+
|
|
7
|
+
Version 0.1.6: 2025/10/08<BR>
|
|
8
|
+
Add the AnsiString class
|
|
9
|
+
|
|
10
|
+
Version 0.1.5: 2025/09/20<BR>
|
|
11
|
+
Add the HyperDynamicArray class to provide large memory access functionality.<BR>
|
|
12
|
+
|
|
13
|
+
Version 0.1.3: 2025/09/19<BR>
|
|
14
|
+
Mainly fixed the issue where Packages could not be found after an update.<BR>
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "BCBvcl4pyAPI"
|
|
7
|
-
version = "0.1.
|
|
7
|
+
version = "0.1.7"
|
|
8
8
|
description = "BCBvcl4pyAPI Python package"
|
|
9
9
|
authors = [
|
|
10
10
|
{ name="James Lin", email="tylin123@ms27.hinet.net" }
|
|
@@ -17,3 +17,6 @@ dependencies = [
|
|
|
17
17
|
|
|
18
18
|
[project.urls]
|
|
19
19
|
Homepage = "https://mis.gotech.biz"
|
|
20
|
+
|
|
21
|
+
[tools.setuptools.packages.find]
|
|
22
|
+
where = ["src"]
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
class AnsiString:
|
|
2
|
+
def __init__(self, Pms_str: str = '', encoding: str = 'byte'):
|
|
3
|
+
"""
|
|
4
|
+
encoding:
|
|
5
|
+
'byte' -> BCB5 byte模式(中文佔兩個byte)
|
|
6
|
+
'unicode' -> Unicode 字元模式
|
|
7
|
+
"""
|
|
8
|
+
self.encoding = encoding
|
|
9
|
+
self.set(Pms_str)
|
|
10
|
+
|
|
11
|
+
# ---------------------------------------------
|
|
12
|
+
# 改變內容
|
|
13
|
+
# ---------------------------------------------
|
|
14
|
+
def set(self, Pms_str: str):
|
|
15
|
+
if self.encoding == 'byte':
|
|
16
|
+
self._data = Pms_str.encode('big5', errors='replace')
|
|
17
|
+
else:
|
|
18
|
+
self._data = Pms_str.encode('utf-8')
|
|
19
|
+
return self # 支援連鎖呼叫
|
|
20
|
+
|
|
21
|
+
# ---------------------------------------------
|
|
22
|
+
# 轉成 Python str
|
|
23
|
+
# ---------------------------------------------
|
|
24
|
+
def str(self):
|
|
25
|
+
if self.encoding == 'byte':
|
|
26
|
+
return self._data.decode('big5', errors='replace')
|
|
27
|
+
else:
|
|
28
|
+
return self._data.decode('utf-8')
|
|
29
|
+
|
|
30
|
+
def __str__(self):
|
|
31
|
+
return self.str()
|
|
32
|
+
|
|
33
|
+
# ---------------------------------------------
|
|
34
|
+
# 取 C 字串 bytes
|
|
35
|
+
# ---------------------------------------------
|
|
36
|
+
def c_str(self):
|
|
37
|
+
return self._data
|
|
38
|
+
|
|
39
|
+
# ---------------------------------------------
|
|
40
|
+
# 支援索引取單 byte
|
|
41
|
+
# ---------------------------------------------
|
|
42
|
+
def __getitem__(self, index):
|
|
43
|
+
return self._data[index]
|
|
44
|
+
|
|
45
|
+
# ---------------------------------------------
|
|
46
|
+
# SubString
|
|
47
|
+
# mode='byte' / 'unicode'
|
|
48
|
+
# ---------------------------------------------
|
|
49
|
+
def SubString(self, start: int, length: int = None, mode: str = None):
|
|
50
|
+
mode = mode or self.encoding
|
|
51
|
+
if mode == 'unicode':
|
|
52
|
+
s = self.str()
|
|
53
|
+
start -= 1
|
|
54
|
+
if length is None:
|
|
55
|
+
return AnsiString(s[start:], encoding=self.encoding)
|
|
56
|
+
else:
|
|
57
|
+
return AnsiString(s[start:start+length], encoding=self.encoding)
|
|
58
|
+
elif mode == 'byte':
|
|
59
|
+
start -= 1
|
|
60
|
+
if length is None:
|
|
61
|
+
return AnsiString(self._data[start:].decode('big5', errors='replace'), encoding=self.encoding)
|
|
62
|
+
else:
|
|
63
|
+
return AnsiString(self._data[start:start+length].decode('big5', errors='replace'), encoding=self.encoding)
|
|
64
|
+
else:
|
|
65
|
+
raise ValueError("mode must be 'byte' or 'unicode'")
|
|
66
|
+
|
|
67
|
+
# ---------------------------------------------
|
|
68
|
+
# 長度
|
|
69
|
+
# ---------------------------------------------
|
|
70
|
+
def Length(self, mode: str = None):
|
|
71
|
+
mode = mode or self.encoding
|
|
72
|
+
if mode == 'unicode':
|
|
73
|
+
return len(self.str())
|
|
74
|
+
elif mode == 'byte':
|
|
75
|
+
return len(self._data)
|
|
76
|
+
else:
|
|
77
|
+
raise ValueError("mode must be 'byte' or 'unicode'")
|
|
78
|
+
|
|
79
|
+
@staticmethod
|
|
80
|
+
def strlen(Pms_str: str, encoding: str = 'byte'):
|
|
81
|
+
if encoding == 'unicode':
|
|
82
|
+
return len(Pms_str)
|
|
83
|
+
elif encoding == 'byte':
|
|
84
|
+
return len(Pms_str.encode('big5', errors='replace'))
|
|
85
|
+
else:
|
|
86
|
+
raise ValueError("encoding must be 'byte' or 'unicode'")
|
|
87
|
+
|
|
88
|
+
# ---------------------------------------------
|
|
89
|
+
# 常用方法
|
|
90
|
+
# ---------------------------------------------
|
|
91
|
+
def Trim(self):
|
|
92
|
+
return AnsiString(self.str().strip(), encoding=self.encoding)
|
|
93
|
+
|
|
94
|
+
def UpperCase(self):
|
|
95
|
+
return AnsiString(self.str().upper(), encoding=self.encoding)
|
|
96
|
+
|
|
97
|
+
def LowerCase(self):
|
|
98
|
+
return AnsiString(self.str().lower(), encoding=self.encoding)
|
|
99
|
+
|
|
100
|
+
def Pos(self, sub: str):
|
|
101
|
+
idx = self.str().find(sub)
|
|
102
|
+
return idx + 1 if idx >= 0 else 0
|
|
103
|
+
|
|
104
|
+
@staticmethod
|
|
105
|
+
def StringOfChar(char: str, count: int, encoding='byte'):
|
|
106
|
+
return AnsiString(char * count, encoding=encoding)
|
|
107
|
+
|
|
108
|
+
@staticmethod
|
|
109
|
+
def sprintf(fmt: str, *args, encoding='byte'):
|
|
110
|
+
return AnsiString(fmt % args, encoding=encoding)
|
|
111
|
+
|
|
112
|
+
# ---------------------------------------------
|
|
113
|
+
# + 運算子
|
|
114
|
+
# ---------------------------------------------
|
|
115
|
+
def __add__(self, other):
|
|
116
|
+
if isinstance(other, AnsiString):
|
|
117
|
+
combined_str = self.str() + other.str()
|
|
118
|
+
elif isinstance(other, str):
|
|
119
|
+
combined_str = self.str() + other
|
|
120
|
+
else:
|
|
121
|
+
raise TypeError("Can only add AnsiString or str")
|
|
122
|
+
return AnsiString(combined_str, encoding=self.encoding)
|
|
123
|
+
|
|
124
|
+
# ---------------------------------------------
|
|
125
|
+
# += 原地累加
|
|
126
|
+
# ---------------------------------------------
|
|
127
|
+
def __iadd__(self, other):
|
|
128
|
+
if isinstance(other, AnsiString):
|
|
129
|
+
new_str = self.str() + other.str()
|
|
130
|
+
elif isinstance(other, str):
|
|
131
|
+
new_str = self.str() + other
|
|
132
|
+
else:
|
|
133
|
+
raise TypeError("Can only add AnsiString or str")
|
|
134
|
+
if self.encoding == 'byte':
|
|
135
|
+
self._data = new_str.encode('big5', errors='replace')
|
|
136
|
+
else:
|
|
137
|
+
self._data = new_str.encode('utf-8')
|
|
138
|
+
return self
|
|
139
|
+
|
|
140
|
+
# ================================================================================
|
|
141
|
+
if(__name__=="__main__"):
|
|
142
|
+
s = AnsiString(" test--測試1234 ")
|
|
143
|
+
|
|
144
|
+
# 連鎖呼叫
|
|
145
|
+
result = s.Trim().UpperCase().SubString(3,5)
|
|
146
|
+
print(str(result)) # 結果: "ST--測試1"
|
|
147
|
+
|
|
148
|
+
# 改變內容也可以連鎖
|
|
149
|
+
s.set("abc 中文").UpperCase().Trim()
|
|
150
|
+
print(str(s)) # "ABC 中文"
|
|
151
|
+
|
|
152
|
+
# 取長度
|
|
153
|
+
print(s.Length()) # byte 長度
|
|
154
|
+
print(s.Length(mode='unicode')) # 字元長度
|
|
155
|
+
|
|
156
|
+
# 靜態 strlen
|
|
157
|
+
ms_MyStr = "test--測試1234"
|
|
158
|
+
mi_Len = AnsiString.strlen(ms_MyStr, encoding="unicode")
|
|
159
|
+
print("mi_Len unicode:", mi_Len)
|
|
160
|
+
mi_Len_byte = AnsiString.strlen(ms_MyStr, encoding="byte")
|
|
161
|
+
print("mi_Len byte:", mi_Len_byte)
|
|
162
|
+
|
|
163
|
+
# SubString byte/unicode
|
|
164
|
+
print(str(s.SubString(2,3))) # byte模式
|
|
165
|
+
print(str(s.SubString(2,3, mode='unicode'))) # unicode模式
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
s.set(str(ms_MyStr))
|
|
169
|
+
print(s.str()) # "新的字串" -> 大寫 "新的字串"
|
|
170
|
+
print(s.Pos("測"))
|
|
171
|
+
|
|
172
|
+
print(f"[{s}] ----> len1={s.Length()}");
|
|
173
|
+
s+="-->增加字";
|
|
174
|
+
print(f"[{s}] ----> len2={s.Length()}");
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import configparser
|
|
3
|
+
|
|
4
|
+
class TIniFile:
|
|
5
|
+
def __init__(self, FileName: str, Encoding: str = "byte"):
|
|
6
|
+
"""
|
|
7
|
+
Encoding:
|
|
8
|
+
"byte" -> Big5 編碼
|
|
9
|
+
"unicode" -> UTF-8 編碼
|
|
10
|
+
"""
|
|
11
|
+
self.FileName = FileName
|
|
12
|
+
self.Encoding = Encoding.lower()
|
|
13
|
+
self.config = configparser.ConfigParser()
|
|
14
|
+
self.config.optionxform = str # 保留大小寫
|
|
15
|
+
|
|
16
|
+
self._encoding_name = "big5" if self.Encoding == "byte" else "utf-8"
|
|
17
|
+
|
|
18
|
+
if os.path.exists(self.FileName):
|
|
19
|
+
self.config.read(self.FileName, encoding=self._encoding_name)
|
|
20
|
+
|
|
21
|
+
# -----------------------
|
|
22
|
+
# 讀取方法
|
|
23
|
+
# -----------------------
|
|
24
|
+
def ReadString(self, Section: str, Ident: str, Default: str = "") -> str:
|
|
25
|
+
if self.config.has_section(Section) and self.config.has_option(Section, Ident):
|
|
26
|
+
return self.config.get(Section, Ident)
|
|
27
|
+
return Default
|
|
28
|
+
|
|
29
|
+
def ReadInteger(self, Section: str, Ident: str, Default: int = 0) -> int:
|
|
30
|
+
try:
|
|
31
|
+
return int(self.ReadString(Section, Ident, str(Default)))
|
|
32
|
+
except ValueError:
|
|
33
|
+
return Default
|
|
34
|
+
|
|
35
|
+
def ReadFloat(self, Section: str, Ident: str, Default: float = 0.0) -> float:
|
|
36
|
+
try:
|
|
37
|
+
return float(self.ReadString(Section, Ident, str(Default)))
|
|
38
|
+
except ValueError:
|
|
39
|
+
return Default
|
|
40
|
+
|
|
41
|
+
def ReadBool(self, Section: str, Ident: str, Default: bool = False) -> bool:
|
|
42
|
+
val = self.ReadString(Section, Ident, str(Default))
|
|
43
|
+
return val.lower() in ['1', 'true', 'yes']
|
|
44
|
+
|
|
45
|
+
# -----------------------
|
|
46
|
+
# 寫入方法
|
|
47
|
+
# -----------------------
|
|
48
|
+
def WriteString(self, Section: str, Ident: str, Value: str):
|
|
49
|
+
if not self.config.has_section(Section):
|
|
50
|
+
self.config.add_section(Section)
|
|
51
|
+
self.config.set(Section, Ident, Value)
|
|
52
|
+
self._save()
|
|
53
|
+
|
|
54
|
+
def WriteInteger(self, Section: str, Ident: str, Value: int):
|
|
55
|
+
self.WriteString(Section, Ident, str(Value))
|
|
56
|
+
|
|
57
|
+
def WriteFloat(self, Section: str, Ident: str, Value: float):
|
|
58
|
+
self.WriteString(Section, Ident, str(Value))
|
|
59
|
+
|
|
60
|
+
def WriteBool(self, Section: str, Ident: str, Value: bool):
|
|
61
|
+
self.WriteString(Section, Ident, str(int(Value)))
|
|
62
|
+
|
|
63
|
+
# -----------------------
|
|
64
|
+
# 刪除 / 檢查
|
|
65
|
+
# -----------------------
|
|
66
|
+
def DeleteKey(self, Section: str, Ident: str):
|
|
67
|
+
if self.config.has_section(Section):
|
|
68
|
+
self.config.remove_option(Section, Ident)
|
|
69
|
+
self._save()
|
|
70
|
+
|
|
71
|
+
def EraseSection(self, Section: str):
|
|
72
|
+
if self.config.has_section(Section):
|
|
73
|
+
self.config.remove_section(Section)
|
|
74
|
+
self._save()
|
|
75
|
+
|
|
76
|
+
def ValueExists(self, Section: str, Ident: str) -> bool:
|
|
77
|
+
return self.config.has_section(Section) and self.config.has_option(Section, Ident)
|
|
78
|
+
|
|
79
|
+
# -----------------------
|
|
80
|
+
# 內部保存
|
|
81
|
+
# -----------------------
|
|
82
|
+
def _save(self):
|
|
83
|
+
with open(self.FileName, 'w', encoding=self._encoding_name) as f:
|
|
84
|
+
self.config.write(f)
|
|
85
|
+
|
|
86
|
+
# -----------------------
|
|
87
|
+
# 關閉 (可選)
|
|
88
|
+
# -----------------------
|
|
89
|
+
def Close(self):
|
|
90
|
+
self.config = None
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
# ================================================================================
|
|
94
|
+
if(__name__=="__main__"):
|
|
95
|
+
# 預設 Big5
|
|
96
|
+
ini = TIniFile("test.ini")
|
|
97
|
+
# 或者使用 Unicode (UTF-8)
|
|
98
|
+
# ini = TIniFile("test.ini", Encoding="unicode")
|
|
99
|
+
|
|
100
|
+
ini.WriteString("User", "Name", "林大明")
|
|
101
|
+
ini.WriteInteger("User", "Age", 36)
|
|
102
|
+
|
|
103
|
+
name = ini.ReadString("User", "Name", "DefaultName")
|
|
104
|
+
age = ini.ReadInteger("User", "Age", 0)
|
|
105
|
+
|
|
106
|
+
print(name, age)
|
|
107
|
+
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import io
|
|
2
|
+
import os
|
|
3
|
+
import pickle
|
|
4
|
+
|
|
5
|
+
class TStream:
|
|
6
|
+
def __init__(self):
|
|
7
|
+
self._stream = io.BytesIO()
|
|
8
|
+
|
|
9
|
+
# ---- 屬性 ----
|
|
10
|
+
@property
|
|
11
|
+
def Position(self) -> int:
|
|
12
|
+
return self._stream.tell()
|
|
13
|
+
|
|
14
|
+
@Position.setter
|
|
15
|
+
def Position(self, value: int):
|
|
16
|
+
self._stream.seek(value, io.SEEK_SET)
|
|
17
|
+
|
|
18
|
+
@property
|
|
19
|
+
def Size(self) -> int:
|
|
20
|
+
current = self._stream.tell()
|
|
21
|
+
self._stream.seek(0, io.SEEK_END)
|
|
22
|
+
size = self._stream.tell()
|
|
23
|
+
self._stream.seek(current, io.SEEK_SET)
|
|
24
|
+
return size
|
|
25
|
+
|
|
26
|
+
# ---- 基本方法 ----
|
|
27
|
+
def Seek(self, Offset: int, Origin: int = io.SEEK_SET) -> int:
|
|
28
|
+
"""移動資料指標"""
|
|
29
|
+
return self._stream.seek(Offset, Origin)
|
|
30
|
+
|
|
31
|
+
def Read(self, Buffer, Count: int) -> int:
|
|
32
|
+
"""讀取 Count 個位元組到 Buffer"""
|
|
33
|
+
data = self._stream.read(Count)
|
|
34
|
+
if isinstance(Buffer, bytearray):
|
|
35
|
+
Buffer[:len(data)] = data
|
|
36
|
+
return len(data)
|
|
37
|
+
|
|
38
|
+
def Write(self, Buffer, Count: int) -> int:
|
|
39
|
+
"""寫入 Count 個位元組"""
|
|
40
|
+
if isinstance(Buffer, (bytes, bytearray)):
|
|
41
|
+
self._stream.write(Buffer[:Count])
|
|
42
|
+
return Count
|
|
43
|
+
raise TypeError("Buffer must be bytes or bytearray")
|
|
44
|
+
|
|
45
|
+
def ReadBuffer(self, Count: int) -> bytes:
|
|
46
|
+
"""讀取指定長度的 bytes"""
|
|
47
|
+
return self._stream.read(Count)
|
|
48
|
+
|
|
49
|
+
def WriteBuffer(self, Data: bytes):
|
|
50
|
+
"""直接寫入 bytes"""
|
|
51
|
+
self._stream.write(Data)
|
|
52
|
+
|
|
53
|
+
def Clear(self):
|
|
54
|
+
"""清空資料"""
|
|
55
|
+
self._stream = io.BytesIO()
|
|
56
|
+
|
|
57
|
+
def SetSize(self, NewSize: int):
|
|
58
|
+
"""設定串流大小"""
|
|
59
|
+
current = self._stream.tell()
|
|
60
|
+
data = self._stream.getvalue()
|
|
61
|
+
if NewSize < len(data):
|
|
62
|
+
data = data[:NewSize]
|
|
63
|
+
else:
|
|
64
|
+
data += b'\x00' * (NewSize - len(data))
|
|
65
|
+
self._stream = io.BytesIO(data)
|
|
66
|
+
self._stream.seek(min(current, NewSize))
|
|
67
|
+
|
|
68
|
+
def LoadFromFile(self, FileName: str):
|
|
69
|
+
"""從檔案載入"""
|
|
70
|
+
if not os.path.exists(FileName):
|
|
71
|
+
raise FileNotFoundError(FileName)
|
|
72
|
+
with open(FileName, "rb") as f:
|
|
73
|
+
self._stream = io.BytesIO(f.read())
|
|
74
|
+
self._stream.seek(0)
|
|
75
|
+
|
|
76
|
+
def SaveToFile(self, FileName: str):
|
|
77
|
+
"""儲存至檔案"""
|
|
78
|
+
with open(FileName, "wb") as f:
|
|
79
|
+
current = self._stream.tell()
|
|
80
|
+
self._stream.seek(0)
|
|
81
|
+
f.write(self._stream.read())
|
|
82
|
+
self._stream.seek(current)
|
|
83
|
+
|
|
84
|
+
# ---- 擴充:物件序列化 ----
|
|
85
|
+
def WriteObject(self, obj):
|
|
86
|
+
"""序列化並寫入任意 Python 物件(包含 dataclass)"""
|
|
87
|
+
data = pickle.dumps(obj)
|
|
88
|
+
self.Clear()
|
|
89
|
+
self._stream.write(data)
|
|
90
|
+
self._stream.seek(0)
|
|
91
|
+
|
|
92
|
+
def ReadObject(self):
|
|
93
|
+
"""讀取並還原先前 WriteObject() 寫入的 Python 物件"""
|
|
94
|
+
self._stream.seek(0)
|
|
95
|
+
return pickle.loads(self._stream.read())
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
class TMemoryStream(TStream):
|
|
99
|
+
"""模擬 BCB5 的 TMemoryStream"""
|
|
100
|
+
def __init__(self):
|
|
101
|
+
super().__init__()
|
|
102
|
+
|
|
103
|
+
# ================================================================================
|
|
104
|
+
# [使用範例]
|
|
105
|
+
if(__name__=="__main__"):
|
|
106
|
+
from dataclasses import dataclass
|
|
107
|
+
|
|
108
|
+
@dataclass
|
|
109
|
+
class STRU_Employee:
|
|
110
|
+
mi_EMPID: int;
|
|
111
|
+
ms_EMPNAME: str;
|
|
112
|
+
ms_BIRTHDAY: str;
|
|
113
|
+
ms_Weight: float;
|
|
114
|
+
|
|
115
|
+
obj_MemStream: TMemoryStream;
|
|
116
|
+
stru_EMP1 : STRU_Employee;
|
|
117
|
+
stru_EMP2 : STRU_Employee;
|
|
118
|
+
stru_EMP3 : STRU_Employee;
|
|
119
|
+
stru_READ : STRU_Employee;
|
|
120
|
+
|
|
121
|
+
obj_MemStream = TMemoryStream();
|
|
122
|
+
stru_EMP1 = STRU_Employee(0, "劉備", "1998/01/02", 54.23);
|
|
123
|
+
stru_EMP2 = STRU_Employee(1, "關羽", "2026/03/26", 74.74);
|
|
124
|
+
stru_EMP3 = STRU_Employee(2, "張飛", "2028/11/18", 94.39);
|
|
125
|
+
stru_READ = STRU_Employee(-1, "", "", 0.0);
|
|
126
|
+
|
|
127
|
+
obj_MemStream.Clear();
|
|
128
|
+
obj_MemStream.WriteObject(stru_EMP1);
|
|
129
|
+
obj_MemStream.Position = 0;
|
|
130
|
+
obj_MemStream.SaveToFile("emp1.bin");
|
|
131
|
+
|
|
132
|
+
obj_MemStream.Clear();
|
|
133
|
+
obj_MemStream.WriteObject(stru_EMP2);
|
|
134
|
+
obj_MemStream.Position = 0;
|
|
135
|
+
obj_MemStream.SaveToFile("emp2.bin");
|
|
136
|
+
|
|
137
|
+
obj_MemStream.Clear();
|
|
138
|
+
obj_MemStream.WriteObject(stru_EMP3);
|
|
139
|
+
obj_MemStream.Position = 0;
|
|
140
|
+
obj_MemStream.SaveToFile("emp3.bin");
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
obj_MemStream.LoadFromFile("emp2.bin");
|
|
144
|
+
stru_READ = obj_MemStream.ReadObject();
|
|
145
|
+
|
|
146
|
+
print(stru_READ.mi_EMPID);
|
|
147
|
+
print(stru_READ.ms_EMPNAME);
|
|
148
|
+
print(stru_READ.ms_BIRTHDAY);
|
|
149
|
+
print(stru_READ.ms_Weight);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
from .BCBvcl4pyAPI import TStringList, TList, DynamicArray
|
|
2
|
+
from .HyperDynamicArrayAPI import HyperDynamicArray
|
|
3
|
+
from .AnsiStringAPI import AnsiString
|
|
4
|
+
|
|
5
|
+
__all__ = ["TStringList", "TList", "DynamicArray",
|
|
6
|
+
"HyperDynamicArray",
|
|
7
|
+
"AnsiString",
|
|
8
|
+
"TMemoryStream"
|
|
9
|
+
]
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: BCBvcl4pyAPI
|
|
3
|
+
Version: 0.1.7
|
|
4
|
+
Summary: BCBvcl4pyAPI Python package
|
|
5
|
+
Author-email: James Lin <tylin123@ms27.hinet.net>
|
|
6
|
+
License: Copyright (c) 2025 James Lin
|
|
7
|
+
|
|
8
|
+
All rights reserved.
|
|
9
|
+
|
|
10
|
+
Permission is granted for **personal, educational, or non-commercial use only**.
|
|
11
|
+
You **may NOT**:
|
|
12
|
+
|
|
13
|
+
1. Sell or otherwise commercially exploit this software or any part of it.
|
|
14
|
+
2. Reproduce, distribute, or sublicense this software for commercial purposes.
|
|
15
|
+
3. Modify or create derivative works for commercial purposes without explicit written permission from the copyright holder.
|
|
16
|
+
|
|
17
|
+
You **may**:
|
|
18
|
+
|
|
19
|
+
- Use the software for personal learning, research, or internal company evaluation (non-commercial).
|
|
20
|
+
- Share the software with attribution to the original author, as long as it is not for commercial gain.
|
|
21
|
+
|
|
22
|
+
**Disclaimer:**
|
|
23
|
+
This software is provided "AS IS", without any warranty of any kind, either expressed or implied,
|
|
24
|
+
including but not limited to the warranties of merchantability, fitness for a particular purpose, or non-infringement.
|
|
25
|
+
In no event shall the author be liable for any claim, damages, or other liability arising from, out of, or in connection with the software or its use.
|
|
26
|
+
|
|
27
|
+
Project-URL: Homepage, https://mis.gotech.biz
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
License-File: LICENSE
|
|
30
|
+
Requires-Dist: pymysql
|
|
31
|
+
Dynamic: license-file
|
|
32
|
+
|
|
33
|
+
#BCBvcl4pyAPI
|
|
34
|
+
|
|
35
|
+
## History of version
|
|
36
|
+
Version 0.1.7: 2025/10/09<BR>
|
|
37
|
+
Add the TMemoryStream, TIniFiles class
|
|
38
|
+
|
|
39
|
+
Version 0.1.6: 2025/10/08<BR>
|
|
40
|
+
Add the AnsiString class
|
|
41
|
+
|
|
42
|
+
Version 0.1.5: 2025/09/20<BR>
|
|
43
|
+
Add the HyperDynamicArray class to provide large memory access functionality.<BR>
|
|
44
|
+
|
|
45
|
+
Version 0.1.3: 2025/09/19<BR>
|
|
46
|
+
Mainly fixed the issue where Packages could not be found after an update.<BR>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
setup.cfg
|
|
5
|
+
src/BCBvcl4pyAPI/AnsiStringAPI.py
|
|
6
|
+
src/BCBvcl4pyAPI/BCBvcl4pyAPI.py
|
|
7
|
+
src/BCBvcl4pyAPI/HyperDynamicArrayAPI.py
|
|
8
|
+
src/BCBvcl4pyAPI/TIniFileAPI.py
|
|
9
|
+
src/BCBvcl4pyAPI/TMemoryStream.py
|
|
10
|
+
src/BCBvcl4pyAPI/__init__.py
|
|
11
|
+
src/BCBvcl4pyAPI.egg-info/PKG-INFO
|
|
12
|
+
src/BCBvcl4pyAPI.egg-info/SOURCES.txt
|
|
13
|
+
src/BCBvcl4pyAPI.egg-info/dependency_links.txt
|
|
14
|
+
src/BCBvcl4pyAPI.egg-info/requires.txt
|
|
15
|
+
src/BCBvcl4pyAPI.egg-info/top_level.txt
|
|
16
|
+
src/Example/PyListTest.py
|
|
17
|
+
src/Example/PyListTest2.py
|
|
18
|
+
src/Example/TestHyperList.py
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
from BCBvcl4pyAPI import TStringList
|
|
2
|
+
from BCBvcl4pyAPI import DynamicArray
|
|
3
|
+
|
|
4
|
+
mi_c : int = 0;
|
|
5
|
+
|
|
6
|
+
obj_StrList = TStringList();
|
|
7
|
+
|
|
8
|
+
obj_StrList.Add("Str--1");
|
|
9
|
+
obj_StrList.Add("Str--2");
|
|
10
|
+
|
|
11
|
+
print();
|
|
12
|
+
for mi_c in range(0, obj_StrList.Count()):
|
|
13
|
+
print(f"data {mi_c}: {obj_StrList[mi_c]}");
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
mda_Values = DynamicArray[float]();
|
|
17
|
+
|
|
18
|
+
mda_Values.Add(1.2);
|
|
19
|
+
mda_Values.Add(2.2);
|
|
20
|
+
mda_Values.Add(3.2);
|
|
21
|
+
mda_Values.Add(4.2);
|
|
22
|
+
mda_Values.Add(5.2);
|
|
23
|
+
|
|
24
|
+
for mi_c in range(0, mda_Values.Length()):
|
|
25
|
+
print(f"data_float = {mda_Values[mi_c]}");
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
from BCBvcl4pyAPI import TStringList
|
|
2
|
+
from BCBvcl4pyAPI import DynamicArray
|
|
3
|
+
|
|
4
|
+
obj_MyList : TStringList;
|
|
5
|
+
mda_MyValues : DynamicArray;
|
|
6
|
+
mi_c : int = 0;
|
|
7
|
+
|
|
8
|
+
mda_MyValues = DynamicArray();
|
|
9
|
+
|
|
10
|
+
mda_MyValues.Add(0.319);
|
|
11
|
+
mda_MyValues.Add(4.123);
|
|
12
|
+
mda_MyValues.Add(3.621);
|
|
13
|
+
|
|
14
|
+
for mi_c in range(0, mda_MyValues.Length()):
|
|
15
|
+
print(mda_MyValues[mi_c]);
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
obj_MyList = TStringList();
|
|
19
|
+
obj_MyList.Add("OKOK");
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
from BCBvcl4pyAPI import HyperDynamicArray
|
|
2
|
+
from dataclasses import dataclass
|
|
3
|
+
|
|
4
|
+
@dataclass
|
|
5
|
+
class TPerson:
|
|
6
|
+
name: str
|
|
7
|
+
age: int
|
|
8
|
+
|
|
9
|
+
# 建立記憶體 table 模式
|
|
10
|
+
arr = HyperDynamicArray[TPerson](
|
|
11
|
+
mysql_host="mis.gotech.biz",
|
|
12
|
+
mysql_port= 3300,
|
|
13
|
+
mysql_user="root",
|
|
14
|
+
mysql_password="gotechdf8000sys",
|
|
15
|
+
mysql_db="df8000",
|
|
16
|
+
table_name="_mem_dataset",
|
|
17
|
+
table_type="memory"
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
arr.Clear();
|
|
21
|
+
|
|
22
|
+
# 加入元素
|
|
23
|
+
for i in range(500):
|
|
24
|
+
arr.Add(TPerson(f"Person{i}", 20+i))
|
|
25
|
+
|
|
26
|
+
print("元素總數:", arr.Count())
|
|
27
|
+
|
|
28
|
+
# 讀取
|
|
29
|
+
for i in range(arr.Count()):
|
|
30
|
+
print(arr[i])
|
|
31
|
+
|
|
32
|
+
print(arr[106].name);
|
|
33
|
+
|
|
34
|
+
# 清空 table
|
|
35
|
+
#arr.Clear()
|
|
36
|
+
#print("清空後元素總數:", arr.Count())
|
|
37
|
+
|
|
38
|
+
arr.Close()
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: BCBvcl4pyAPI
|
|
3
|
-
Version: 0.1.5
|
|
4
|
-
Summary: BCBvcl4pyAPI Python package
|
|
5
|
-
Author-email: James Lin <tylin123@ms27.hinet.net>
|
|
6
|
-
Project-URL: Homepage, https://mis.gotech.biz
|
|
7
|
-
Description-Content-Type: text/markdown
|
|
8
|
-
Requires-Dist: pymysql
|
|
9
|
-
|
|
10
|
-
Version 0.1.3: 2025/09/19
|
|
11
|
-
Mainly fixed the issue where Packages could not be found after an update.
|
|
12
|
-
Version 0.1.5: 2025/09/20
|
|
13
|
-
Add the HyperDynamicArray class to provide large memory access functionality.
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
README.md
|
|
2
|
-
pyproject.toml
|
|
3
|
-
setup.cfg
|
|
4
|
-
BCBvcl4pyAPI/BCBvcl4pyAPI.py
|
|
5
|
-
BCBvcl4pyAPI/HyperDynamicArrayAPI.py
|
|
6
|
-
BCBvcl4pyAPI/__init__.py
|
|
7
|
-
BCBvcl4pyAPI.egg-info/PKG-INFO
|
|
8
|
-
BCBvcl4pyAPI.egg-info/SOURCES.txt
|
|
9
|
-
BCBvcl4pyAPI.egg-info/dependency_links.txt
|
|
10
|
-
BCBvcl4pyAPI.egg-info/requires.txt
|
|
11
|
-
BCBvcl4pyAPI.egg-info/top_level.txt
|
bcbvcl4pyapi-0.1.5/PKG-INFO
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: BCBvcl4pyAPI
|
|
3
|
-
Version: 0.1.5
|
|
4
|
-
Summary: BCBvcl4pyAPI Python package
|
|
5
|
-
Author-email: James Lin <tylin123@ms27.hinet.net>
|
|
6
|
-
Project-URL: Homepage, https://mis.gotech.biz
|
|
7
|
-
Description-Content-Type: text/markdown
|
|
8
|
-
Requires-Dist: pymysql
|
|
9
|
-
|
|
10
|
-
Version 0.1.3: 2025/09/19
|
|
11
|
-
Mainly fixed the issue where Packages could not be found after an update.
|
|
12
|
-
Version 0.1.5: 2025/09/20
|
|
13
|
-
Add the HyperDynamicArray class to provide large memory access functionality.
|
bcbvcl4pyapi-0.1.5/README.md
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|