コード例 #1
0
ファイル: client.py プロジェクト: faassen/webobtoolkit
def client_pipeline(app=send_request_app,
                     cookie_support=True,
                     content_decoding=True,
                     logging=False, log_level=None):
    """
       :rtype: pre-configured :ref:`wsgi_application`

       :param app: is a :ref:`wsgi_application` to wrap, the default
       is :ref:`webob.client.send_request_app`

       :param cookie_support: enables/disables the
       :func:`filters.cookie_filter`

       :param content_decoding: enables/disables the
       :func:`filters.decode_filter`

       :param logging: enables/disables the :func:`filters.http_log_filter`

       :param log_level: the log_level for :func:`filters.http_log_filter`
    """
    if content_decoding:
        wsgi = filters.decode_filter(app)

    if logging:
        if log_level:
            wsgi = filters.http_log_filter(wsgi, level=log_level)
        else:
            wsgi = filters.http_log_filter(wsgi)

    if cookie_support:
        wsgi = filters.cookie_filter(wsgi)

    wsgi = filters.charset_filter(wsgi)
    return wsgi
コード例 #2
0
def client_pipeline(app=send_request_app,
                    cookie_support=True,
                    content_decoding=True,
                    logging=False,
                    log_level=None):
    """
       :rtype: pre-configured :ref:`wsgi_application`

       :param app: is a :ref:`wsgi_application` to wrap, the default
       is :ref:`webob.client.send_request_app`

       :param cookie_support: enables/disables the
       :func:`filters.cookie_filter`

       :param content_decoding: enables/disables the
       :func:`filters.decode_filter`

       :param logging: enables/disables the :func:`filters.http_log_filter`

       :param log_level: the log_level for :func:`filters.http_log_filter`
    """
    if content_decoding:
        wsgi = filters.decode_filter(app)

    if logging:
        if log_level:
            wsgi = filters.http_log_filter(wsgi, level=log_level)
        else:
            wsgi = filters.http_log_filter(wsgi)

    if cookie_support:
        wsgi = filters.cookie_filter(wsgi)

    wsgi = filters.charset_filter(wsgi)
    return wsgi
コード例 #3
0
 def testBinary(self):
     """
     magically figures out transfer encodings and gzip deflates is necessary
     """
     r = Request.blank("/").get_response(filters.decode_filter(gzip_server))
     self.assert_("compressed" in r.body, r.body)
コード例 #4
0
ファイル: filter_usage.py プロジェクト: imdeany/webobtoolkit
using filters
"""
from webobtoolkit import filters
from webob import Request, Response
import datetime


def time_application(environ, start_response):
    body = "the current time is %s " % datetime.datetime.now().isoformat()
    return Response(body)(environ, start_response)


# add cookie support
application = filters.cookie_filter(time_application)

# decompress the response if it is compressed
application = filters.decode_filter(time_application)


# raise an error the app returns something other than a 200 success
# response
def assert_success(request, response):
    assert response.status_int == 200, "the request was not sucessful"


application = filters.assert_filter(time_application, assert_=assert_success)

response = Request.blank("/").get_response(application)

print str(response)
コード例 #5
0
 def testBinary(self):
     """
     magically figures out transfer encodings and gzip deflates is necessary
     """
     r = Request.blank("/").get_response(filters.decode_filter(gzip_server))
     self.assert_("compressed" in r.body, r.body)
コード例 #6
0
 def testInvalidContentEncoding(self):
     """
     Tests the resiliency of webobtoolkit when decoding a response w/ invalid content encoding headers
     """
     r = Request.blank("/").get_response(filters.decode_filter(invalid_content_encoding_server))
     self.assert_("lying about it's encoding" in r.text, r.body)