aiobtclientapi.utils
Utilities
Functions
- async aiobtclientapi.utils.download(url, to=None, maxsize=None)[source]
Download URL to file or return
bytes- Parameters:
url – URL to download
to – File path to store bytes from url in
maxsize – Maximum allowed
Content-Lengthor None for unlimited download size
- Raises:
ReadError – if anything goes wrong
- aiobtclientapi.utils.is_infohash(string)[source]
Return True if string looks like a torrent infohash, False otherwise
- aiobtclientapi.utils.is_magnet(string)[source]
Return True if string is a magnet URI, False otherwise
- aiobtclientapi.utils.is_url(string)[source]
Return True if string looks like an URL, False otherwise
- async aiobtclientapi.utils.merge_async_generators(*generators)[source]
Combine multiple asynchronous generators into one
Every generated value is wrapped in a coroutine that returns it or raises an exception raised by the generator.
Example:
>>> async for coro in merge_async_generators(a, b, c): >>> try: >>> print('Good value:', await coro) >>> except ValueError as e: >>> print('Bad value:', e)
- aiobtclientapi.utils.read_bytes(path, maxsize=None)[source]
Return
bytesfrom file- Parameters:
path – Path to file
maxsize – Maximum size of path in bytes
- Raises:
ReadError – if reading path fails or size of path exceeds maxsize bytes
- aiobtclientapi.utils.without_None_values(dct)[source]
Return copy of dct without the keys that map to None
Classes
- class aiobtclientapi.utils.DynamicInterval(min, max, progress_getter, name=None)[source]
Bases:
objectGenerate intervals from min to max depending on some ongoing operation
- Parameters:
min – Minimum interval
max – Maximum interval
progress_getter –
Callable that takes no arguments and returns a number from 0 to 100
As progress approaches 100, the interval returned by
next()gets closer to min.name – Any object with a descriptive string representation (only used for debugging)
- property progress
Most recent return value from progress_getter
- class aiobtclientapi.utils.Infohash(string)[source]
Bases:
strCase-insensitive string of exactly 40 hexadecimal digits
- class aiobtclientapi.utils.Monitor(call, attribute=None, interval=1, timeout=None)[source]
Bases:
objectContinuously call awaitable until it returns a predefined value
- Parameters:
call – Any awaitable that doesn’t take any arguments
attribute – Attribute from the return value of call to act on, e.g. if call returns a
Responseobject and you want to monitor itssuccessattributeinterval (
DynamicIntervalinstance orint) – Seconds to sleep before calling call againtimeout – Maximum number of seconds overall before
TimeoutErroris raised
- async return_value_equals(value, negate=False)[source]
Block until
await call() == value- Parameters:
negate – Invert the result of the comparison
- async return_value_is(value, negate=False)[source]
Block until
await call() is value- Parameters:
negate – Invert the result of the comparison