Skip to content

Commit 9cc644c

Browse files
committed
refactor: 重构目录结构
1 parent dea3ac4 commit 9cc644c

11 files changed

Lines changed: 32 additions & 28 deletions

File tree

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,14 @@ ab_request/http_client/
6060
### 基本使用
6161

6262
```python
63-
from ab_request.http_client import BaseClient, JSONResponseParser
63+
from http_client import BaseClient, JSONResponseParser
64+
6465

6566
class MyAPIClient(BaseClient):
6667
base_url = "https://api.example.com"
6768
response_parser_class = JSONResponseParser
6869

70+
6971
# 创建客户端实例
7072
client = MyAPIClient()
7173

@@ -93,12 +95,14 @@ results = client.request([
9395
### 使用缓存
9496

9597
```python
96-
from ab_request.http_client import CacheClientMixin
98+
from http_client import CacheClientMixin
99+
97100

98101
class CachedAPIClient(CacheClientMixin, BaseClient):
99102
base_url = "https://api.example.com"
100103
default_cache_expire = 300 # 5分钟
101104

105+
102106
client = CachedAPIClient()
103107

104108
# 第一次请求会缓存
@@ -134,7 +138,7 @@ class AuthenticatedClient(BaseClient):
134138

135139
## 📚 更多示例
136140

137-
查看 [examples.py](./examples.py) 获取更多使用示例。
141+
查看 [examples.py](examples.py) 获取更多使用示例。
138142

139143
运行示例:
140144
```bash
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
- 缓存: CacheClientMixin, InMemoryCacheBackend, RedisCacheBackend
1313
1414
使用示例:
15-
>>> from ab_request.http_client import BaseClient, JSONResponseParser
15+
>>> from http_client import BaseClient, JSONResponseParser
1616
>>>
1717
>>> class MyAPIClient(BaseClient):
1818
... base_url = "https://api.example.com"
@@ -23,10 +23,10 @@
2323
"""
2424

2525
# 核心客户端
26-
from ab_request.http_client.client import BaseClient
26+
from http_client.client import BaseClient
2727

2828
# 异常类
29-
from ab_request.http_client.exceptions import (
29+
from http_client.exceptions import (
3030
APIClientError,
3131
APIClientHTTPError,
3232
APIClientNetworkError,
@@ -36,7 +36,7 @@
3636
)
3737

3838
# 响应解析器
39-
from ab_request.http_client.parser import (
39+
from http_client.parser import (
4040
BaseResponseParser,
4141
ContentResponseParser,
4242
FileWriteResponseParser,
@@ -46,35 +46,35 @@
4646
)
4747

4848
# 响应格式化器
49-
from ab_request.http_client.formatter import (
49+
from http_client.formatter import (
5050
BaseResponseFormatter,
5151
DefaultResponseFormatter,
5252
)
5353

5454
# 异步执行器
55-
from ab_request.http_client.async_executor import (
55+
from http_client.async_executor import (
5656
BaseAsyncExecutor,
5757
ThreadPoolAsyncExecutor,
5858
)
5959

6060
# 响应验证器
61-
from ab_request.http_client.validator import (
61+
from http_client.validator import (
6262
BaseResponseValidator,
6363
CustomValidator,
6464
JSONFieldValidator,
6565
StatusCodeValidator,
6666
)
6767

6868
# 缓存支持
69-
from ab_request.http_client.cache import (
69+
from http_client.cache import (
7070
BaseCacheBackend,
7171
CacheClientMixin,
7272
InMemoryCacheBackend,
7373
RedisCacheBackend,
7474
)
7575

7676
# 常量配置
77-
from ab_request.http_client.constants import (
77+
from http_client.constants import (
7878
CACHEABLE_METHODS,
7979
DEFAULT_CACHE_EXPIRE,
8080
DEFAULT_MAX_WORKERS,
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
from concurrent.futures import Future, ThreadPoolExecutor, as_completed
1111
from typing import Any
1212

13-
from ab_request.http_client.constants import LOG_FORMAT
14-
from ab_request.http_client.exceptions import APIClientError
13+
from http_client.constants import LOG_FORMAT
14+
from http_client.exceptions import APIClientError
1515

1616
logging.basicConfig(level=logging.INFO, format=LOG_FORMAT)
1717
logger = logging.getLogger(__name__)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
import redis
1919

20-
from ab_request.http_client.constants import (
20+
from http_client.constants import (
2121
CACHEABLE_METHODS,
2222
DEFAULT_CACHE_EXPIRE,
2323
DEFAULT_CACHE_MAXSIZE,
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
ResponseDict: TypeAlias = dict[str, Any]
2727
RequestDataType: TypeAlias = RequestConfig | list[RequestConfig] | None
2828

29-
from ab_request.http_client.constants import (
29+
from http_client.constants import (
3030
DEFAULT_MAX_WORKERS,
3131
DEFAULT_POOL_CONFIG,
3232
DEFAULT_RETRIES,
@@ -35,22 +35,22 @@
3535
LOG_FORMAT,
3636
RESPONSE_CODE_FORMATTING_ERROR,
3737
)
38-
from ab_request.http_client.exceptions import (
38+
from http_client.exceptions import (
3939
APIClientError,
4040
APIClientHTTPError,
4141
APIClientNetworkError,
4242
APIClientTimeoutError,
4343
APIClientValidationError,
4444
)
45-
from ab_request.http_client.async_executor import BaseAsyncExecutor, ThreadPoolAsyncExecutor
46-
from ab_request.http_client.formatter import BaseResponseFormatter, DefaultResponseFormatter
47-
from ab_request.http_client.parser import (
45+
from http_client.async_executor import BaseAsyncExecutor, ThreadPoolAsyncExecutor
46+
from http_client.formatter import BaseResponseFormatter, DefaultResponseFormatter
47+
from http_client.parser import (
4848
BaseResponseParser,
4949
FileWriteResponseParser,
5050
JSONResponseParser,
5151
RawResponseParser,
5252
)
53-
from ab_request.http_client.validator import BaseResponseValidator
53+
from http_client.validator import BaseResponseValidator
5454

5555
# 配置日志
5656
logging.basicConfig(level=logging.INFO, format=LOG_FORMAT)
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
"""
22
HTTP 客户端使用示例
33
4-
演示如何使用 ab_request.http_client 模块的各种功能
4+
演示如何使用 http_client 模块的各种功能
55
"""
66

77
from requests.auth import AuthBase
88

9-
from ab_request.http_client import (
9+
from http_client import (
1010
BaseClient,
1111
ContentResponseParser,
1212
JSONResponseParser,
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010

1111
import requests
1212

13-
from ab_request.http_client.constants import (
13+
from http_client.constants import (
1414
LOG_FORMAT,
1515
RESPONSE_CODE_NON_HTTP_ERROR,
1616
RESPONSE_CODE_UNEXPECTED_TYPE,
1717
)
18-
from ab_request.http_client.exceptions import APIClientError
18+
from http_client.exceptions import APIClientError
1919

2020
logging.basicConfig(level=logging.INFO, format=LOG_FORMAT)
2121
logger = logging.getLogger(__name__)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
import requests
1313

14-
from ab_request.http_client.constants import (
14+
from http_client.constants import (
1515
DEFAULT_CHUNK_SIZE,
1616
DEFAULT_DOWNLOAD_PATH,
1717
DEFAULT_FILENAME,

0 commit comments

Comments
 (0)