1
0
This commit is contained in:
Jon Michael Aanes 2024-03-11 20:41:04 +01:00
parent 2c18faefe5
commit 8f678c341f
Signed by: Jmaa
SSH Key Fingerprint: SHA256:Ab0GfHGCblESJx7JRE4fj4bFy/KRpeLhi41y4pF3sNA
3 changed files with 14 additions and 7 deletions

View File

@ -1,4 +1,6 @@
'''Utility module for setting up ratelimiting on third-party sessions.''' """Utility module for setting up ratelimiting on third-party sessions."""
from _version import __version__
import logging import logging
@ -13,13 +15,15 @@ except ImportError:
) )
def setup_limiter(session: requests.Session, url_prefix: str, **limiter_args): requests.Session: def setup_limiter(
''' session: requests.Session, url_prefix: str, **limiter_args
) -> requests.Session:
"""
Initializes limiter on session for the given domain with the given Initializes limiter on session for the given domain with the given
settings. settings.
Will always return the given session itself. Will always return the given session itself.
''' """
if requests_ratelimiter: if requests_ratelimiter:
session.mount(url_prefix, requests_ratelimiter.LimiterAdapter(**limiter_args)) session.mount(url_prefix, requests_ratelimiter.LimiterAdapter(**limiter_args))
return session return session

View File

@ -0,0 +1 @@
__version__ = '0.1.0'

View File

@ -7,18 +7,20 @@ PACKAGE_NAME = 'requests_util'
with open('README.md', 'r') as f: with open('README.md', 'r') as f:
readme = f.read() readme = f.read()
with open(PACKAGE_NAME+'/_version.py', 'r') as f: with open(PACKAGE_NAME + '/_version.py', 'r') as f:
text = f.read() text = f.read()
match = re.match(r'^__version__\s*=\s*(["\'])([\d\.]+)\1$', text) match = re.match(r'^__version__\s*=\s*(["\'])([\d\.]+)\1$', text)
version = match.group(2) version = match.group(2)
del match, text del match, text
def get_short_description(readme: str): def get_short_description(readme: str):
readme = re.sub(r'#+[^\n]*\n+', '', readme) readme = re.sub(r'#+[^\n]*\n+', '', readme)
m = re.search(r'^\s*(\w+[\w\s,]+\.)', readme) m = re.search(r'^\s*(\w+[\w\s,]+\.)', readme)
readme = m.group(1) readme = m.group(1)
return readme return readme
setup( setup(
name=PACKAGE_NAME, name=PACKAGE_NAME,
version=version, version=version,
@ -27,10 +29,10 @@ setup(
long_description_content_type='text/markdown', long_description_content_type='text/markdown',
author='Jmaa', author='Jmaa',
author_email='jonjmaa@gmail.com', author_email='jonjmaa@gmail.com',
url='https://gitfub.space/Jmaa/'+PACKAGE_NAME, url='https://gitfub.space/Jmaa/' + PACKAGE_NAME,
packages=[PACKAGE_NAME], packages=[PACKAGE_NAME],
install_requires=['requests'], install_requires=['requests'],
extras_require = { extras_require={
'Request ratelimiting': ['requests_ratelimiter'], 'Request ratelimiting': ['requests_ratelimiter'],
'Request caching': ['requests_cache'], 'Request caching': ['requests_cache'],
}, },