# 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 self._response_for('insights', geoip2.models.Insights,
                                  ip_address)

    def _response_for(self, path, model_class, ip_address):
        if ip_address != 'me':
            ip_address = str(compat_ip_address(ip_address))
        uri = '/'.join([self._base_uri, path, ip_address])
        response = requests.get(
            uri,
            auth=(self._account_id, self._license_key),
            headers={
                'Accept': 'application/json',
                'User-Agent': self._user_agent()
            },
            timeout=self._timeout)
        if response.status_code != 200:
            raise self._exception_for_error(response, uri)
        body = self._handle_success(response, uri)
        return model_class(body, locales=self._locales)

    def _user_agent(self):
        return 'GeoIP2 Python Client v%s (%s)' % (geoip2.__version__,
                                                  default_user_agent())

    def _handle_success(self, response, uri):
        try:
            return response.json()
        except ValueError as ex:

# 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 self._response_for('insights', geoip2.models.Insights,
                                  ip_address)

    def _response_for(self, path, model_class, ip_address):
        if ip_address != 'me':
            ip_address = str(compat_ip_address(ip_address))
        uri = '/'.join([self._base_uri, path, ip_address])
        response = requests.get(
            uri,
            auth=(self._account_id, self._license_key),
            headers={
                'Accept': 'application/json',
                'User-Agent': self._user_agent()
            },
            timeout=self._timeout)
        if response.status_code != 200:
            raise self._exception_for_error(response, uri)
        body = self._handle_success(response, uri)
        return model_class(body, locales=self._locales)

    def _user_agent(self):
        return 'GeoIP2 Python Client v%s (%s)' % (geoip2.__version__,
                                                  default_user_agent())

    def _handle_success(self, response, uri):
        try:
            return response.json()
        except ValueError as ex:

            raise GeoIP2Error('Received a 200 response for %(uri)s'