# 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)
            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 '
                             'code or error keys', status, uri)

    def _exception_for_web_service_error(self, message, code, status, uri):
        if code in ('IP_ADDRESS_NOT_FOUND', 'IP_ADDRESS_RESERVED'):
            return AddressNotFoundError(message)
        elif code in ('ACCOUNT_ID_REQUIRED', 'ACCOUNT_ID_UNKNOWN',
                      'AUTHORIZATION_INVALID', 'LICENSE_KEY_REQUIRED',
                      'USER_ID_REQUIRED', 'USER_ID_UNKNOWN'):
            return AuthenticationError(message)
        elif code in ('INSUFFICIENT_FUNDS', 'OUT_OF_QUERIES'):
            return OutOfQueriesError(message)
        elif code == 'PERMISSION_REQUIRED':

# 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)

            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 '
                             'code or error keys', status, uri)

    def _exception_for_web_service_error(self, message, code, status, uri):
        if code in ('IP_ADDRESS_NOT_FOUND', 'IP_ADDRESS_RESERVED'):
            return AddressNotFoundError(message)
        elif code in ('ACCOUNT_ID_REQUIRED', 'ACCOUNT_ID_UNKNOWN',
                      'AUTHORIZATION_INVALID', 'LICENSE_KEY_REQUIRED',
                      'USER_ID_REQUIRED', 'USER_ID_UNKNOWN'):
            return AuthenticationError(message)
        elif code in ('INSUFFICIENT_FUNDS', 'OUT_OF_QUERIES'):
            return OutOfQueriesError(message)
        elif code == 'PERMISSION_REQUIRED':

            return PermissionRequiredError(message)