# Path: autopush/constants.py
# DEFAULT_ROUTER_TIMEOUT = 3
# 
# Path: autopush/exceptions.py
# class RouterException(AutopushException):
#     """Exception if routing has failed, may include a custom status_code and
#     body to write to the response.
# 
#     """
#     def __init__(self, message, status_code=500, response_body="",
#                  router_data=None, headers=None, log_exception=True,
#                  errno=None, logged_status=None, **kwargs):
#         """Create a new RouterException"""
#         super(AutopushException, self).__init__(message)
#         self.status_code = status_code
#         self.headers = {} if headers is None else headers
#         self.log_exception = log_exception
#         self.response_body = response_body or message
#         self.errno = errno
#         self.logged_status = logged_status
#         self.extra = kwargs


import json
import treq
from twisted.web.http_headers import Headers
from twisted.logger import Logger
from twisted.internet.error import ConnectError
from autopush.constants import DEFAULT_ROUTER_TIMEOUT
from autopush.exceptions import RouterException
        if 500 <= response.code <= 599:
            result.retry_message = payload
            return result

        # Fetch the content body
        d = response.text()
        d.addCallback(result.parse_response, response.code, payload)
        return d

    def error(self, failure):
        if isinstance(failure.value, GCMAuthenticationError) or \
                isinstance(failure.value, ConnectError):
            raise failure.value
        self.log.error("GCMClient failure: {}".format(failure.value))
        raise RouterException("Server error: {}".format(failure.value))

    def send(self, payload):
        """Send a payload to GCM

        :param payload: Dictionary of GCM formatted data
        :type payload: JSONMessage
        :return: Result

        """
        headers = Headers({
            'Content-Type': ['application/json'],
            'Authorization': ['key={}'.format(self._api_key)],
        })

        if 'timeout' not in self._options:

# Path: autopush/constants.py
# DEFAULT_ROUTER_TIMEOUT = 3
# 
# Path: autopush/exceptions.py
# class RouterException(AutopushException):
#     """Exception if routing has failed, may include a custom status_code and
#     body to write to the response.
# 
#     """
#     def __init__(self, message, status_code=500, response_body="",
#                  router_data=None, headers=None, log_exception=True,
#                  errno=None, logged_status=None, **kwargs):
#         """Create a new RouterException"""
#         super(AutopushException, self).__init__(message)
#         self.status_code = status_code
#         self.headers = {} if headers is None else headers
#         self.log_exception = log_exception
#         self.response_body = response_body or message
#         self.errno = errno
#         self.logged_status = logged_status
#         self.extra = kwargs


# Path: autopush/router/gcmclient.py
import json
import treq
from twisted.web.http_headers import Headers
from twisted.logger import Logger
from twisted.internet.error import ConnectError
from autopush.constants import DEFAULT_ROUTER_TIMEOUT
from autopush.exceptions import RouterException

        if 500 <= response.code <= 599:
            result.retry_message = payload
            return result

        # Fetch the content body
        d = response.text()
        d.addCallback(result.parse_response, response.code, payload)
        return d

    def error(self, failure):
        if isinstance(failure.value, GCMAuthenticationError) or \
                isinstance(failure.value, ConnectError):
            raise failure.value
        self.log.error("GCMClient failure: {}".format(failure.value))
        raise RouterException("Server error: {}".format(failure.value))

    def send(self, payload):
        """Send a payload to GCM

        :param payload: Dictionary of GCM formatted data
        :type payload: JSONMessage
        :return: Result

        """
        headers = Headers({
            'Content-Type': ['application/json'],
            'Authorization': ['key={}'.format(self._api_key)],
        })

        if 'timeout' not in self._options:

            self._options['timeout'] = DEFAULT_ROUTER_TIMEOUT