aio-scrapy 2.1.4__py3-none-any.whl → 2.1.7__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.
- {aio_scrapy-2.1.4.dist-info → aio_scrapy-2.1.7.dist-info}/LICENSE +1 -1
- aio_scrapy-2.1.7.dist-info/METADATA +147 -0
- aio_scrapy-2.1.7.dist-info/RECORD +134 -0
- {aio_scrapy-2.1.4.dist-info → aio_scrapy-2.1.7.dist-info}/WHEEL +1 -1
- aioscrapy/VERSION +1 -1
- aioscrapy/cmdline.py +438 -5
- aioscrapy/core/downloader/__init__.py +522 -17
- aioscrapy/core/downloader/handlers/__init__.py +187 -5
- aioscrapy/core/downloader/handlers/aiohttp.py +190 -6
- aioscrapy/core/downloader/handlers/curl_cffi.py +126 -5
- aioscrapy/core/downloader/handlers/httpx.py +135 -5
- aioscrapy/core/downloader/handlers/pyhttpx.py +137 -5
- aioscrapy/core/downloader/handlers/requests.py +120 -2
- aioscrapy/core/downloader/handlers/webdriver/__init__.py +2 -0
- aioscrapy/core/downloader/handlers/webdriver/drissionpage.py +493 -0
- aioscrapy/core/downloader/handlers/webdriver/driverpool.py +234 -0
- aioscrapy/core/downloader/handlers/webdriver/playwright.py +498 -0
- aioscrapy/core/engine.py +381 -20
- aioscrapy/core/scheduler.py +350 -36
- aioscrapy/core/scraper.py +509 -33
- aioscrapy/crawler.py +392 -10
- aioscrapy/db/__init__.py +149 -0
- aioscrapy/db/absmanager.py +212 -6
- aioscrapy/db/aiomongo.py +292 -10
- aioscrapy/db/aiomysql.py +363 -10
- aioscrapy/db/aiopg.py +299 -2
- aioscrapy/db/aiorabbitmq.py +444 -4
- aioscrapy/db/aioredis.py +260 -11
- aioscrapy/dupefilters/__init__.py +110 -5
- aioscrapy/dupefilters/disk.py +124 -2
- aioscrapy/dupefilters/redis.py +598 -32
- aioscrapy/exceptions.py +151 -13
- aioscrapy/http/__init__.py +1 -1
- aioscrapy/http/headers.py +237 -3
- aioscrapy/http/request/__init__.py +257 -11
- aioscrapy/http/request/form.py +83 -3
- aioscrapy/http/request/json_request.py +121 -9
- aioscrapy/http/response/__init__.py +306 -33
- aioscrapy/http/response/html.py +42 -3
- aioscrapy/http/response/text.py +496 -49
- aioscrapy/http/response/web_driver.py +144 -0
- aioscrapy/http/response/xml.py +45 -3
- aioscrapy/libs/downloader/defaultheaders.py +66 -2
- aioscrapy/libs/downloader/downloadtimeout.py +91 -2
- aioscrapy/libs/downloader/ja3fingerprint.py +95 -2
- aioscrapy/libs/downloader/retry.py +192 -6
- aioscrapy/libs/downloader/stats.py +142 -0
- aioscrapy/libs/downloader/useragent.py +93 -2
- aioscrapy/libs/extensions/closespider.py +166 -4
- aioscrapy/libs/extensions/corestats.py +151 -1
- aioscrapy/libs/extensions/logstats.py +145 -1
- aioscrapy/libs/extensions/metric.py +370 -1
- aioscrapy/libs/extensions/throttle.py +235 -1
- aioscrapy/libs/pipelines/__init__.py +345 -2
- aioscrapy/libs/pipelines/csv.py +242 -0
- aioscrapy/libs/pipelines/excel.py +545 -0
- aioscrapy/libs/pipelines/mongo.py +132 -0
- aioscrapy/libs/pipelines/mysql.py +67 -0
- aioscrapy/libs/pipelines/pg.py +67 -0
- aioscrapy/libs/spider/depth.py +141 -3
- aioscrapy/libs/spider/httperror.py +144 -4
- aioscrapy/libs/spider/offsite.py +202 -2
- aioscrapy/libs/spider/referer.py +396 -21
- aioscrapy/libs/spider/urllength.py +97 -1
- aioscrapy/link.py +115 -8
- aioscrapy/logformatter.py +199 -8
- aioscrapy/middleware/absmanager.py +328 -2
- aioscrapy/middleware/downloader.py +218 -0
- aioscrapy/middleware/extension.py +50 -1
- aioscrapy/middleware/itempipeline.py +96 -0
- aioscrapy/middleware/spider.py +360 -7
- aioscrapy/process.py +200 -0
- aioscrapy/proxy/__init__.py +142 -3
- aioscrapy/proxy/redis.py +136 -2
- aioscrapy/queue/__init__.py +168 -16
- aioscrapy/scrapyd/runner.py +124 -3
- aioscrapy/serializer.py +182 -2
- aioscrapy/settings/__init__.py +610 -128
- aioscrapy/settings/default_settings.py +314 -14
- aioscrapy/signalmanager.py +151 -20
- aioscrapy/signals.py +183 -1
- aioscrapy/spiderloader.py +165 -12
- aioscrapy/spiders/__init__.py +233 -6
- aioscrapy/statscollectors.py +312 -1
- aioscrapy/utils/conf.py +345 -17
- aioscrapy/utils/curl.py +168 -16
- aioscrapy/utils/decorators.py +76 -6
- aioscrapy/utils/deprecate.py +212 -19
- aioscrapy/utils/httpobj.py +55 -3
- aioscrapy/utils/log.py +79 -0
- aioscrapy/utils/misc.py +189 -21
- aioscrapy/utils/ossignal.py +67 -5
- aioscrapy/utils/project.py +165 -3
- aioscrapy/utils/python.py +254 -44
- aioscrapy/utils/reqser.py +75 -1
- aioscrapy/utils/request.py +173 -12
- aioscrapy/utils/response.py +91 -6
- aioscrapy/utils/signal.py +196 -14
- aioscrapy/utils/spider.py +51 -4
- aioscrapy/utils/template.py +93 -6
- aioscrapy/utils/tools.py +191 -17
- aioscrapy/utils/trackref.py +198 -12
- aioscrapy/utils/url.py +341 -36
- aio_scrapy-2.1.4.dist-info/METADATA +0 -239
- aio_scrapy-2.1.4.dist-info/RECORD +0 -133
- aioscrapy/core/downloader/handlers/playwright/__init__.py +0 -115
- aioscrapy/core/downloader/handlers/playwright/driverpool.py +0 -59
- aioscrapy/core/downloader/handlers/playwright/webdriver.py +0 -96
- aioscrapy/http/response/playwright.py +0 -36
- aioscrapy/libs/pipelines/execl.py +0 -169
- {aio_scrapy-2.1.4.dist-info → aio_scrapy-2.1.7.dist-info}/entry_points.txt +0 -0
- {aio_scrapy-2.1.4.dist-info → aio_scrapy-2.1.7.dist-info}/top_level.txt +0 -0
aioscrapy/db/__init__.py
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Database management module for aioscrapy.
|
|
3
|
+
aioscrapy的数据库管理模块。
|
|
4
|
+
|
|
5
|
+
This module provides a unified interface for managing different types of database
|
|
6
|
+
connections in aioscrapy. It supports Redis, MySQL, RabbitMQ, MongoDB, and PostgreSQL
|
|
7
|
+
through their respective async libraries.
|
|
8
|
+
此模块为aioscrapy中的不同类型数据库连接提供了统一的接口。它通过各自的异步库
|
|
9
|
+
支持Redis、MySQL、RabbitMQ、MongoDB和PostgreSQL。
|
|
10
|
+
"""
|
|
11
|
+
|
|
1
12
|
from importlib import import_module
|
|
2
13
|
from typing import Any
|
|
3
14
|
|
|
@@ -7,8 +18,12 @@ from aioscrapy.db.aioredis import redis_manager
|
|
|
7
18
|
from aioscrapy.utils.log import logger
|
|
8
19
|
from aioscrapy.utils.misc import load_object
|
|
9
20
|
|
|
21
|
+
# Public API
|
|
22
|
+
# 公共API
|
|
10
23
|
__all__ = ['db_manager', 'get_pool', 'get_manager']
|
|
11
24
|
|
|
25
|
+
# Mapping of database module names to their manager keys and class paths
|
|
26
|
+
# 数据库模块名称到其管理器键和类路径的映射
|
|
12
27
|
DB_MODULE_MAP = {
|
|
13
28
|
'redis': ('redis', 'aioscrapy.db.aioredis.redis_manager'),
|
|
14
29
|
'aiomysql': ('mysql', 'aioscrapy.db.aiomysql.mysql_manager'),
|
|
@@ -17,56 +32,190 @@ DB_MODULE_MAP = {
|
|
|
17
32
|
'asyncpg': ('pg', 'aioscrapy.db.aiopg.pg_manager'),
|
|
18
33
|
}
|
|
19
34
|
|
|
35
|
+
# Dictionary to store available database managers
|
|
36
|
+
# 存储可用数据库管理器的字典
|
|
20
37
|
db_manager_map = {}
|
|
21
38
|
|
|
39
|
+
# Dynamically load available database managers based on installed packages
|
|
40
|
+
# 根据已安装的包动态加载可用的数据库管理器
|
|
22
41
|
for module_name, (manager_key, class_path) in DB_MODULE_MAP.items():
|
|
23
42
|
try:
|
|
43
|
+
# Try to import the module to check if it's available
|
|
44
|
+
# 尝试导入模块以检查它是否可用
|
|
24
45
|
import_module(module_name)
|
|
25
46
|
except ImportError:
|
|
47
|
+
# Skip if the module is not installed
|
|
48
|
+
# 如果模块未安装,则跳过
|
|
26
49
|
pass
|
|
27
50
|
else:
|
|
51
|
+
# Load the manager class and add it to the map
|
|
52
|
+
# 加载管理器类并将其添加到映射中
|
|
28
53
|
db_manager_map[manager_key] = load_object(class_path)
|
|
29
54
|
|
|
30
55
|
|
|
31
56
|
class DBManager:
|
|
57
|
+
"""
|
|
58
|
+
Central manager for database connections in aioscrapy.
|
|
59
|
+
aioscrapy中数据库连接的中央管理器。
|
|
60
|
+
|
|
61
|
+
This class provides a unified interface for accessing different types of database
|
|
62
|
+
connections. It manages connection pools for various database types and provides
|
|
63
|
+
methods to initialize connections from settings or configuration dictionaries.
|
|
64
|
+
此类为访问不同类型的数据库连接提供了统一的接口。它管理各种数据库类型的连接池,
|
|
65
|
+
并提供从设置或配置字典初始化连接的方法。
|
|
66
|
+
"""
|
|
32
67
|
|
|
33
68
|
@staticmethod
|
|
34
69
|
def get_manager(db_type: str) -> AbsDBPoolManager:
|
|
70
|
+
"""
|
|
71
|
+
Get the database manager for a specific database type.
|
|
72
|
+
获取特定数据库类型的数据库管理器。
|
|
73
|
+
|
|
74
|
+
Args:
|
|
75
|
+
db_type: The type of database ('redis', 'mysql', 'rabbitmq', 'mongo', 'pg').
|
|
76
|
+
数据库类型('redis'、'mysql'、'rabbitmq'、'mongo'、'pg')。
|
|
77
|
+
|
|
78
|
+
Returns:
|
|
79
|
+
AbsDBPoolManager: The database manager instance.
|
|
80
|
+
数据库管理器实例。
|
|
81
|
+
|
|
82
|
+
Raises:
|
|
83
|
+
AssertionError: If the specified database type is not supported.
|
|
84
|
+
如果不支持指定的数据库类型。
|
|
85
|
+
"""
|
|
35
86
|
manager = db_manager_map.get(db_type)
|
|
36
87
|
assert manager is not None, f"Not support db type:{db_type}"
|
|
37
88
|
return manager
|
|
38
89
|
|
|
39
90
|
def get_pool(self, db_type: str, alias='default') -> Any:
|
|
91
|
+
"""
|
|
92
|
+
Get a connection pool for a specific database type.
|
|
93
|
+
获取特定数据库类型的连接池。
|
|
94
|
+
|
|
95
|
+
Args:
|
|
96
|
+
db_type: The type of database ('redis', 'mysql', 'rabbitmq', 'mongo', 'pg').
|
|
97
|
+
数据库类型('redis'、'mysql'、'rabbitmq'、'mongo'、'pg')。
|
|
98
|
+
alias: The alias of the connection pool, defaults to 'default'.
|
|
99
|
+
连接池的别名,默认为'default'。
|
|
100
|
+
|
|
101
|
+
Returns:
|
|
102
|
+
Any: The connection pool instance.
|
|
103
|
+
连接池实例。
|
|
104
|
+
"""
|
|
40
105
|
manager = self.get_manager(db_type)
|
|
41
106
|
return manager.get_pool(alias)
|
|
42
107
|
|
|
43
108
|
@staticmethod
|
|
44
109
|
async def close_all() -> None:
|
|
110
|
+
"""
|
|
111
|
+
Close all database connections.
|
|
112
|
+
关闭所有数据库连接。
|
|
113
|
+
|
|
114
|
+
This method closes all connection pools for all database types.
|
|
115
|
+
此方法关闭所有数据库类型的所有连接池。
|
|
116
|
+
|
|
117
|
+
Returns:
|
|
118
|
+
None
|
|
119
|
+
"""
|
|
45
120
|
for manager in db_manager_map.values():
|
|
46
121
|
await manager.close_all()
|
|
47
122
|
|
|
48
123
|
@staticmethod
|
|
49
124
|
async def from_dict(db_args: dict) -> None:
|
|
125
|
+
"""
|
|
126
|
+
Initialize database connections from a configuration dictionary.
|
|
127
|
+
从配置字典初始化数据库连接。
|
|
128
|
+
|
|
129
|
+
Args:
|
|
130
|
+
db_args: A dictionary mapping database types to their configuration.
|
|
131
|
+
将数据库类型映射到其配置的字典。
|
|
132
|
+
Example:
|
|
133
|
+
{
|
|
134
|
+
'redis': {'default': {'host': 'localhost', 'port': 6379}},
|
|
135
|
+
'mysql': {'default': {'host': 'localhost', 'user': 'root'}}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
Returns:
|
|
139
|
+
None
|
|
140
|
+
"""
|
|
50
141
|
for db_type, args in db_args.items():
|
|
51
142
|
manager = db_manager_map.get(db_type)
|
|
52
143
|
if manager is None:
|
|
53
144
|
logger.warning(f'Not support db type: {db_type}; Only {", ".join(db_manager_map.keys())} supported')
|
|
145
|
+
continue
|
|
54
146
|
await manager.from_dict(args)
|
|
55
147
|
|
|
56
148
|
@staticmethod
|
|
57
149
|
async def from_settings(settings: aioscrapy.Settings) -> None:
|
|
150
|
+
"""
|
|
151
|
+
Initialize database connections from aioscrapy settings.
|
|
152
|
+
从aioscrapy设置初始化数据库连接。
|
|
153
|
+
|
|
154
|
+
This method initializes all available database managers with the provided settings.
|
|
155
|
+
Each manager will extract its relevant settings from the settings object.
|
|
156
|
+
此方法使用提供的设置初始化所有可用的数据库管理器。
|
|
157
|
+
每个管理器将从设置对象中提取其相关设置。
|
|
158
|
+
|
|
159
|
+
Args:
|
|
160
|
+
settings: The aioscrapy settings object.
|
|
161
|
+
aioscrapy设置对象。
|
|
162
|
+
|
|
163
|
+
Returns:
|
|
164
|
+
None
|
|
165
|
+
"""
|
|
58
166
|
for manager in db_manager_map.values():
|
|
59
167
|
await manager.from_settings(settings)
|
|
60
168
|
|
|
61
169
|
async def from_crawler(self, crawler: "aioscrapy.Crawler") -> None:
|
|
170
|
+
"""
|
|
171
|
+
Initialize database connections from a crawler.
|
|
172
|
+
从爬虫初始化数据库连接。
|
|
173
|
+
|
|
174
|
+
This is a convenience method that extracts settings from the crawler
|
|
175
|
+
and calls from_settings.
|
|
176
|
+
这是一个便捷方法,它从爬虫中提取设置并调用from_settings。
|
|
177
|
+
|
|
178
|
+
Args:
|
|
179
|
+
crawler: The aioscrapy crawler instance.
|
|
180
|
+
aioscrapy爬虫实例。
|
|
181
|
+
|
|
182
|
+
Returns:
|
|
183
|
+
None
|
|
184
|
+
"""
|
|
62
185
|
return await self.from_settings(crawler.settings)
|
|
63
186
|
|
|
64
187
|
def __getattr__(self, db_type: str) -> Any:
|
|
188
|
+
"""
|
|
189
|
+
Access a database manager directly as an attribute.
|
|
190
|
+
直接将数据库管理器作为属性访问。
|
|
191
|
+
|
|
192
|
+
This method allows accessing database managers using attribute syntax:
|
|
193
|
+
db_manager.redis, db_manager.mysql, etc.
|
|
194
|
+
此方法允许使用属性语法访问数据库管理器:
|
|
195
|
+
db_manager.redis、db_manager.mysql等。
|
|
196
|
+
|
|
197
|
+
Args:
|
|
198
|
+
db_type: The type of database ('redis', 'mysql', 'rabbitmq', 'mongo', 'pg').
|
|
199
|
+
数据库类型('redis'、'mysql'、'rabbitmq'、'mongo'、'pg')。
|
|
200
|
+
|
|
201
|
+
Returns:
|
|
202
|
+
AbsDBPoolManager: The database manager instance.
|
|
203
|
+
数据库管理器实例。
|
|
204
|
+
|
|
205
|
+
Raises:
|
|
206
|
+
AttributeError: If the specified database type is not supported.
|
|
207
|
+
如果不支持指定的数据库类型。
|
|
208
|
+
"""
|
|
65
209
|
if db_type not in db_manager_map:
|
|
66
210
|
raise AttributeError(f'Not support db type: {db_type}')
|
|
67
211
|
return db_manager_map[db_type]
|
|
68
212
|
|
|
69
213
|
|
|
214
|
+
# Singleton instance of DBManager
|
|
215
|
+
# DBManager的单例实例
|
|
70
216
|
db_manager = DBManager()
|
|
217
|
+
|
|
218
|
+
# Convenience functions for accessing the singleton
|
|
219
|
+
# 用于访问单例的便捷函数
|
|
71
220
|
get_manager = db_manager.get_manager
|
|
72
221
|
get_pool = db_manager.get_pool
|
aioscrapy/db/absmanager.py
CHANGED
|
@@ -1,47 +1,253 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Abstract database pool manager for aioscrapy.
|
|
3
|
+
aioscrapy的抽象数据库池管理器。
|
|
4
|
+
|
|
5
|
+
This module defines the abstract base class for all database pool managers
|
|
6
|
+
in aioscrapy. It specifies the interface that all database managers must implement.
|
|
7
|
+
此模块定义了aioscrapy中所有数据库池管理器的抽象基类。
|
|
8
|
+
它指定了所有数据库管理器必须实现的接口。
|
|
9
|
+
"""
|
|
10
|
+
|
|
1
11
|
from abc import ABCMeta, abstractmethod
|
|
2
12
|
|
|
3
13
|
import aioscrapy
|
|
4
14
|
|
|
5
15
|
|
|
6
16
|
class AbsDBPoolManager(object, metaclass=ABCMeta):
|
|
17
|
+
"""
|
|
18
|
+
Abstract base class for database connection pool managers.
|
|
19
|
+
数据库连接池管理器的抽象基类。
|
|
20
|
+
|
|
21
|
+
This class defines the interface that all database pool managers must implement.
|
|
22
|
+
It provides methods for creating, accessing, and closing connection pools,
|
|
23
|
+
as well as initializing pools from settings or configuration dictionaries.
|
|
24
|
+
此类定义了所有数据库池管理器必须实现的接口。
|
|
25
|
+
它提供了创建、访问和关闭连接池的方法,以及从设置或配置字典初始化池的方法。
|
|
26
|
+
"""
|
|
7
27
|
|
|
8
28
|
@property
|
|
9
29
|
@abstractmethod
|
|
10
30
|
def _clients(self) -> dict:
|
|
31
|
+
"""
|
|
32
|
+
Dictionary of connection pools managed by this manager.
|
|
33
|
+
此管理器管理的连接池字典。
|
|
34
|
+
|
|
35
|
+
This property should return a dictionary mapping aliases to connection pools.
|
|
36
|
+
Subclasses must implement this property.
|
|
37
|
+
此属性应返回将别名映射到连接池的字典。
|
|
38
|
+
子类必须实现此属性。
|
|
39
|
+
|
|
40
|
+
Returns:
|
|
41
|
+
dict: A dictionary mapping aliases to connection pools.
|
|
42
|
+
将别名映射到连接池的字典。
|
|
43
|
+
"""
|
|
11
44
|
return {}
|
|
12
45
|
|
|
13
46
|
@abstractmethod
|
|
14
47
|
async def create(self, alias: str, params: dict):
|
|
15
|
-
"""
|
|
48
|
+
"""
|
|
49
|
+
Create a new connection pool.
|
|
50
|
+
创建新的连接池。
|
|
51
|
+
|
|
52
|
+
This method creates a new connection pool with the given alias and parameters.
|
|
53
|
+
Subclasses must implement this method.
|
|
54
|
+
此方法使用给定的别名和参数创建新的连接池。
|
|
55
|
+
子类必须实现此方法。
|
|
56
|
+
|
|
57
|
+
Args:
|
|
58
|
+
alias: The alias for the new connection pool.
|
|
59
|
+
新连接池的别名。
|
|
60
|
+
params: The parameters for creating the connection pool.
|
|
61
|
+
创建连接池的参数。
|
|
62
|
+
|
|
63
|
+
Returns:
|
|
64
|
+
The created connection pool.
|
|
65
|
+
创建的连接池。
|
|
66
|
+
"""
|
|
16
67
|
|
|
17
68
|
@abstractmethod
|
|
18
69
|
def get_pool(self, alias: str):
|
|
19
|
-
"""
|
|
70
|
+
"""
|
|
71
|
+
Get a connection pool by its alias.
|
|
72
|
+
通过别名获取连接池。
|
|
73
|
+
|
|
74
|
+
This method retrieves an existing connection pool with the given alias.
|
|
75
|
+
Subclasses must implement this method.
|
|
76
|
+
此方法检索具有给定别名的现有连接池。
|
|
77
|
+
子类必须实现此方法。
|
|
78
|
+
|
|
79
|
+
Args:
|
|
80
|
+
alias: The alias of the connection pool to retrieve.
|
|
81
|
+
要检索的连接池的别名。
|
|
82
|
+
|
|
83
|
+
Returns:
|
|
84
|
+
The connection pool with the given alias.
|
|
85
|
+
具有给定别名的连接池。
|
|
86
|
+
|
|
87
|
+
Raises:
|
|
88
|
+
KeyError: If no connection pool exists with the given alias.
|
|
89
|
+
如果不存在具有给定别名的连接池。
|
|
90
|
+
"""
|
|
20
91
|
|
|
21
92
|
@abstractmethod
|
|
22
93
|
async def close_all(self):
|
|
23
|
-
"""
|
|
94
|
+
"""
|
|
95
|
+
Close all connection pools.
|
|
96
|
+
关闭所有连接池。
|
|
97
|
+
|
|
98
|
+
This method closes all connection pools managed by this manager.
|
|
99
|
+
Subclasses must implement this method.
|
|
100
|
+
此方法关闭此管理器管理的所有连接池。
|
|
101
|
+
子类必须实现此方法。
|
|
102
|
+
|
|
103
|
+
Returns:
|
|
104
|
+
None
|
|
105
|
+
"""
|
|
24
106
|
|
|
25
107
|
@abstractmethod
|
|
26
108
|
async def close(self, alias: str):
|
|
27
|
-
"""
|
|
109
|
+
"""
|
|
110
|
+
Close a specific connection pool.
|
|
111
|
+
关闭特定的连接池。
|
|
112
|
+
|
|
113
|
+
This method closes the connection pool with the given alias.
|
|
114
|
+
Subclasses must implement this method.
|
|
115
|
+
此方法关闭具有给定别名的连接池。
|
|
116
|
+
子类必须实现此方法。
|
|
117
|
+
|
|
118
|
+
Args:
|
|
119
|
+
alias: The alias of the connection pool to close.
|
|
120
|
+
要关闭的连接池的别名。
|
|
121
|
+
|
|
122
|
+
Returns:
|
|
123
|
+
None
|
|
124
|
+
|
|
125
|
+
Raises:
|
|
126
|
+
KeyError: If no connection pool exists with the given alias.
|
|
127
|
+
如果不存在具有给定别名的连接池。
|
|
128
|
+
"""
|
|
28
129
|
|
|
29
130
|
@abstractmethod
|
|
30
131
|
async def from_dict(self, db_args: dict):
|
|
31
|
-
"""
|
|
132
|
+
"""
|
|
133
|
+
Initialize connection pools from a configuration dictionary.
|
|
134
|
+
从配置字典初始化连接池。
|
|
135
|
+
|
|
136
|
+
This method creates connection pools based on the configuration in db_args.
|
|
137
|
+
Subclasses must implement this method.
|
|
138
|
+
此方法根据db_args中的配置创建连接池。
|
|
139
|
+
子类必须实现此方法。
|
|
140
|
+
|
|
141
|
+
Args:
|
|
142
|
+
db_args: A dictionary mapping aliases to connection parameters.
|
|
143
|
+
将别名映射到连接参数的字典。
|
|
144
|
+
Example:
|
|
145
|
+
{
|
|
146
|
+
'default': {'host': 'localhost', 'port': 6379},
|
|
147
|
+
'cache': {'host': 'cache.example.com', 'port': 6379}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
Returns:
|
|
151
|
+
None
|
|
152
|
+
"""
|
|
32
153
|
|
|
33
154
|
@abstractmethod
|
|
34
155
|
async def from_settings(self, settings: aioscrapy.Settings):
|
|
35
|
-
"""
|
|
156
|
+
"""
|
|
157
|
+
Initialize connection pools from aioscrapy settings.
|
|
158
|
+
从aioscrapy设置初始化连接池。
|
|
159
|
+
|
|
160
|
+
This method creates connection pools based on the configuration in settings.
|
|
161
|
+
Subclasses must implement this method.
|
|
162
|
+
此方法根据settings中的配置创建连接池。
|
|
163
|
+
子类必须实现此方法。
|
|
164
|
+
|
|
165
|
+
Args:
|
|
166
|
+
settings: The aioscrapy settings object.
|
|
167
|
+
aioscrapy设置对象。
|
|
168
|
+
|
|
169
|
+
Returns:
|
|
170
|
+
None
|
|
171
|
+
"""
|
|
36
172
|
|
|
37
173
|
async def from_crawler(self, crawler: "aioscrapy.Crawler"):
|
|
174
|
+
"""
|
|
175
|
+
Initialize connection pools from a crawler.
|
|
176
|
+
从爬虫初始化连接池。
|
|
177
|
+
|
|
178
|
+
This is a convenience method that extracts settings from the crawler
|
|
179
|
+
and calls from_settings.
|
|
180
|
+
这是一个便捷方法,它从爬虫中提取设置并调用from_settings。
|
|
181
|
+
|
|
182
|
+
Args:
|
|
183
|
+
crawler: The aioscrapy crawler instance.
|
|
184
|
+
aioscrapy爬虫实例。
|
|
185
|
+
|
|
186
|
+
Returns:
|
|
187
|
+
None
|
|
188
|
+
"""
|
|
38
189
|
return await self.from_settings(crawler.settings)
|
|
39
190
|
|
|
40
191
|
def __call__(self, alias: str):
|
|
192
|
+
"""
|
|
193
|
+
Make the manager callable to get a connection pool.
|
|
194
|
+
使管理器可调用以获取连接池。
|
|
195
|
+
|
|
196
|
+
This method allows using the manager as a function to get a connection pool:
|
|
197
|
+
manager('default')
|
|
198
|
+
此方法允许将管理器用作函数以获取连接池:
|
|
199
|
+
manager('default')
|
|
200
|
+
|
|
201
|
+
Args:
|
|
202
|
+
alias: The alias of the connection pool to retrieve.
|
|
203
|
+
要检索的连接池的别名。
|
|
204
|
+
|
|
205
|
+
Returns:
|
|
206
|
+
The connection pool with the given alias.
|
|
207
|
+
具有给定别名的连接池。
|
|
208
|
+
"""
|
|
41
209
|
return self.get_pool(alias)
|
|
42
210
|
|
|
43
211
|
def __getitem__(self, alias: str):
|
|
212
|
+
"""
|
|
213
|
+
Allow dictionary-style access to connection pools.
|
|
214
|
+
允许字典样式访问连接池。
|
|
215
|
+
|
|
216
|
+
This method allows accessing connection pools using dictionary syntax:
|
|
217
|
+
manager['default']
|
|
218
|
+
此方法允许使用字典语法访问连接池:
|
|
219
|
+
manager['default']
|
|
220
|
+
|
|
221
|
+
Args:
|
|
222
|
+
alias: The alias of the connection pool to retrieve.
|
|
223
|
+
要检索的连接池的别名。
|
|
224
|
+
|
|
225
|
+
Returns:
|
|
226
|
+
The connection pool with the given alias.
|
|
227
|
+
具有给定别名的连接池。
|
|
228
|
+
"""
|
|
44
229
|
return self.get_pool(alias)
|
|
45
230
|
|
|
46
231
|
def __getattr__(self, alias: str):
|
|
232
|
+
"""
|
|
233
|
+
Allow attribute-style access to connection pools.
|
|
234
|
+
允许属性样式访问连接池。
|
|
235
|
+
|
|
236
|
+
This method allows accessing connection pools using attribute syntax:
|
|
237
|
+
manager.default
|
|
238
|
+
此方法允许使用属性语法访问连接池:
|
|
239
|
+
manager.default
|
|
240
|
+
|
|
241
|
+
Args:
|
|
242
|
+
alias: The alias of the connection pool to retrieve.
|
|
243
|
+
要检索的连接池的别名。
|
|
244
|
+
|
|
245
|
+
Returns:
|
|
246
|
+
The connection pool with the given alias.
|
|
247
|
+
具有给定别名的连接池。
|
|
248
|
+
|
|
249
|
+
Raises:
|
|
250
|
+
AttributeError: If no connection pool exists with the given alias.
|
|
251
|
+
如果不存在具有给定别名的连接池。
|
|
252
|
+
"""
|
|
47
253
|
return self.get_pool(alias)
|