provide-foundation 0.0.0.dev1__py3-none-any.whl → 0.0.0.dev2__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.
- provide/foundation/__init__.py +29 -3
- provide/foundation/archive/operations.py +4 -6
- provide/foundation/cli/__init__.py +2 -2
- provide/foundation/cli/commands/deps.py +13 -7
- provide/foundation/cli/commands/logs/__init__.py +1 -1
- provide/foundation/cli/commands/logs/query.py +1 -1
- provide/foundation/cli/commands/logs/send.py +1 -1
- provide/foundation/cli/commands/logs/tail.py +1 -1
- provide/foundation/cli/decorators.py +11 -10
- provide/foundation/cli/main.py +1 -1
- provide/foundation/cli/testing.py +2 -35
- provide/foundation/cli/utils.py +21 -17
- provide/foundation/config/__init__.py +35 -2
- provide/foundation/config/converters.py +479 -0
- provide/foundation/config/defaults.py +67 -0
- provide/foundation/config/env.py +4 -19
- provide/foundation/config/loader.py +9 -3
- provide/foundation/console/input.py +5 -5
- provide/foundation/console/output.py +35 -13
- provide/foundation/context/__init__.py +8 -4
- provide/foundation/context/core.py +85 -109
- provide/foundation/crypto/certificates/operations.py +1 -1
- provide/foundation/errors/__init__.py +2 -3
- provide/foundation/errors/decorators.py +0 -231
- provide/foundation/errors/types.py +0 -97
- provide/foundation/file/directory.py +13 -22
- provide/foundation/file/lock.py +3 -1
- provide/foundation/hub/components.py +72 -384
- provide/foundation/hub/config.py +151 -0
- provide/foundation/hub/discovery.py +62 -0
- provide/foundation/hub/handlers.py +81 -0
- provide/foundation/hub/lifecycle.py +194 -0
- provide/foundation/hub/manager.py +4 -4
- provide/foundation/hub/processors.py +44 -0
- provide/foundation/integrations/__init__.py +11 -0
- provide/foundation/{observability → integrations}/openobserve/__init__.py +10 -7
- provide/foundation/{observability → integrations}/openobserve/auth.py +1 -1
- provide/foundation/{observability → integrations}/openobserve/client.py +12 -12
- provide/foundation/{observability → integrations}/openobserve/commands.py +3 -3
- provide/foundation/integrations/openobserve/config.py +37 -0
- provide/foundation/{observability → integrations}/openobserve/formatters.py +1 -1
- provide/foundation/{observability → integrations}/openobserve/otlp.py +1 -1
- provide/foundation/{observability → integrations}/openobserve/search.py +2 -2
- provide/foundation/{observability → integrations}/openobserve/streaming.py +4 -4
- provide/foundation/logger/config/logging.py +68 -298
- provide/foundation/logger/config/telemetry.py +41 -121
- provide/foundation/logger/setup/coordinator.py +1 -1
- provide/foundation/observability/__init__.py +2 -2
- provide/foundation/process/__init__.py +9 -0
- provide/foundation/process/exit.py +47 -0
- provide/foundation/process/lifecycle.py +33 -33
- provide/foundation/resilience/__init__.py +35 -0
- provide/foundation/resilience/circuit.py +164 -0
- provide/foundation/resilience/decorators.py +220 -0
- provide/foundation/resilience/fallback.py +193 -0
- provide/foundation/resilience/retry.py +325 -0
- provide/foundation/streams/config.py +79 -0
- provide/foundation/streams/console.py +7 -8
- provide/foundation/streams/core.py +6 -3
- provide/foundation/streams/file.py +12 -2
- provide/foundation/testing/__init__.py +7 -2
- provide/foundation/testing/cli.py +30 -17
- provide/foundation/testing/common/__init__.py +0 -2
- provide/foundation/testing/common/fixtures.py +0 -27
- provide/foundation/testing/file/content_fixtures.py +316 -0
- provide/foundation/testing/file/directory_fixtures.py +107 -0
- provide/foundation/testing/file/fixtures.py +45 -516
- provide/foundation/testing/file/special_fixtures.py +153 -0
- provide/foundation/testing/logger.py +76 -0
- provide/foundation/testing/process/async_fixtures.py +405 -0
- provide/foundation/testing/process/fixtures.py +50 -571
- provide/foundation/testing/process/subprocess_fixtures.py +209 -0
- provide/foundation/testing/threading/basic_fixtures.py +101 -0
- provide/foundation/testing/threading/data_fixtures.py +99 -0
- provide/foundation/testing/threading/execution_fixtures.py +263 -0
- provide/foundation/testing/threading/fixtures.py +34 -500
- provide/foundation/testing/threading/sync_fixtures.py +97 -0
- provide/foundation/testing/time/fixtures.py +4 -4
- provide/foundation/tools/cache.py +8 -6
- provide/foundation/tools/downloader.py +23 -12
- provide/foundation/tracer/spans.py +2 -2
- provide/foundation/transport/config.py +26 -95
- provide/foundation/transport/middleware.py +30 -36
- provide/foundation/utils/deps.py +14 -12
- provide/foundation/utils/parsing.py +49 -4
- {provide_foundation-0.0.0.dev1.dist-info → provide_foundation-0.0.0.dev2.dist-info}/METADATA +1 -1
- {provide_foundation-0.0.0.dev1.dist-info → provide_foundation-0.0.0.dev2.dist-info}/RECORD +93 -68
- /provide/foundation/{observability → integrations}/openobserve/exceptions.py +0 -0
- /provide/foundation/{observability → integrations}/openobserve/models.py +0 -0
- {provide_foundation-0.0.0.dev1.dist-info → provide_foundation-0.0.0.dev2.dist-info}/WHEEL +0 -0
- {provide_foundation-0.0.0.dev1.dist-info → provide_foundation-0.0.0.dev2.dist-info}/entry_points.txt +0 -0
- {provide_foundation-0.0.0.dev1.dist-info → provide_foundation-0.0.0.dev2.dist-info}/licenses/LICENSE +0 -0
- {provide_foundation-0.0.0.dev1.dist-info → provide_foundation-0.0.0.dev2.dist-info}/top_level.txt +0 -0
@@ -9,6 +9,8 @@ and ensuring test isolation for the Foundation logging system.
|
|
9
9
|
"""
|
10
10
|
|
11
11
|
import structlog
|
12
|
+
import pytest
|
13
|
+
from unittest.mock import Mock
|
12
14
|
|
13
15
|
from provide.foundation.logger.core import (
|
14
16
|
_LAZY_SETUP_STATE,
|
@@ -17,6 +19,78 @@ from provide.foundation.logger.core import (
|
|
17
19
|
from provide.foundation.streams.file import reset_streams
|
18
20
|
|
19
21
|
|
22
|
+
@pytest.fixture
|
23
|
+
def mock_logger():
|
24
|
+
"""
|
25
|
+
Comprehensive mock logger for testing.
|
26
|
+
|
27
|
+
Provides compatibility with both stdlib logging and structlog interfaces,
|
28
|
+
including method call tracking and common logger attributes.
|
29
|
+
|
30
|
+
Returns:
|
31
|
+
Mock logger with debug, info, warning, error methods and structlog compatibility.
|
32
|
+
"""
|
33
|
+
logger = Mock()
|
34
|
+
logger.debug = Mock()
|
35
|
+
logger.info = Mock()
|
36
|
+
logger.warning = Mock()
|
37
|
+
logger.warn = Mock() # Alias for warning
|
38
|
+
logger.error = Mock()
|
39
|
+
logger.exception = Mock()
|
40
|
+
logger.critical = Mock()
|
41
|
+
logger.fatal = Mock() # Alias for critical
|
42
|
+
|
43
|
+
# Add common logger attributes
|
44
|
+
logger.name = "mock_logger"
|
45
|
+
logger.level = 10 # DEBUG level
|
46
|
+
logger.handlers = []
|
47
|
+
logger.disabled = False
|
48
|
+
|
49
|
+
# Add structlog compatibility methods
|
50
|
+
logger.bind = Mock(return_value=logger)
|
51
|
+
logger.unbind = Mock(return_value=logger)
|
52
|
+
logger.new = Mock(return_value=logger)
|
53
|
+
logger.msg = Mock() # Alternative to info
|
54
|
+
|
55
|
+
# Add trace method for Foundation's extended logging
|
56
|
+
logger.trace = Mock()
|
57
|
+
|
58
|
+
return logger
|
59
|
+
|
60
|
+
|
61
|
+
def mock_logger_factory():
|
62
|
+
"""
|
63
|
+
Factory function to create mock loggers outside of pytest context.
|
64
|
+
|
65
|
+
Useful for unit tests that need a mock logger but aren't using pytest fixtures.
|
66
|
+
|
67
|
+
Returns:
|
68
|
+
Mock logger with the same interface as the pytest fixture.
|
69
|
+
"""
|
70
|
+
logger = Mock()
|
71
|
+
logger.debug = Mock()
|
72
|
+
logger.info = Mock()
|
73
|
+
logger.warning = Mock()
|
74
|
+
logger.warn = Mock()
|
75
|
+
logger.error = Mock()
|
76
|
+
logger.exception = Mock()
|
77
|
+
logger.critical = Mock()
|
78
|
+
logger.fatal = Mock()
|
79
|
+
|
80
|
+
logger.name = "mock_logger"
|
81
|
+
logger.level = 10
|
82
|
+
logger.handlers = []
|
83
|
+
logger.disabled = False
|
84
|
+
|
85
|
+
logger.bind = Mock(return_value=logger)
|
86
|
+
logger.unbind = Mock(return_value=logger)
|
87
|
+
logger.new = Mock(return_value=logger)
|
88
|
+
logger.msg = Mock()
|
89
|
+
logger.trace = Mock()
|
90
|
+
|
91
|
+
return logger
|
92
|
+
|
93
|
+
|
20
94
|
def _reset_opentelemetry_providers() -> None:
|
21
95
|
"""
|
22
96
|
Reset OpenTelemetry providers to uninitialized state.
|
@@ -133,4 +207,6 @@ def reset_foundation_setup_for_testing() -> None:
|
|
133
207
|
__all__ = [
|
134
208
|
"reset_foundation_setup_for_testing",
|
135
209
|
"reset_foundation_state",
|
210
|
+
"mock_logger",
|
211
|
+
"mock_logger_factory",
|
136
212
|
]
|
@@ -0,0 +1,405 @@
|
|
1
|
+
"""
|
2
|
+
Async-specific test fixtures for process testing.
|
3
|
+
|
4
|
+
Provides fixtures for testing async operations, event loops, and
|
5
|
+
async context management across the provide-io ecosystem.
|
6
|
+
"""
|
7
|
+
|
8
|
+
import asyncio
|
9
|
+
from unittest.mock import AsyncMock
|
10
|
+
from collections.abc import AsyncGenerator, Callable
|
11
|
+
|
12
|
+
import pytest
|
13
|
+
|
14
|
+
|
15
|
+
@pytest.fixture
|
16
|
+
async def clean_event_loop() -> AsyncGenerator[None, None]:
|
17
|
+
"""
|
18
|
+
Ensure clean event loop for async tests.
|
19
|
+
|
20
|
+
Cancels all pending tasks after the test to prevent event loop issues.
|
21
|
+
|
22
|
+
Yields:
|
23
|
+
None - fixture for test setup/teardown.
|
24
|
+
"""
|
25
|
+
yield
|
26
|
+
|
27
|
+
# Clean up any pending tasks
|
28
|
+
loop = asyncio.get_event_loop()
|
29
|
+
pending = asyncio.all_tasks(loop)
|
30
|
+
|
31
|
+
for task in pending:
|
32
|
+
if not task.done():
|
33
|
+
task.cancel()
|
34
|
+
|
35
|
+
# Wait for all tasks to complete cancellation
|
36
|
+
if pending:
|
37
|
+
await asyncio.gather(*pending, return_exceptions=True)
|
38
|
+
|
39
|
+
|
40
|
+
@pytest.fixture
|
41
|
+
def async_timeout() -> Callable[[float], asyncio.Task]:
|
42
|
+
"""
|
43
|
+
Provide configurable timeout wrapper for async operations.
|
44
|
+
|
45
|
+
Returns:
|
46
|
+
A function that wraps async operations with a timeout.
|
47
|
+
"""
|
48
|
+
def _timeout_wrapper(coro, seconds: float = 5.0):
|
49
|
+
"""
|
50
|
+
Wrap a coroutine with a timeout.
|
51
|
+
|
52
|
+
Args:
|
53
|
+
coro: Coroutine to wrap
|
54
|
+
seconds: Timeout in seconds
|
55
|
+
|
56
|
+
Returns:
|
57
|
+
Result of the coroutine or raises asyncio.TimeoutError
|
58
|
+
"""
|
59
|
+
return asyncio.wait_for(coro, timeout=seconds)
|
60
|
+
|
61
|
+
return _timeout_wrapper
|
62
|
+
|
63
|
+
|
64
|
+
@pytest.fixture
|
65
|
+
def event_loop_policy():
|
66
|
+
"""
|
67
|
+
Set event loop policy for tests to avoid conflicts.
|
68
|
+
|
69
|
+
Returns:
|
70
|
+
New event loop policy for isolated testing.
|
71
|
+
"""
|
72
|
+
policy = asyncio.get_event_loop_policy()
|
73
|
+
new_policy = asyncio.DefaultEventLoopPolicy()
|
74
|
+
asyncio.set_event_loop_policy(new_policy)
|
75
|
+
|
76
|
+
yield new_policy
|
77
|
+
|
78
|
+
# Restore original policy
|
79
|
+
asyncio.set_event_loop_policy(policy)
|
80
|
+
|
81
|
+
|
82
|
+
@pytest.fixture
|
83
|
+
async def async_context_manager():
|
84
|
+
"""
|
85
|
+
Factory for creating mock async context managers.
|
86
|
+
|
87
|
+
Returns:
|
88
|
+
Function that creates configured async context manager mocks.
|
89
|
+
"""
|
90
|
+
def _create_async_cm(enter_value=None, exit_value=None):
|
91
|
+
"""
|
92
|
+
Create a mock async context manager.
|
93
|
+
|
94
|
+
Args:
|
95
|
+
enter_value: Value to return from __aenter__
|
96
|
+
exit_value: Value to return from __aexit__
|
97
|
+
|
98
|
+
Returns:
|
99
|
+
AsyncMock configured as context manager
|
100
|
+
"""
|
101
|
+
mock_cm = AsyncMock()
|
102
|
+
mock_cm.__aenter__ = AsyncMock(return_value=enter_value)
|
103
|
+
mock_cm.__aexit__ = AsyncMock(return_value=exit_value)
|
104
|
+
return mock_cm
|
105
|
+
|
106
|
+
return _create_async_cm
|
107
|
+
|
108
|
+
|
109
|
+
@pytest.fixture
|
110
|
+
async def async_iterator():
|
111
|
+
"""
|
112
|
+
Factory for creating mock async iterators.
|
113
|
+
|
114
|
+
Returns:
|
115
|
+
Function that creates async iterator mocks with specified values.
|
116
|
+
"""
|
117
|
+
def _create_async_iter(values):
|
118
|
+
"""
|
119
|
+
Create a mock async iterator.
|
120
|
+
|
121
|
+
Args:
|
122
|
+
values: List of values to yield
|
123
|
+
|
124
|
+
Returns:
|
125
|
+
Async iterator that yields the specified values
|
126
|
+
"""
|
127
|
+
class AsyncIterator:
|
128
|
+
def __init__(self, vals):
|
129
|
+
self.vals = vals
|
130
|
+
self.index = 0
|
131
|
+
|
132
|
+
def __aiter__(self):
|
133
|
+
return self
|
134
|
+
|
135
|
+
async def __anext__(self):
|
136
|
+
if self.index >= len(self.vals):
|
137
|
+
raise StopAsyncIteration
|
138
|
+
value = self.vals[self.index]
|
139
|
+
self.index += 1
|
140
|
+
return value
|
141
|
+
|
142
|
+
return AsyncIterator(values)
|
143
|
+
|
144
|
+
return _create_async_iter
|
145
|
+
|
146
|
+
|
147
|
+
@pytest.fixture
|
148
|
+
def async_queue():
|
149
|
+
"""
|
150
|
+
Create an async queue for testing producer/consumer patterns.
|
151
|
+
|
152
|
+
Returns:
|
153
|
+
asyncio.Queue instance for testing.
|
154
|
+
"""
|
155
|
+
return asyncio.Queue()
|
156
|
+
|
157
|
+
|
158
|
+
@pytest.fixture
|
159
|
+
async def async_lock():
|
160
|
+
"""
|
161
|
+
Create an async lock for testing synchronization.
|
162
|
+
|
163
|
+
Returns:
|
164
|
+
asyncio.Lock instance for testing.
|
165
|
+
"""
|
166
|
+
return asyncio.Lock()
|
167
|
+
|
168
|
+
|
169
|
+
@pytest.fixture
|
170
|
+
def mock_async_sleep():
|
171
|
+
"""
|
172
|
+
Mock asyncio.sleep to speed up tests.
|
173
|
+
|
174
|
+
Returns:
|
175
|
+
Mock that replaces asyncio.sleep with instant return.
|
176
|
+
"""
|
177
|
+
original_sleep = asyncio.sleep
|
178
|
+
|
179
|
+
async def instant_sleep(seconds):
|
180
|
+
"""Sleep replacement that returns immediately."""
|
181
|
+
return None
|
182
|
+
|
183
|
+
asyncio.sleep = instant_sleep
|
184
|
+
|
185
|
+
yield instant_sleep
|
186
|
+
|
187
|
+
# Restore original
|
188
|
+
asyncio.sleep = original_sleep
|
189
|
+
|
190
|
+
|
191
|
+
@pytest.fixture
|
192
|
+
def async_gather_helper():
|
193
|
+
"""
|
194
|
+
Helper for testing asyncio.gather operations.
|
195
|
+
|
196
|
+
Returns:
|
197
|
+
Function to gather async results with error handling.
|
198
|
+
"""
|
199
|
+
async def _gather(*coroutines, return_exceptions: bool = False):
|
200
|
+
"""
|
201
|
+
Gather results from multiple coroutines.
|
202
|
+
|
203
|
+
Args:
|
204
|
+
*coroutines: Coroutines to gather
|
205
|
+
return_exceptions: Whether to return exceptions as results
|
206
|
+
|
207
|
+
Returns:
|
208
|
+
List of results from coroutines
|
209
|
+
"""
|
210
|
+
return await asyncio.gather(*coroutines, return_exceptions=return_exceptions)
|
211
|
+
|
212
|
+
return _gather
|
213
|
+
|
214
|
+
|
215
|
+
@pytest.fixture
|
216
|
+
def async_task_group():
|
217
|
+
"""
|
218
|
+
Manage a group of async tasks with cleanup.
|
219
|
+
|
220
|
+
Returns:
|
221
|
+
AsyncTaskGroup instance for managing tasks.
|
222
|
+
"""
|
223
|
+
class AsyncTaskGroup:
|
224
|
+
def __init__(self):
|
225
|
+
self.tasks = []
|
226
|
+
|
227
|
+
def create_task(self, coro):
|
228
|
+
"""Create and track a task."""
|
229
|
+
task = asyncio.create_task(coro)
|
230
|
+
self.tasks.append(task)
|
231
|
+
return task
|
232
|
+
|
233
|
+
async def wait_all(self, timeout: float = None):
|
234
|
+
"""Wait for all tasks to complete."""
|
235
|
+
if not self.tasks:
|
236
|
+
return []
|
237
|
+
|
238
|
+
done, pending = await asyncio.wait(
|
239
|
+
self.tasks,
|
240
|
+
timeout=timeout,
|
241
|
+
return_when=asyncio.ALL_COMPLETED
|
242
|
+
)
|
243
|
+
|
244
|
+
if pending:
|
245
|
+
for task in pending:
|
246
|
+
task.cancel()
|
247
|
+
|
248
|
+
results = []
|
249
|
+
for task in done:
|
250
|
+
try:
|
251
|
+
results.append(task.result())
|
252
|
+
except Exception as e:
|
253
|
+
results.append(e)
|
254
|
+
|
255
|
+
return results
|
256
|
+
|
257
|
+
async def cancel_all(self):
|
258
|
+
"""Cancel all tasks."""
|
259
|
+
for task in self.tasks:
|
260
|
+
if not task.done():
|
261
|
+
task.cancel()
|
262
|
+
|
263
|
+
if self.tasks:
|
264
|
+
await asyncio.gather(*self.tasks, return_exceptions=True)
|
265
|
+
|
266
|
+
async def __aenter__(self):
|
267
|
+
return self
|
268
|
+
|
269
|
+
async def __aexit__(self, *args):
|
270
|
+
await self.cancel_all()
|
271
|
+
|
272
|
+
return AsyncTaskGroup()
|
273
|
+
|
274
|
+
|
275
|
+
@pytest.fixture
|
276
|
+
def async_condition_waiter():
|
277
|
+
"""
|
278
|
+
Helper for waiting on async conditions in tests.
|
279
|
+
|
280
|
+
Returns:
|
281
|
+
Function to wait for conditions with timeout.
|
282
|
+
"""
|
283
|
+
async def _wait_for(condition: Callable[[], bool], timeout: float = 5.0, interval: float = 0.1):
|
284
|
+
"""
|
285
|
+
Wait for a condition to become true.
|
286
|
+
|
287
|
+
Args:
|
288
|
+
condition: Function that returns True when condition is met
|
289
|
+
timeout: Maximum wait time
|
290
|
+
interval: Check interval
|
291
|
+
|
292
|
+
Returns:
|
293
|
+
True if condition met, False if timeout
|
294
|
+
"""
|
295
|
+
start = asyncio.get_event_loop().time()
|
296
|
+
|
297
|
+
while asyncio.get_event_loop().time() - start < timeout:
|
298
|
+
if condition():
|
299
|
+
return True
|
300
|
+
await asyncio.sleep(interval)
|
301
|
+
|
302
|
+
return False
|
303
|
+
|
304
|
+
return _wait_for
|
305
|
+
|
306
|
+
|
307
|
+
@pytest.fixture
|
308
|
+
def async_pipeline():
|
309
|
+
"""
|
310
|
+
Create an async pipeline for testing data flow.
|
311
|
+
|
312
|
+
Returns:
|
313
|
+
AsyncPipeline instance for chaining async operations.
|
314
|
+
"""
|
315
|
+
class AsyncPipeline:
|
316
|
+
def __init__(self):
|
317
|
+
self.stages = []
|
318
|
+
self.results = []
|
319
|
+
|
320
|
+
def add_stage(self, func: Callable):
|
321
|
+
"""Add a processing stage."""
|
322
|
+
self.stages.append(func)
|
323
|
+
return self
|
324
|
+
|
325
|
+
async def process(self, data):
|
326
|
+
"""Process data through all stages."""
|
327
|
+
result = data
|
328
|
+
for stage in self.stages:
|
329
|
+
if asyncio.iscoroutinefunction(stage):
|
330
|
+
result = await stage(result)
|
331
|
+
else:
|
332
|
+
result = stage(result)
|
333
|
+
self.results.append(result)
|
334
|
+
return result
|
335
|
+
|
336
|
+
async def process_batch(self, items: list):
|
337
|
+
"""Process multiple items."""
|
338
|
+
tasks = [self.process(item) for item in items]
|
339
|
+
return await asyncio.gather(*tasks)
|
340
|
+
|
341
|
+
def clear(self):
|
342
|
+
"""Clear stages and results."""
|
343
|
+
self.stages.clear()
|
344
|
+
self.results.clear()
|
345
|
+
|
346
|
+
return AsyncPipeline()
|
347
|
+
|
348
|
+
|
349
|
+
@pytest.fixture
|
350
|
+
def async_rate_limiter():
|
351
|
+
"""
|
352
|
+
Create an async rate limiter for testing.
|
353
|
+
|
354
|
+
Returns:
|
355
|
+
AsyncRateLimiter instance for controlling request rates.
|
356
|
+
"""
|
357
|
+
class AsyncRateLimiter:
|
358
|
+
def __init__(self, rate: int = 10, per: float = 1.0):
|
359
|
+
self.rate = rate
|
360
|
+
self.per = per
|
361
|
+
self.allowance = rate
|
362
|
+
self.last_check = asyncio.get_event_loop().time()
|
363
|
+
|
364
|
+
async def acquire(self):
|
365
|
+
"""Acquire permission to proceed."""
|
366
|
+
current = asyncio.get_event_loop().time()
|
367
|
+
time_passed = current - self.last_check
|
368
|
+
self.last_check = current
|
369
|
+
|
370
|
+
self.allowance += time_passed * (self.rate / self.per)
|
371
|
+
if self.allowance > self.rate:
|
372
|
+
self.allowance = self.rate
|
373
|
+
|
374
|
+
if self.allowance < 1.0:
|
375
|
+
sleep_time = (1.0 - self.allowance) * (self.per / self.rate)
|
376
|
+
await asyncio.sleep(sleep_time)
|
377
|
+
self.allowance = 0.0
|
378
|
+
else:
|
379
|
+
self.allowance -= 1.0
|
380
|
+
|
381
|
+
async def __aenter__(self):
|
382
|
+
await self.acquire()
|
383
|
+
return self
|
384
|
+
|
385
|
+
async def __aexit__(self, *args):
|
386
|
+
pass
|
387
|
+
|
388
|
+
return AsyncRateLimiter()
|
389
|
+
|
390
|
+
|
391
|
+
__all__ = [
|
392
|
+
"clean_event_loop",
|
393
|
+
"async_timeout",
|
394
|
+
"event_loop_policy",
|
395
|
+
"async_context_manager",
|
396
|
+
"async_iterator",
|
397
|
+
"async_queue",
|
398
|
+
"async_lock",
|
399
|
+
"mock_async_sleep",
|
400
|
+
"async_gather_helper",
|
401
|
+
"async_task_group",
|
402
|
+
"async_condition_waiter",
|
403
|
+
"async_pipeline",
|
404
|
+
"async_rate_limiter",
|
405
|
+
]
|