# Path: server/mlabns/third_party/geoip2/geoip2/errors.py
# class AddressNotFoundError(GeoIP2Error):
#     """The address you were looking up was not found."""
# 
# class AuthenticationError(GeoIP2Error):
#     """There was a problem authenticating the request."""
# 
# class GeoIP2Error(RuntimeError):
#     """There was a generic error in GeoIP2.
# 
#     This class represents a generic error. It extends :py:exc:`RuntimeError`
#     and does not add any additional attributes.
# 
#     """
# 
# class HTTPError(GeoIP2Error):
#     """There was an error when making your HTTP request.
# 
#     This class represents an HTTP transport error. It extends
#     :py:exc:`GeoIP2Error` and adds attributes of its own.
# 
#     :ivar http_status: The HTTP status code returned
#     :ivar uri: The URI queried
# 
#     """
# 
#     def __init__(self, message, http_status=None, uri=None):
#         super(HTTPError, self).__init__(message)
#         self.http_status = http_status
#         self.uri = uri
# 
# class InvalidRequestError(GeoIP2Error):
#     """The request was invalid."""
# 
# class OutOfQueriesError(GeoIP2Error):
#     """Your account is out of funds for the service queried."""
# 
# class PermissionRequiredError(GeoIP2Error):
#     """Your account does not have permission to access this service."""


import requests
import geoip2
import geoip2.models
from requests.utils import default_user_agent
from .compat import compat_ip_address
from .errors import (AddressNotFoundError, AuthenticationError, GeoIP2Error,
                     HTTPError, InvalidRequestError, OutOfQueriesError,
                     PermissionRequiredError)
                              uri)

    def _exception_for_error(self, response, uri):
        status = response.status_code

        if 400 <= status < 500:
            return self._exception_for_4xx_status(response, status, uri)
        elif 500 <= status < 600:
            return self._exception_for_5xx_status(status, uri)
        return self._exception_for_non_200_status(status, uri)

    def _exception_for_4xx_status(self, response, status, uri):
        if not response.content:
            return HTTPError('Received a %(status)i error for %(uri)s '
                             'with no body.' % locals(), status, uri)
        elif response.headers['Content-Type'].find('json') == -1:
            return HTTPError('Received a %i for %s with the following '
                             'body: %s' % (status, uri, response.content),
                             status, uri)
        try:
            body = response.json()
        except ValueError as ex:
            return HTTPError(
                'Received a %(status)i error for %(uri)s but it did'
                ' not include the expected JSON body: ' % locals() +
                ', '.join(ex.args), status, uri)
        else:
            if 'code' in body and 'error' in body:
                return self._exception_for_web_service_error(
                    body.get('error'), body.get('code'), status, uri)

# Path: server/mlabns/third_party/geoip2/geoip2/errors.py
# class AddressNotFoundError(GeoIP2Error):
#     """The address you were looking up was not found."""
# 
# class AuthenticationError(GeoIP2Error):
#     """There was a problem authenticating the request."""
# 
# class GeoIP2Error(RuntimeError):
#     """There was a generic error in GeoIP2.
# 
#     This class represents a generic error. It extends :py:exc:`RuntimeError`
#     and does not add any additional attributes.
# 
#     """
# 
# class HTTPError(GeoIP2Error):
#     """There was an error when making your HTTP request.
# 
#     This class represents an HTTP transport error. It extends
#     :py:exc:`GeoIP2Error` and adds attributes of its own.
# 
#     :ivar http_status: The HTTP status code returned
#     :ivar uri: The URI queried
# 
#     """
# 
#     def __init__(self, message, http_status=None, uri=None):
#         super(HTTPError, self).__init__(message)
#         self.http_status = http_status
#         self.uri = uri
# 
# class InvalidRequestError(GeoIP2Error):
#     """The request was invalid."""
# 
# class OutOfQueriesError(GeoIP2Error):
#     """Your account is out of funds for the service queried."""
# 
# class PermissionRequiredError(GeoIP2Error):
#     """Your account does not have permission to access this service."""


# Path: server/mlabns/third_party/geoip2/geoip2/webservice.py
import requests
import geoip2
import geoip2.models
from requests.utils import default_user_agent
from .compat import compat_ip_address
from .errors import (AddressNotFoundError, AuthenticationError, GeoIP2Error,
                     HTTPError, InvalidRequestError, OutOfQueriesError,
                     PermissionRequiredError)

                              uri)

    def _exception_for_error(self, response, uri):
        status = response.status_code

        if 400 <= status < 500:
            return self._exception_for_4xx_status(response, status, uri)
        elif 500 <= status < 600:
            return self._exception_for_5xx_status(status, uri)
        return self._exception_for_non_200_status(status, uri)

    def _exception_for_4xx_status(self, response, status, uri):
        if not response.content:
            return HTTPError('Received a %(status)i error for %(uri)s '
                             'with no body.' % locals(), status, uri)
        elif response.headers['Content-Type'].find('json') == -1:
            return HTTPError('Received a %i for %s with the following '
                             'body: %s' % (status, uri, response.content),
                             status, uri)
        try:
            body = response.json()
        except ValueError as ex:
            return HTTPError(
                'Received a %(status)i error for %(uri)s but it did'
                ' not include the expected JSON body: ' % locals() +
                ', '.join(ex.args), status, uri)
        else:
            if 'code' in body and 'error' in body:
                return self._exception_for_web_service_error(
                    body.get('error'), body.get('code'), status, uri)

            return HTTPError('Response contains JSON but it does not specify '