當前位置: 首頁>>代碼示例>>Python>>正文


Python Response.default_headers方法代碼示例

本文整理匯總了Python中gunicorn.http.wsgi.Response.default_headers方法的典型用法代碼示例。如果您正苦於以下問題:Python Response.default_headers方法的具體用法?Python Response.default_headers怎麽用?Python Response.default_headers使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在gunicorn.http.wsgi.Response的用法示例。


在下文中一共展示了Response.default_headers方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_http_header_encoding

# 需要導入模塊: from gunicorn.http.wsgi import Response [as 別名]
# 或者: from gunicorn.http.wsgi.Response import default_headers [as 別名]
def test_http_header_encoding():
    """ tests whether http response headers are USASCII encoded """

    mocked_socket = mock.MagicMock()
    mocked_socket.sendall = mock.MagicMock()

    mocked_request = mock.MagicMock()
    response = Response(mocked_request, mocked_socket, None)

    # set umlaut header value - latin-1 is OK
    response.headers.append(('foo', 'häder'))
    response.send_headers()

    # set a-breve header value - unicode, non-latin-1 fails
    response = Response(mocked_request, mocked_socket, None)
    response.headers.append(('apple', 'măr'))
    with pytest.raises(UnicodeEncodeError):
        response.send_headers()

    # build our own header_str to compare against
    tosend = response.default_headers()
    tosend.extend(["%s: %s\r\n" % (k, v) for k, v in response.headers])
    header_str = "%s\r\n" % "".join(tosend)

    with pytest.raises(UnicodeEncodeError):
        mocked_socket.sendall(util.to_bytestring(header_str, "ascii"))
開發者ID:benoitc,項目名稱:gunicorn,代碼行數:28,代碼來源:test_http.py

示例2: test_http_header_encoding

# 需要導入模塊: from gunicorn.http.wsgi import Response [as 別名]
# 或者: from gunicorn.http.wsgi.Response import default_headers [as 別名]
def test_http_header_encoding():
    """ tests whether http response headers are USASCII encoded """

    mocked_socket = mock.MagicMock()
    mocked_socket.sendall = mock.MagicMock()

    mocked_request = mock.MagicMock()
    response = Response(mocked_request, mocked_socket, None)

    # set umlaut header
    response.headers.append(('foo', 'häder'))
    try:
        response.send_headers()
    except Exception as e:
        assert isinstance(e, UnicodeEncodeError)


    # build our own header_str to compare against
    tosend = response.default_headers()
    tosend.extend(["%s: %s\r\n" % (k, v) for k, v in response.headers])
    header_str = "%s\r\n" % "".join(tosend)

    try:
        mocked_socket.sendall(util.to_bytestring(header_str,"ascii"))
    except Exception as e:
        assert isinstance(e, UnicodeEncodeError)
開發者ID:BerlinK,項目名稱:web,代碼行數:28,代碼來源:test_http.py

示例3: test_http_header_encoding

# 需要導入模塊: from gunicorn.http.wsgi import Response [as 別名]
# 或者: from gunicorn.http.wsgi.Response import default_headers [as 別名]
def test_http_header_encoding():
    """ tests whether http response headers are ISO-8859-1 encoded """

    mocked_socket = mock.MagicMock()
    mocked_socket.sendall = mock.MagicMock()
    mocked_request = mock.MagicMock()
    response = Response(mocked_request, mocked_socket, None)

    # set umlaut header
    response.headers.append(('foo', 'häder'))
    response.send_headers()

    # build our own header_str to compare against
    tosend = response.default_headers()
    tosend.extend(["%s: %s\r\n" % (k, v) for k, v in response.headers])
    header_str = "%s\r\n" % "".join(tosend)

    mocked_socket.sendall.assert_called_with(util.to_latin1(header_str))
開發者ID:keakon,項目名稱:gunicorn,代碼行數:20,代碼來源:test_http.py


注:本文中的gunicorn.http.wsgi.Response.default_headers方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。