示例#1
0
    def delete(self, uri):
        """Perform a HTTP delete

        :param src uri: The URL to send the DELETE to
        :rtype: consulate.api.Response

        """
        LOGGER.debug("DELETE %s", uri)
        return api.Response(self.session.delete(uri, timeout=self.timeout))
示例#2
0
    def _process_response(response):
        """Build an api.Response object based upon the requests response
        object.

        :param requests.response response: The requests response
        :rtype: consulate.api.Response

        """
        return api.Response(response.status_code, response.content,
                            response.headers)
    def get(self, uri, timeout=None):
        """Perform a HTTP get

        :param src uri: The URL to send the DELETE to
        :param timeout: How long to wait on the response
        :type timeout: int or float or None
        :rtype: consulate.api.Response

        """
        LOGGER.debug("GET %s", uri)
        try:
            return api.Response(self.session.get(uri, timeout=timeout or self.timeout))
        except (requests.exceptions.RequestException, OSError, socket.error) as err:
            raise exceptions.RequestError(str(err))
    def put(self, uri, data=None, timeout=None):
        """Perform a HTTP put

        :param src uri: The URL to send the DELETE to
        :param str data: The PUT data
        :param timeout: How long to wait on the response
        :type timeout: int or float or None
        :rtype: consulate.api.Response

        """
        LOGGER.debug("PUT %s with %r", uri, data)
        headers = {"Content-Type": CONTENT_FORM if utils.is_string(data) else CONTENT_JSON}
        try:
            return api.Response(self.session.put(uri, data=data, headers=headers, timeout=timeout or self.timeout))
        except (requests.exceptions.RequestException, OSError, socket.error) as err:
            raise exceptions.RequestError(str(err))