mirror of
https://github.com/gogcom/galaxy-integrations-python-api.git
synced 2026-01-01 11:28:12 -05:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
701d3cf522 | ||
|
|
c8083b9006 | ||
|
|
0608ade6d3 | ||
|
|
c349a3df8e | ||
|
|
1fd959a665 | ||
|
|
234a21d085 | ||
|
|
90835ece58 |
@@ -1,2 +1,6 @@
|
|||||||
|
-e .
|
||||||
pytest==4.2.0
|
pytest==4.2.0
|
||||||
pytest-flakes==4.0.0
|
pytest-flakes==4.0.0
|
||||||
|
# because of pip bug https://github.com/pypa/pip/issues/4780
|
||||||
|
aiohttp==3.5.4
|
||||||
|
certifi==2019.3.9
|
||||||
|
|||||||
9
setup.py
9
setup.py
@@ -2,9 +2,14 @@ from setuptools import setup, find_packages
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="galaxy.plugin.api",
|
name="galaxy.plugin.api",
|
||||||
version="0.26",
|
version="0.28",
|
||||||
description="Galaxy python plugin API",
|
description="Galaxy python plugin API",
|
||||||
author='Galaxy team',
|
author='Galaxy team',
|
||||||
author_email='galaxy@gog.com',
|
author_email='galaxy@gog.com',
|
||||||
packages=find_packages(exclude=["tests"])
|
packages=find_packages("src"),
|
||||||
|
package_dir={'': 'src'},
|
||||||
|
install_requires=[
|
||||||
|
"aiohttp==3.5.4",
|
||||||
|
"certifi==2019.3.9"
|
||||||
|
]
|
||||||
)
|
)
|
||||||
|
|||||||
43
src/galaxy/http.py
Normal file
43
src/galaxy/http.py
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
import asyncio
|
||||||
|
import ssl
|
||||||
|
from http import HTTPStatus
|
||||||
|
|
||||||
|
import aiohttp
|
||||||
|
import certifi
|
||||||
|
|
||||||
|
from galaxy.api.errors import (
|
||||||
|
AccessDenied, AuthenticationRequired,
|
||||||
|
BackendTimeout, BackendNotAvailable, BackendError, NetworkError, UnknownError
|
||||||
|
)
|
||||||
|
|
||||||
|
class HttpClient:
|
||||||
|
def __init__(self, limit=20, timeout=aiohttp.ClientTimeout(total=60), cookie_jar=None):
|
||||||
|
ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
||||||
|
ssl_context.load_verify_locations(certifi.where())
|
||||||
|
connector = aiohttp.TCPConnector(limit=limit, timeout=timeout, ssl=ssl_context)
|
||||||
|
self._session = aiohttp.ClientSession(connector=connector, cookie_jar=cookie_jar)
|
||||||
|
|
||||||
|
async def close(self):
|
||||||
|
await self._session.close()
|
||||||
|
|
||||||
|
async def request(self, method, *args, **kwargs):
|
||||||
|
try:
|
||||||
|
response = await self._session.request(method, *args, **kwargs)
|
||||||
|
except asyncio.TimeoutError:
|
||||||
|
raise BackendTimeout()
|
||||||
|
except aiohttp.ClientConnectionError:
|
||||||
|
raise NetworkError()
|
||||||
|
except aiohttp.ServerDisconnectedError:
|
||||||
|
raise BackendNotAvailable()
|
||||||
|
if response.status == HTTPStatus.UNAUTHORIZED:
|
||||||
|
raise AuthenticationRequired()
|
||||||
|
if response.status == HTTPStatus.FORBIDDEN:
|
||||||
|
raise AccessDenied()
|
||||||
|
if response.status == HTTPStatus.SERVICE_UNAVAILABLE:
|
||||||
|
raise BackendNotAvailable()
|
||||||
|
if response.status >= 500:
|
||||||
|
raise BackendError()
|
||||||
|
if response.status >= 400:
|
||||||
|
raise UnknownError()
|
||||||
|
|
||||||
|
return response
|
||||||
Reference in New Issue
Block a user