Commit c0df2fa0 authored by Leo Pound Singer's avatar Leo Pound Singer
Browse files


parent 18dce76e
Pipeline #93432 failed with stages
in 8 minutes and 9 seconds
import json
import pytest
import six
from unittest import mock
except ImportError:
......@@ -16,9 +16,50 @@
# along with gracedb. If not, see <>.
from warnings import warn
from .requests.errors import HTTPError
import requests.exceptions
warn('DEPRECATED: this module is provided for backward compatibility. '
'Use requests.exceptions instead.')
__all__ = ('HTTPError',)
class HTTPError(requests.exceptions.HTTPError):
def status(self):
warn('DEPRECATED: this attribute has been moved to '
return self.response.status_code
def reason(self):
warn('DEPRECATED: this attribute has been moved to '
return self.response.reason
def message(self):
warn('DEPRECATED: this attribute has been moved to '
return self.response.text
def _hook_raise_errors(response, *args, **kwargs):
"""Response hook to raise exception for any HTTP error (status >= 400)."""
except requests.HTTPError as e:
# FIXME: remove once ligo.gracedb.exceptions has been removed
raise HTTPError(e.args, response=e.response)
class SessionLegacyErrorMixin(object):
"""A mixin for :class:`requests.Session` to raise legacy GraceDB exceptions
upon HTTP errors."""
def __init__(self, *args, **kwargs):
super(SessionLegacyErrorMixin, self).__init__(*args, **kwargs)
# Note: prepend instead of append so that the legacy exceptions
# override the normal ones.
self.hooks['response'].insert(0, _hook_raise_errors)
......@@ -26,11 +26,12 @@ from ligo.requests.cert_reload import load_certificate
from requests import codes, HTTPError
from .utils import event_or_superevent
from .exceptions import SessionLegacyErrorMixin
class GraceDb(Session):
class GraceDb(SessionLegacyErrorMixin, Session):
"""GraceDb REST client class.
Provides a client object for accessing the GraceDB server API.
......@@ -40,15 +40,13 @@ with open(readme_file, 'rb') as f:
# Required packages for tests
tests_require = [
tests_require = []
# Add pytest requirement - 5.0.0+ only supports Python 3.5+
pytest_requirement = 'pytest>=3.1.0'
if sys.version_info < (3, 5):
pytest_requirement += ',<5.0.0'
# Add mock for Python 2
if sys.version_info.major < 3:
......@@ -87,7 +85,7 @@ setup(
version=parse_version(os.path.join('ligo', 'gracedb', '')),
author=("Tanner Prestegard, Alexander Pace, Branson Stephens, Brian Moe, "
"Patrick Brady, Leo Singer"),
"Patrick Brady"),
description="A Python package for accessing the GraceDB API.",
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment