wcp32-client 0.1.1__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.
- wcp32_client-0.1.1/.gitignore +11 -0
- wcp32_client-0.1.1/CHANGELOG.md +14 -0
- wcp32_client-0.1.1/LICENSE +22 -0
- wcp32_client-0.1.1/PKG-INFO +237 -0
- wcp32_client-0.1.1/README.md +185 -0
- wcp32_client-0.1.1/examples/basic_usage.py +26 -0
- wcp32_client-0.1.1/examples/export_category.py +40 -0
- wcp32_client-0.1.1/pyproject.toml +74 -0
- wcp32_client-0.1.1/src/wcp32/__init__.py +46 -0
- wcp32_client-0.1.1/src/wcp32/_parsers.py +433 -0
- wcp32_client-0.1.1/src/wcp32/_transport.py +215 -0
- wcp32_client-0.1.1/src/wcp32/client.py +72 -0
- wcp32_client-0.1.1/src/wcp32/exceptions.py +32 -0
- wcp32_client-0.1.1/src/wcp32/models.py +112 -0
- wcp32_client-0.1.1/src/wcp32/py.typed +1 -0
- wcp32_client-0.1.1/src/wcp32/services/__init__.py +18 -0
- wcp32_client-0.1.1/src/wcp32/services/attachments.py +158 -0
- wcp32_client-0.1.1/src/wcp32/services/categories.py +93 -0
- wcp32_client-0.1.1/src/wcp32/services/documents.py +231 -0
- wcp32_client-0.1.1/src/wcp32/services/raw.py +21 -0
- wcp32_client-0.1.1/src/wcp32/services/search.py +38 -0
- wcp32_client-0.1.1/src/wcp32/services/users.py +113 -0
- wcp32_client-0.1.1/tests/fixtures/document.html +40 -0
- wcp32_client-0.1.1/tests/fixtures/resource_document.html +42 -0
- wcp32_client-0.1.1/tests/fixtures/search.html +19 -0
- wcp32_client-0.1.1/tests/fixtures/user-edit.html +13 -0
- wcp32_client-0.1.1/tests/test_integration.py +57 -0
- wcp32_client-0.1.1/tests/test_parsers.py +73 -0
- wcp32_client-0.1.1/tests/test_services.py +105 -0
- wcp32_client-0.1.1/tests/test_transport.py +72 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.1
|
|
4
|
+
|
|
5
|
+
- Parse resource-file documents that contain both authored content and attachments.
|
|
6
|
+
- Read resource document content from `#textsBoxId`.
|
|
7
|
+
- Extract the real attachment name, size, and download URL from resource cards.
|
|
8
|
+
|
|
9
|
+
## 0.1.0
|
|
10
|
+
|
|
11
|
+
- Initial read-only client for WCP 3.2.0.
|
|
12
|
+
- Session login and logout.
|
|
13
|
+
- Typed category, document, content, attachment, user, and search services.
|
|
14
|
+
- Streaming attachment downloads and a read-only raw GET escape hatch.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 WCP32 Client Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: wcp32-client
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: A typed, read-only Python client for WCP 3.2.x knowledge management systems.
|
|
5
|
+
Project-URL: WCP upstream, https://gitee.com/macplus/WCP
|
|
6
|
+
Author: WCP32 Client Contributors
|
|
7
|
+
License: MIT License
|
|
8
|
+
|
|
9
|
+
Copyright (c) 2026 WCP32 Client Contributors
|
|
10
|
+
|
|
11
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
12
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
13
|
+
in the Software without restriction, including without limitation the rights
|
|
14
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
15
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
16
|
+
furnished to do so, subject to the following conditions:
|
|
17
|
+
|
|
18
|
+
The above copyright notice and this permission notice shall be included in all
|
|
19
|
+
copies or substantial portions of the Software.
|
|
20
|
+
|
|
21
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
22
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
23
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
24
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
25
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
26
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
27
|
+
SOFTWARE.
|
|
28
|
+
|
|
29
|
+
License-File: LICENSE
|
|
30
|
+
Keywords: client,knowledge-management,sdk,wcp
|
|
31
|
+
Classifier: Development Status :: 3 - Alpha
|
|
32
|
+
Classifier: Intended Audience :: Developers
|
|
33
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
34
|
+
Classifier: Programming Language :: Python :: 3
|
|
35
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
36
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
37
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
38
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
39
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
40
|
+
Requires-Python: >=3.10
|
|
41
|
+
Requires-Dist: beautifulsoup4<5,>=4.12
|
|
42
|
+
Requires-Dist: requests<3,>=2.31
|
|
43
|
+
Provides-Extra: dev
|
|
44
|
+
Requires-Dist: build>=1.2; extra == 'dev'
|
|
45
|
+
Requires-Dist: mypy>=1.10; extra == 'dev'
|
|
46
|
+
Requires-Dist: pytest>=8; extra == 'dev'
|
|
47
|
+
Requires-Dist: responses>=0.25; extra == 'dev'
|
|
48
|
+
Requires-Dist: ruff>=0.6; extra == 'dev'
|
|
49
|
+
Requires-Dist: twine>=5; extra == 'dev'
|
|
50
|
+
Requires-Dist: types-requests>=2.31; extra == 'dev'
|
|
51
|
+
Description-Content-Type: text/markdown
|
|
52
|
+
|
|
53
|
+
# wcp32-client
|
|
54
|
+
|
|
55
|
+
`wcp32-client` 是面向太原扁舟 WCP 3.2.x 知识管理系统的同步、只读 Python
|
|
56
|
+
客户端。它封装了 WCP 旧版的 JSESSIONID 登录、后台 EasyUI JSON 接口、前台
|
|
57
|
+
HTML 文档页和附件下载地址。
|
|
58
|
+
|
|
59
|
+
> 该项目不是 WCP 官方 SDK。首个验收版本以 WCP 3.2.0 为基线,不兼容 WCP5。
|
|
60
|
+
|
|
61
|
+
## 安装
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
python -m pip install wcp32-client
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
从源码安装:
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
python -m pip install .
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## 快速开始
|
|
74
|
+
|
|
75
|
+
```python
|
|
76
|
+
from wcp32 import WcpClient
|
|
77
|
+
|
|
78
|
+
with WcpClient("https://wcp.example.com/") as client:
|
|
79
|
+
client.login("username", "password")
|
|
80
|
+
|
|
81
|
+
for category in client.categories.iter_all():
|
|
82
|
+
print(category.id, category.name)
|
|
83
|
+
|
|
84
|
+
page = client.documents.list(category_id="分类ID", page_size=100)
|
|
85
|
+
for document in page.items:
|
|
86
|
+
print(document.id, document.title)
|
|
87
|
+
|
|
88
|
+
content = client.documents.get_content("文档ID")
|
|
89
|
+
print(content.text)
|
|
90
|
+
|
|
91
|
+
for attachment in client.attachments.list("文档ID"):
|
|
92
|
+
print(attachment.name, attachment.size)
|
|
93
|
+
|
|
94
|
+
current_user = client.users.me()
|
|
95
|
+
print(current_user.id, current_user.name)
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
凭据只在运行时传给 `login()`;请勿把账号、密码或 JSESSIONID 写入源码。
|
|
99
|
+
|
|
100
|
+
## API
|
|
101
|
+
|
|
102
|
+
### 分类
|
|
103
|
+
|
|
104
|
+
```python
|
|
105
|
+
roots = client.categories.list()
|
|
106
|
+
children = client.categories.list(parent_id="父分类ID")
|
|
107
|
+
category = client.categories.get("分类ID")
|
|
108
|
+
tree = client.categories.tree()
|
|
109
|
+
all_categories = list(client.categories.iter_all())
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### 文档
|
|
113
|
+
|
|
114
|
+
```python
|
|
115
|
+
page = client.documents.list(
|
|
116
|
+
category_id="分类ID",
|
|
117
|
+
page=1,
|
|
118
|
+
page_size=100,
|
|
119
|
+
recursive=False,
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
all_documents = list(
|
|
123
|
+
client.documents.iter("分类ID", recursive=True, page_size=100)
|
|
124
|
+
)
|
|
125
|
+
|
|
126
|
+
document = client.documents.get("文档ID")
|
|
127
|
+
html_content = client.documents.get_content("文档ID", format="html")
|
|
128
|
+
text_content = client.documents.get_content("文档ID", format="text")
|
|
129
|
+
versions = client.documents.versions("文档ID")
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
`recursive=False` 只查询当前分类。开启递归后,客户端遍历后代分类并按文档 ID
|
|
133
|
+
去重。
|
|
134
|
+
|
|
135
|
+
### 附件
|
|
136
|
+
|
|
137
|
+
```python
|
|
138
|
+
attachments = client.attachments.list("文档ID")
|
|
139
|
+
attachment = client.attachments.get("附件ID")
|
|
140
|
+
|
|
141
|
+
data = client.attachments.read("附件ID", max_bytes=10 * 1024 * 1024)
|
|
142
|
+
|
|
143
|
+
for chunk in client.attachments.iter_bytes("附件ID"):
|
|
144
|
+
process(chunk)
|
|
145
|
+
|
|
146
|
+
saved_path = client.attachments.download(
|
|
147
|
+
"附件ID",
|
|
148
|
+
"downloads/report.pdf",
|
|
149
|
+
overwrite=False,
|
|
150
|
+
)
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
`download()` 默认不覆盖文件,并使用临时文件完成原子替换。
|
|
154
|
+
|
|
155
|
+
### 用户和搜索
|
|
156
|
+
|
|
157
|
+
```python
|
|
158
|
+
users = client.users.list(page=1, page_size=100)
|
|
159
|
+
user = client.users.get("用户ID")
|
|
160
|
+
me = client.users.me()
|
|
161
|
+
user_documents = client.users.documents("用户ID")
|
|
162
|
+
|
|
163
|
+
results = client.search.documents("关键词", page=1)
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
用户后台接口通常需要管理员权限。权限不足会抛出
|
|
167
|
+
`WcpPermissionError`,不会返回伪造的空列表。
|
|
168
|
+
|
|
169
|
+
### 原始只读请求
|
|
170
|
+
|
|
171
|
+
```python
|
|
172
|
+
response = client.raw.get("home/PubrecommendServiceList.do")
|
|
173
|
+
payload = response.json()
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
`raw` 只提供 GET,不暴露通用 POST/PUT/DELETE。
|
|
177
|
+
|
|
178
|
+
## 返回模型
|
|
179
|
+
|
|
180
|
+
列表接口返回 `Page[T]`,其中包含:
|
|
181
|
+
|
|
182
|
+
- `items`:类型模型列表;
|
|
183
|
+
- `total`:服务端报告的总数;
|
|
184
|
+
- `page`、`page_size`;
|
|
185
|
+
- `raw`:WCP 原始响应字段。
|
|
186
|
+
|
|
187
|
+
`Category`、`Document`、`Attachment`、`User` 等模型也保留 `raw`,用于访问尚未
|
|
188
|
+
标准化的旧版字段。
|
|
189
|
+
|
|
190
|
+
## 异常
|
|
191
|
+
|
|
192
|
+
- `WcpAuthenticationError`:登录失败或会话失效;
|
|
193
|
+
- `WcpPermissionError`:当前账号没有后台接口权限;
|
|
194
|
+
- `WcpNotFoundError`:文档、分类、附件或用户不存在;
|
|
195
|
+
- `WcpTransportError`:超时、连接失败或 HTTP 错误;
|
|
196
|
+
- `WcpParseError`:WCP 页面/JSON 结构与预期不符;
|
|
197
|
+
- `WcpVersionError`:检测到不兼容的服务器版本。
|
|
198
|
+
|
|
199
|
+
## 代理、TLS 和超时
|
|
200
|
+
|
|
201
|
+
```python
|
|
202
|
+
client = WcpClient(
|
|
203
|
+
"https://wcp.example.com/",
|
|
204
|
+
timeout=30,
|
|
205
|
+
verify_tls=True,
|
|
206
|
+
proxies={"https": "http://proxy.example.com:8080"},
|
|
207
|
+
retries=2,
|
|
208
|
+
)
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
## 运行测试
|
|
212
|
+
|
|
213
|
+
```bash
|
|
214
|
+
python -m pip install -e ".[dev]"
|
|
215
|
+
pytest
|
|
216
|
+
ruff check .
|
|
217
|
+
mypy src
|
|
218
|
+
python -m build
|
|
219
|
+
twine check dist/*
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
内网集成测试默认跳过。显式提供以下环境变量后运行:
|
|
223
|
+
|
|
224
|
+
```text
|
|
225
|
+
WCP_BASE_URL
|
|
226
|
+
WCP_USERNAME
|
|
227
|
+
WCP_PASSWORD
|
|
228
|
+
WCP_TEST_CATEGORY_ID # 可选
|
|
229
|
+
WCP_TEST_DOCUMENT_ID # 可选
|
|
230
|
+
WCP_TEST_ATTACHMENT_DOCUMENT_ID # 可选,包含附件的文档
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
```bash
|
|
234
|
+
pytest -m integration
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
集成测试只调用查询、登录和退出接口。
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
# wcp32-client
|
|
2
|
+
|
|
3
|
+
`wcp32-client` 是面向太原扁舟 WCP 3.2.x 知识管理系统的同步、只读 Python
|
|
4
|
+
客户端。它封装了 WCP 旧版的 JSESSIONID 登录、后台 EasyUI JSON 接口、前台
|
|
5
|
+
HTML 文档页和附件下载地址。
|
|
6
|
+
|
|
7
|
+
> 该项目不是 WCP 官方 SDK。首个验收版本以 WCP 3.2.0 为基线,不兼容 WCP5。
|
|
8
|
+
|
|
9
|
+
## 安装
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
python -m pip install wcp32-client
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
从源码安装:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
python -m pip install .
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## 快速开始
|
|
22
|
+
|
|
23
|
+
```python
|
|
24
|
+
from wcp32 import WcpClient
|
|
25
|
+
|
|
26
|
+
with WcpClient("https://wcp.example.com/") as client:
|
|
27
|
+
client.login("username", "password")
|
|
28
|
+
|
|
29
|
+
for category in client.categories.iter_all():
|
|
30
|
+
print(category.id, category.name)
|
|
31
|
+
|
|
32
|
+
page = client.documents.list(category_id="分类ID", page_size=100)
|
|
33
|
+
for document in page.items:
|
|
34
|
+
print(document.id, document.title)
|
|
35
|
+
|
|
36
|
+
content = client.documents.get_content("文档ID")
|
|
37
|
+
print(content.text)
|
|
38
|
+
|
|
39
|
+
for attachment in client.attachments.list("文档ID"):
|
|
40
|
+
print(attachment.name, attachment.size)
|
|
41
|
+
|
|
42
|
+
current_user = client.users.me()
|
|
43
|
+
print(current_user.id, current_user.name)
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
凭据只在运行时传给 `login()`;请勿把账号、密码或 JSESSIONID 写入源码。
|
|
47
|
+
|
|
48
|
+
## API
|
|
49
|
+
|
|
50
|
+
### 分类
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
roots = client.categories.list()
|
|
54
|
+
children = client.categories.list(parent_id="父分类ID")
|
|
55
|
+
category = client.categories.get("分类ID")
|
|
56
|
+
tree = client.categories.tree()
|
|
57
|
+
all_categories = list(client.categories.iter_all())
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### 文档
|
|
61
|
+
|
|
62
|
+
```python
|
|
63
|
+
page = client.documents.list(
|
|
64
|
+
category_id="分类ID",
|
|
65
|
+
page=1,
|
|
66
|
+
page_size=100,
|
|
67
|
+
recursive=False,
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
all_documents = list(
|
|
71
|
+
client.documents.iter("分类ID", recursive=True, page_size=100)
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
document = client.documents.get("文档ID")
|
|
75
|
+
html_content = client.documents.get_content("文档ID", format="html")
|
|
76
|
+
text_content = client.documents.get_content("文档ID", format="text")
|
|
77
|
+
versions = client.documents.versions("文档ID")
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
`recursive=False` 只查询当前分类。开启递归后,客户端遍历后代分类并按文档 ID
|
|
81
|
+
去重。
|
|
82
|
+
|
|
83
|
+
### 附件
|
|
84
|
+
|
|
85
|
+
```python
|
|
86
|
+
attachments = client.attachments.list("文档ID")
|
|
87
|
+
attachment = client.attachments.get("附件ID")
|
|
88
|
+
|
|
89
|
+
data = client.attachments.read("附件ID", max_bytes=10 * 1024 * 1024)
|
|
90
|
+
|
|
91
|
+
for chunk in client.attachments.iter_bytes("附件ID"):
|
|
92
|
+
process(chunk)
|
|
93
|
+
|
|
94
|
+
saved_path = client.attachments.download(
|
|
95
|
+
"附件ID",
|
|
96
|
+
"downloads/report.pdf",
|
|
97
|
+
overwrite=False,
|
|
98
|
+
)
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
`download()` 默认不覆盖文件,并使用临时文件完成原子替换。
|
|
102
|
+
|
|
103
|
+
### 用户和搜索
|
|
104
|
+
|
|
105
|
+
```python
|
|
106
|
+
users = client.users.list(page=1, page_size=100)
|
|
107
|
+
user = client.users.get("用户ID")
|
|
108
|
+
me = client.users.me()
|
|
109
|
+
user_documents = client.users.documents("用户ID")
|
|
110
|
+
|
|
111
|
+
results = client.search.documents("关键词", page=1)
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
用户后台接口通常需要管理员权限。权限不足会抛出
|
|
115
|
+
`WcpPermissionError`,不会返回伪造的空列表。
|
|
116
|
+
|
|
117
|
+
### 原始只读请求
|
|
118
|
+
|
|
119
|
+
```python
|
|
120
|
+
response = client.raw.get("home/PubrecommendServiceList.do")
|
|
121
|
+
payload = response.json()
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
`raw` 只提供 GET,不暴露通用 POST/PUT/DELETE。
|
|
125
|
+
|
|
126
|
+
## 返回模型
|
|
127
|
+
|
|
128
|
+
列表接口返回 `Page[T]`,其中包含:
|
|
129
|
+
|
|
130
|
+
- `items`:类型模型列表;
|
|
131
|
+
- `total`:服务端报告的总数;
|
|
132
|
+
- `page`、`page_size`;
|
|
133
|
+
- `raw`:WCP 原始响应字段。
|
|
134
|
+
|
|
135
|
+
`Category`、`Document`、`Attachment`、`User` 等模型也保留 `raw`,用于访问尚未
|
|
136
|
+
标准化的旧版字段。
|
|
137
|
+
|
|
138
|
+
## 异常
|
|
139
|
+
|
|
140
|
+
- `WcpAuthenticationError`:登录失败或会话失效;
|
|
141
|
+
- `WcpPermissionError`:当前账号没有后台接口权限;
|
|
142
|
+
- `WcpNotFoundError`:文档、分类、附件或用户不存在;
|
|
143
|
+
- `WcpTransportError`:超时、连接失败或 HTTP 错误;
|
|
144
|
+
- `WcpParseError`:WCP 页面/JSON 结构与预期不符;
|
|
145
|
+
- `WcpVersionError`:检测到不兼容的服务器版本。
|
|
146
|
+
|
|
147
|
+
## 代理、TLS 和超时
|
|
148
|
+
|
|
149
|
+
```python
|
|
150
|
+
client = WcpClient(
|
|
151
|
+
"https://wcp.example.com/",
|
|
152
|
+
timeout=30,
|
|
153
|
+
verify_tls=True,
|
|
154
|
+
proxies={"https": "http://proxy.example.com:8080"},
|
|
155
|
+
retries=2,
|
|
156
|
+
)
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## 运行测试
|
|
160
|
+
|
|
161
|
+
```bash
|
|
162
|
+
python -m pip install -e ".[dev]"
|
|
163
|
+
pytest
|
|
164
|
+
ruff check .
|
|
165
|
+
mypy src
|
|
166
|
+
python -m build
|
|
167
|
+
twine check dist/*
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
内网集成测试默认跳过。显式提供以下环境变量后运行:
|
|
171
|
+
|
|
172
|
+
```text
|
|
173
|
+
WCP_BASE_URL
|
|
174
|
+
WCP_USERNAME
|
|
175
|
+
WCP_PASSWORD
|
|
176
|
+
WCP_TEST_CATEGORY_ID # 可选
|
|
177
|
+
WCP_TEST_DOCUMENT_ID # 可选
|
|
178
|
+
WCP_TEST_ATTACHMENT_DOCUMENT_ID # 可选,包含附件的文档
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
```bash
|
|
182
|
+
pytest -m integration
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
集成测试只调用查询、登录和退出接口。
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"""Minimal read-only usage example."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
|
|
7
|
+
from wcp32 import WcpClient
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def main() -> None:
|
|
11
|
+
base_url = os.environ["WCP_BASE_URL"]
|
|
12
|
+
username = os.environ["WCP_USERNAME"]
|
|
13
|
+
password = os.environ["WCP_PASSWORD"]
|
|
14
|
+
|
|
15
|
+
with WcpClient(base_url) as client:
|
|
16
|
+
client.login(username, password)
|
|
17
|
+
me = client.users.me()
|
|
18
|
+
print(f"Logged in as {me.name} ({me.id})")
|
|
19
|
+
|
|
20
|
+
for category in client.categories.iter_all():
|
|
21
|
+
print(category.id, category.name)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
if __name__ == "__main__":
|
|
25
|
+
main()
|
|
26
|
+
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"""Export all documents in one category as JSON."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import json
|
|
7
|
+
import os
|
|
8
|
+
from dataclasses import asdict
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
|
|
11
|
+
from wcp32 import WcpClient
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def main() -> None:
|
|
15
|
+
parser = argparse.ArgumentParser()
|
|
16
|
+
parser.add_argument("category_id")
|
|
17
|
+
parser.add_argument("output", type=Path)
|
|
18
|
+
parser.add_argument("--recursive", action="store_true")
|
|
19
|
+
args = parser.parse_args()
|
|
20
|
+
|
|
21
|
+
with WcpClient(os.environ["WCP_BASE_URL"]) as client:
|
|
22
|
+
client.login(os.environ["WCP_USERNAME"], os.environ["WCP_PASSWORD"])
|
|
23
|
+
documents = [
|
|
24
|
+
asdict(document)
|
|
25
|
+
for document in client.documents.iter(
|
|
26
|
+
args.category_id,
|
|
27
|
+
recursive=args.recursive,
|
|
28
|
+
)
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
args.output.write_text(
|
|
32
|
+
json.dumps(documents, ensure_ascii=False, indent=2),
|
|
33
|
+
encoding="utf-8",
|
|
34
|
+
)
|
|
35
|
+
print(f"Exported {len(documents)} documents to {args.output}")
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
if __name__ == "__main__":
|
|
39
|
+
main()
|
|
40
|
+
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.25"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "wcp32-client"
|
|
7
|
+
version = "0.1.1"
|
|
8
|
+
description = "A typed, read-only Python client for WCP 3.2.x knowledge management systems."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = { file = "LICENSE" }
|
|
12
|
+
authors = [
|
|
13
|
+
{ name = "WCP32 Client Contributors" }
|
|
14
|
+
]
|
|
15
|
+
keywords = ["wcp", "knowledge-management", "sdk", "client"]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 3 - Alpha",
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
"License :: OSI Approved :: MIT License",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Programming Language :: Python :: 3.10",
|
|
22
|
+
"Programming Language :: Python :: 3.11",
|
|
23
|
+
"Programming Language :: Python :: 3.12",
|
|
24
|
+
"Programming Language :: Python :: 3.13",
|
|
25
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
26
|
+
]
|
|
27
|
+
dependencies = [
|
|
28
|
+
"requests>=2.31,<3",
|
|
29
|
+
"beautifulsoup4>=4.12,<5",
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
[project.optional-dependencies]
|
|
33
|
+
dev = [
|
|
34
|
+
"build>=1.2",
|
|
35
|
+
"mypy>=1.10",
|
|
36
|
+
"pytest>=8",
|
|
37
|
+
"responses>=0.25",
|
|
38
|
+
"ruff>=0.6",
|
|
39
|
+
"twine>=5",
|
|
40
|
+
"types-requests>=2.31",
|
|
41
|
+
]
|
|
42
|
+
|
|
43
|
+
[project.urls]
|
|
44
|
+
"WCP upstream" = "https://gitee.com/macplus/WCP"
|
|
45
|
+
|
|
46
|
+
[tool.hatch.build.targets.wheel]
|
|
47
|
+
packages = ["src/wcp32"]
|
|
48
|
+
|
|
49
|
+
[tool.hatch.build.targets.sdist]
|
|
50
|
+
exclude = [
|
|
51
|
+
"/demo.py",
|
|
52
|
+
"/dist",
|
|
53
|
+
"/SHA256SUMS",
|
|
54
|
+
]
|
|
55
|
+
|
|
56
|
+
[tool.pytest.ini_options]
|
|
57
|
+
addopts = "-ra"
|
|
58
|
+
testpaths = ["tests"]
|
|
59
|
+
pythonpath = ["src"]
|
|
60
|
+
markers = [
|
|
61
|
+
"integration: read-only tests against a live WCP server",
|
|
62
|
+
]
|
|
63
|
+
|
|
64
|
+
[tool.ruff]
|
|
65
|
+
line-length = 100
|
|
66
|
+
target-version = "py310"
|
|
67
|
+
|
|
68
|
+
[tool.ruff.lint]
|
|
69
|
+
select = ["E", "F", "I", "UP", "B"]
|
|
70
|
+
|
|
71
|
+
[tool.mypy]
|
|
72
|
+
python_version = "3.10"
|
|
73
|
+
strict = true
|
|
74
|
+
warn_unused_ignores = true
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"""Typed, read-only Python client for WCP 3.2.x."""
|
|
2
|
+
|
|
3
|
+
from .client import WcpClient
|
|
4
|
+
from .exceptions import (
|
|
5
|
+
WcpAuthenticationError,
|
|
6
|
+
WcpError,
|
|
7
|
+
WcpNotFoundError,
|
|
8
|
+
WcpParseError,
|
|
9
|
+
WcpPermissionError,
|
|
10
|
+
WcpTransportError,
|
|
11
|
+
WcpVersionError,
|
|
12
|
+
)
|
|
13
|
+
from .models import (
|
|
14
|
+
Attachment,
|
|
15
|
+
Category,
|
|
16
|
+
CategoryNode,
|
|
17
|
+
Document,
|
|
18
|
+
DocumentContent,
|
|
19
|
+
DocumentVersion,
|
|
20
|
+
Page,
|
|
21
|
+
SessionInfo,
|
|
22
|
+
User,
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
__version__ = "0.1.1"
|
|
26
|
+
|
|
27
|
+
__all__ = [
|
|
28
|
+
"Attachment",
|
|
29
|
+
"Category",
|
|
30
|
+
"CategoryNode",
|
|
31
|
+
"Document",
|
|
32
|
+
"DocumentContent",
|
|
33
|
+
"DocumentVersion",
|
|
34
|
+
"Page",
|
|
35
|
+
"SessionInfo",
|
|
36
|
+
"User",
|
|
37
|
+
"WcpAuthenticationError",
|
|
38
|
+
"WcpClient",
|
|
39
|
+
"WcpError",
|
|
40
|
+
"WcpNotFoundError",
|
|
41
|
+
"WcpParseError",
|
|
42
|
+
"WcpPermissionError",
|
|
43
|
+
"WcpTransportError",
|
|
44
|
+
"WcpVersionError",
|
|
45
|
+
"__version__",
|
|
46
|
+
]
|