本文整理汇总了Python中pulsar.utils.httpurl.Headers类的典型用法代码示例。如果您正苦于以下问题:Python Headers类的具体用法?Python Headers怎么用?Python Headers使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Headers类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_remove_header
def test_remove_header(self):
h = Headers([('Content-type', 'text/html')])
self.assertEqual(len(h), 1)
self.assertEqual(h.remove_header('foo'), None)
self.assertEqual(h.remove_header('content-length'), None)
self.assertEqual(h.remove_header('content-type'), ['text/html'])
self.assertEqual(len(h), 0)
开发者ID:Danzeer,项目名称:pulsar,代码行数:7,代码来源:headers.py
示例2: test_override
def test_override(self):
h = Headers([('Accept-encoding', 'gzip'),
('Accept-encoding', 'deflate'),
('Accept', '*/*')], kind=2)
h.override([('Accept-encoding', 'gzip2'),
('Accept-encoding', 'deflate2'),
('Accept', 'text/html'),
('Accept', '*/*; q=0.8')])
self.assertEqual(len(h), 2)
self.assertEqual(h['accept-encoding'], 'gzip2, deflate2')
self.assertEqual(h['accept'], 'text/html, */*; q=0.8')
开发者ID:Danzeer,项目名称:pulsar,代码行数:11,代码来源:headers.py
示例3: test_cookies
def test_cookies(self):
h = Headers()
cookies = SimpleCookie({'bla': 'foo', 'pippo': 'pluto'})
self.assertEqual(len(cookies), 2)
for c in cookies.values():
v = c.OutputString()
h.add_header('Set-Cookie', v)
h = str(h)
self.assertTrue(
h in ('Set-Cookie: bla=foo\r\nSet-Cookie: pippo=pluto\r\n\r\n',
'Set-Cookie: pippo=pluto\r\nSet-Cookie: bla=foo\r\n\r\n'))
开发者ID:Danzeer,项目名称:pulsar,代码行数:11,代码来源:headers.py
示例4: testClientHeader
def testClientHeader(self):
h = Headers(kind='client')
self.assertEqual(h.kind, 'client')
self.assertEqual(len(h), 0)
h['content-type'] = 'text/html'
self.assertEqual(h.get_all('content-type'), ['text/html'])
self.assertEqual(len(h), 1)
h['server'] = 'bla'
self.assertEqual(len(h), 1)
del h['content-type']
self.assertEqual(len(h), 0)
self.assertEqual(h.get_all('content-type', []), [])
开发者ID:Danzeer,项目名称:pulsar,代码行数:12,代码来源:headers.py
示例5: test_remove_header_value
def test_remove_header_value(self):
h = Headers([('Accept-encoding', 'gzip'),
('Accept-encoding', 'deflate'),
('Accept', '*/*')], kind=2)
self.assertEqual(len(h), 2)
self.assertEqual(h['accept-encoding'], 'gzip, deflate')
self.assertEqual(h.remove_header('accept-encoding', 'x'), None)
self.assertEqual(h['accept-encoding'], 'gzip, deflate')
self.assertEqual(h.remove_header('accept-encoding', 'deflate'),
'deflate')
self.assertEqual(len(h), 2)
self.assertEqual(h['accept-encoding'], 'gzip')
开发者ID:Danzeer,项目名称:pulsar,代码行数:12,代码来源:headers.py
示例6: __init__
def __init__(self, client, url, method, inp_params=None, headers=None,
data=None, files=None, json=None, history=None, auth=None,
charset=None, max_redirects=10, source_address=None,
allow_redirects=False, decompress=True, version=None,
wait_continue=False, websocket_handler=None, cookies=None,
params=None, stream=False, proxies=None, verify=True,
**ignored):
self.client = client
self.method = method.upper()
self.inp_params = inp_params or {}
self.unredirected_headers = Headers(kind='client')
self.history = history
self.wait_continue = wait_continue
self.max_redirects = max_redirects
self.allow_redirects = allow_redirects
self.charset = charset or 'utf-8'
self.version = version
self.decompress = decompress
self.websocket_handler = websocket_handler
self.source_address = source_address
self.stream = stream
self.verify = verify
self.new_parser()
if auth and not isinstance(auth, Auth):
auth = HTTPBasicAuth(*auth)
self.auth = auth
self.headers = client._get_headers(headers)
self.url = full_url(url, params, method=self.method)
self.body = self._encode_body(data, files, json)
self._set_proxy(proxies, ignored)
cookies = cookiejar_from_dict(client.cookies, cookies)
if cookies:
cookies.add_cookie_header(self)
开发者ID:wilddom,项目名称:pulsar,代码行数:33,代码来源:__init__.py
示例7: get_headers
def get_headers(self, request, headers=None):
# Returns a :class:`Header` obtained from combining
# :attr:`headers` with *headers*. Can handle websocket requests.
if request.scheme in ('ws', 'wss'):
d = Headers((
('Connection', 'Upgrade'),
('Upgrade', 'websocket'),
('Sec-WebSocket-Version', str(max(SUPPORTED_VERSIONS))),
('Sec-WebSocket-Key', self.websocket_key),
('user-agent', self.client_version)
), kind='client')
else:
d = self.headers.copy()
if headers:
d.override(headers)
return d
开发者ID:successtest9,项目名称:pulsar,代码行数:16,代码来源:__init__.py
示例8: __init__
def __init__(self, wsgi_callable, cfg, server_software=None):
super(HttpServerResponse, self).__init__()
self.wsgi_callable = wsgi_callable
self.cfg = cfg
self.parser = http_parser(kind=0)
self.headers = Headers()
self.keep_alive = False
self.SERVER_SOFTWARE = server_software or self.SERVER_SOFTWARE
开发者ID:Ghost-script,项目名称:dyno-chat,代码行数:8,代码来源:server.py
示例9: request_headers
def request_headers(self, environ):
'''Modify request headers via the list of :attr:`headers_middleware`.
The returned headers will be sent to the target uri.'''
headers = Headers(kind='client')
for k in environ:
if k.startswith('HTTP_'):
head = k[5:].replace('_','-')
headers[head] = environ[k]
for head in ENVIRON_HEADERS:
k = head.replace('-','_').upper()
v = environ.get(k)
if v:
headers[head] = v
headers.update(self.headers)
for middleware in self.headers_middleware:
middleware(environ, headers)
return headers
开发者ID:cyberj,项目名称:pulsar,代码行数:17,代码来源:manage.py
示例10: __init__
def __init__(
self,
client,
url,
method,
inp_params=None,
headers=None,
data=None,
files=None,
history=None,
charset=None,
encode_multipart=True,
multipart_boundary=None,
source_address=None,
allow_redirects=False,
max_redirects=10,
decompress=True,
version=None,
wait_continue=False,
websocket_handler=None,
cookies=None,
urlparams=None,
**ignored
):
self.client = client
self._data = None
self.files = files
self.urlparams = urlparams
self.inp_params = inp_params or {}
self.unredirected_headers = Headers(kind="client")
self.method = method.upper()
self.full_url = url
if urlparams:
self._encode_url(urlparams)
self.set_proxy(None)
self.history = history
self.wait_continue = wait_continue
self.max_redirects = max_redirects
self.allow_redirects = allow_redirects
self.charset = charset or "utf-8"
self.version = version
self.decompress = decompress
self.encode_multipart = encode_multipart
self.multipart_boundary = multipart_boundary
self.websocket_handler = websocket_handler
self.source_address = source_address
self.new_parser()
if self._scheme in tls_schemes:
self._ssl = client.ssl_context(**ignored)
self.headers = client.get_headers(self, headers)
cookies = cookiejar_from_dict(client.cookies, cookies)
if cookies:
cookies.add_cookie_header(self)
self.unredirected_headers["host"] = host_no_default_port(self._scheme, self._netloc)
client.set_proxy(self)
self.data = data
开发者ID:nmg1986,项目名称:pulsar,代码行数:56,代码来源:__init__.py
示例11: __init__
def __init__(self, status=None, content=None, response_headers=None,
content_type=None, encoding=None, environ=None):
self.environ = environ
self.status_code = status or self.DEFAULT_STATUS_CODE
self.encoding = encoding
self.cookies = SimpleCookie()
self.headers = Headers(response_headers, kind='server')
self.content = content
if content_type is not None:
self.content_type = content_type
开发者ID:etataurov,项目名称:pulsar,代码行数:10,代码来源:wrappers.py
示例12: get_headers
def get_headers(self, request, headers=None):
# Returns a :class:`Header` obtained from combining
# :attr:`headers` with *headers*. Can handle websocket requests.
if request.scheme in ("ws", "wss"):
d = Headers(
(
("Connection", "Upgrade"),
("Upgrade", "websocket"),
("Sec-WebSocket-Version", str(max(SUPPORTED_VERSIONS))),
("Sec-WebSocket-Key", self.websocket_key),
("user-agent", self.client_version),
),
kind="client",
)
else:
d = self.headers.copy()
if headers:
d.override(headers)
return d
开发者ID:nmg1986,项目名称:pulsar,代码行数:19,代码来源:__init__.py
示例13: __init__
def __init__(self, status=None, content=None, response_headers=None,
content_type=None, encoding=None, environ=None,
can_store_cookies=True):
self.environ = environ
self.status_code = status or self.DEFAULT_STATUS_CODE
self.encoding = encoding
self.cookies = SimpleCookie()
self.headers = Headers(response_headers, kind='server')
self.content = content
self._can_store_cookies = can_store_cookies
if content_type is not None:
self.content_type = content_type
if environ:
cookie = environ.get('HTTP_COOKIE')
if cookie:
self.cookies.load(cookie)
开发者ID:JinsongBian,项目名称:pulsar,代码行数:16,代码来源:wrappers.py
示例14: __init__
def __init__(
self,
status=None,
content=None,
response_headers=None,
content_type=None,
encoding=None,
environ=None,
start_response=None,
):
super(WsgiResponse, self).__init__(environ, start_response)
self.status_code = status or self.DEFAULT_STATUS_CODE
self.encoding = encoding
self.cookies = SimpleCookie()
self.headers = Headers(response_headers, kind="server")
self.content = content
if content_type is not None:
self.content_type = content_type
开发者ID:ilmiacs,项目名称:pulsar,代码行数:18,代码来源:wsgi.py
示例15: __init__
def __init__(self, client, url, method, inp_params=None, headers=None,
data=None, files=None, history=None, auth=None,
charset=None, encode_multipart=True, multipart_boundary=None,
source_address=None, allow_redirects=False, max_redirects=10,
decompress=True, version=None, wait_continue=False,
websocket_handler=None, cookies=None, urlparams=None,
stream=False, proxies=None, verify=True, **ignored):
self.client = client
self._data = None
self.files = files
self.urlparams = urlparams
self.inp_params = inp_params or {}
self.unredirected_headers = Headers(kind='client')
self.method = method.upper()
self.full_url = url
if urlparams:
self._encode_url(urlparams)
self.history = history
self.wait_continue = wait_continue
self.max_redirects = max_redirects
self.allow_redirects = allow_redirects
self.charset = charset or 'utf-8'
self.version = version
self.decompress = decompress
self.encode_multipart = encode_multipart
self.multipart_boundary = multipart_boundary
self.websocket_handler = websocket_handler
self.source_address = source_address
self.stream = stream
self.verify = verify
self.new_parser()
if self._scheme in tls_schemes:
self._ssl = client.ssl_context(verify=self.verify, **ignored)
if auth and not isinstance(auth, Auth):
auth = HTTPBasicAuth(*auth)
self.auth = auth
self.headers = client.get_headers(self, headers)
cookies = cookiejar_from_dict(client.cookies, cookies)
if cookies:
cookies.add_cookie_header(self)
self.unredirected_headers['host'] = host_no_default_port(self._scheme,
self._netloc)
self.data = data
self._set_proxy(proxies)
开发者ID:arhik,项目名称:pulsar,代码行数:44,代码来源:__init__.py
示例16: HttpRequest
class HttpRequest(RequestBase):
'''An :class:`HttpClient` request for an HTTP resource.
This class has a similar interface to :class:`urllib.request.Request`.
:param files: optional dictionary of name, file-like-objects.
:param allow_redirects: allow the response to follow redirects.
.. attribute:: method
The request method
.. attribute:: version
HTTP version for this request, usually ``HTTP/1.1``
.. attribute:: encode_multipart
If ``True`` (default), defaults POST data as ``multipart/form-data``.
Pass ``encode_multipart=False`` to default to
``application/x-www-form-urlencoded``. In any case, this parameter is
overwritten by passing the correct content-type header.
.. attribute:: history
List of past :class:`.HttpResponse` (collected during redirects).
.. attribute:: wait_continue
if ``True``, the :class:`HttpRequest` includes the
``Expect: 100-Continue`` header.
'''
CONNECT = 'CONNECT'
_proxy = None
_ssl = None
_tunnel = None
def __init__(self, client, url, method, inp_params=None, headers=None,
data=None, files=None, history=None,
charset=None, encode_multipart=True, multipart_boundary=None,
source_address=None, allow_redirects=False, max_redirects=10,
decompress=True, version=None, wait_continue=False,
websocket_handler=None, cookies=None, urlparams=None,
**ignored):
self.client = client
self._data = None
self.files = files
self.urlparams = urlparams
self.inp_params = inp_params or {}
self.unredirected_headers = Headers(kind='client')
self.method = method.upper()
self.full_url = url
if urlparams:
self._encode_url(urlparams)
self.set_proxy(None)
self.history = history
self.wait_continue = wait_continue
self.max_redirects = max_redirects
self.allow_redirects = allow_redirects
self.charset = charset or 'utf-8'
self.version = version
self.decompress = decompress
self.encode_multipart = encode_multipart
self.multipart_boundary = multipart_boundary
self.websocket_handler = websocket_handler
self.source_address = source_address
self.new_parser()
if self._scheme in tls_schemes:
self._ssl = client.ssl_context(**ignored)
self.headers = client.get_headers(self, headers)
cookies = cookiejar_from_dict(client.cookies, cookies)
if cookies:
cookies.add_cookie_header(self)
self.unredirected_headers['host'] = host_no_default_port(self._scheme,
self._netloc)
client.set_proxy(self)
self.data = data
@property
def address(self):
'''``(host, port)`` tuple of the HTTP resource'''
return self._tunnel.address if self._tunnel else (self.host, self.port)
@property
def target_address(self):
return (self.host, int(self.port))
@property
def ssl(self):
'''Context for TLS connections.
If this is a tunneled request and the tunnel connection is not yet
established, it returns ``None``.
'''
if not self._tunnel:
return self._ssl
@property
def key(self):
#.........这里部分代码省略.........
开发者ID:successtest9,项目名称:pulsar,代码行数:101,代码来源:__init__.py
示例17: WsgiResponse
class WsgiResponse(object):
'''A WSGI response.
Instances are callable using the standard WSGI call and, importantly,
iterable::
response = WsgiResponse(200)
A :class:`WsgiResponse` is an iterable over bytes to send back to the
requesting client.
.. attribute:: status_code
Integer indicating the HTTP status, (i.e. 200)
.. attribute:: response
String indicating the HTTP status (i.e. 'OK')
.. attribute:: status
String indicating the HTTP status code and response (i.e. '200 OK')
.. attribute:: content_type
The content type of this response. Can be ``None``.
.. attribute:: headers
The :class:`pulsar.utils.httpurl.Headers` container for this response.
.. attribute:: environ
The dictionary of WSGI environment if passed to the constructor.
'''
_started = False
DEFAULT_STATUS_CODE = 200
def __init__(self, status=None, content=None, response_headers=None,
content_type=None, encoding=None, environ=None):
self.environ = environ
self.status_code = status or self.DEFAULT_STATUS_CODE
self.encoding = encoding
self.cookies = SimpleCookie()
self.headers = Headers(response_headers, kind='server')
self.content = content
if content_type is not None:
self.content_type = content_type
@property
def started(self):
return self._started
@property
def path(self):
if self.environ:
return self.environ.get('PATH_INFO', '')
@property
def method(self):
if self.environ:
return self.environ.get('REQUEST_METHOD')
@property
def connection(self):
if self.environ:
return self.environ.get('pulsar.connection')
def _get_content(self):
return self._content
def _set_content(self, content):
if not self._started:
if content is None:
content = ()
elif ispy3k:
if isinstance(content, str):
content = content.encode(self.encoding or 'utf-8')
else: # pragma nocover
if isinstance(content, unicode):
content = content.encode(self.encoding or 'utf-8')
if isinstance(content, bytes):
content = (content,)
self._content = content
else:
raise RuntimeError('Cannot set content. Already iterated')
content = property(_get_content, _set_content)
def _get_content_type(self):
return self.headers.get('content-type')
def _set_content_type(self, typ):
if typ:
self.headers['content-type'] = typ
else:
self.headers.pop('content-type', None)
content_type = property(_get_content_type, _set_content_type)
def length(self):
#.........这里部分代码省略.........
开发者ID:elimisteve,项目名称:pulsar,代码行数:101,代码来源:wrappers.py
示例18: test_add_header_with_params
def test_add_header_with_params(self):
h = Headers()
h.add_header('content-type', 'text/html', charset=DEFAULT_CHARSET)
self.assertEqual(h['content-type'], 'text/html; charset=ISO-8859-1')
开发者ID:BazookaShao,项目名称:pulsar,代码行数:4,代码来源:headers.py
示例19: HttpRequest
class HttpRequest(RequestBase):
"""An :class:`HttpClient` request for an HTTP resource.
This class has a similar interface to :class:`urllib.request.Request`.
:param files: optional dictionary of name, file-like-objects.
:param allow_redirects: allow the response to follow redirects.
.. attribute:: method
The request method
.. attribute:: version
HTTP version for this request, usually ``HTTP/1.1``
.. attribute:: encode_multipart
If ``True`` (default), defaults POST data as ``multipart/form-data``.
Pass ``encode_multipart=False`` to default to
``application/x-www-form-urlencoded``. In any case, this parameter is
overwritten by passing the correct content-type header.
.. attribute:: history
List of past :class:`.HttpResponse` (collected during redirects).
.. attribute:: wait_continue
if ``True``, the :class:`HttpRequest` includes the
``Expect: 100-Continue`` header.
.. attribute:: stream
Allow for streaming body
"""
_proxy = None
_ssl = None
_tunnel = None
_write_done = False
def __init__(self, client, url, method, inp_params=None, headers=None,
data=None, files=None, history=None, auth=None,
charset=None, encode_multipart=True, multipart_boundary=None,
source_address=None, allow_redirects=False, max_redirects=10,
decompress=True, version=None, wait_continue=False,
websocket_handler=None, cookies=None, urlparams=None,
stream=False, proxies=None, verify=True, **ignored):
self.client = client
self._data = None
self.files = files
self.urlparams = urlparams
self.inp_params = inp_params or {}
self.unredirected_headers = Headers(kind='client')
self.method = method.upper()
self.full_url = url
if urlparams:
self._encode_url(urlparams)
self.history = history
self.wait_continue = wait_continue
self.max_redirects = max_redirects
self.allow_redirects = allow_redirects
self.charset = charset or 'utf-8'
self.version = version
self.decompress = decompress
self.encode_multipart = encode_multipart
self.multipart_boundary = multipart_boundary
self.websocket_handler = websocket_handler
self.source_address = source_address
self.stream = stream
self.verify = verify
self.new_parser()
if self._scheme in tls_schemes:
self._ssl = client.ssl_context(verify=self.verify, **ignored)
if auth and not isinstance(auth, Auth):
auth = HTTPBasicAuth(*auth)
self.auth = auth
self.headers = client.get_headers(self, headers)
cookies = cookiejar_from_dict(client.cookies, cookies)
if cookies:
cookies.add_cookie_header(self)
self.unredirected_headers['host'] = host_no_default_port(self._scheme,
self._netloc)
self.data = data
self._set_proxy(proxies)
@property
def address(self):
"""``(host, port)`` tuple of the HTTP resource
"""
return self._tunnel.address if self._tunnel else (self.host, self.port)
@property
def target_address(self):
return (self.host, int(self.port))
@property
def ssl(self):
"""Context for TLS connections.
#.........这里部分代码省略.........
开发者ID:arhik,项目名称:pulsar,代码行数:101,代码来源:__init__.py
示例20: WsgiResponse
class WsgiResponse:
"""A WSGI response.
Instances are callable using the standard WSGI call and, importantly,
iterable::
response = WsgiResponse(200)
A :class:`WsgiResponse` is an iterable over bytes to send back to the
requesting client.
.. attribute:: status_code
Integer indicating the HTTP status, (i.e. 200)
.. attribute:: response
String indicating the HTTP status (i.e. 'OK')
.. attribute:: status
String indicating the HTTP status code and response (i.e. '200 OK')
.. attribute:: content_type
The content type of this response. Can be ``None``.
.. attribute:: headers
The :class:`.Headers` container for this response.
.. attribute:: environ
The dictionary of WSGI environment if passed to the constructor.
.. attribute:: cookies
A python :class:`SimpleCookie` container of cookies included in the
request as well as cookies set during the response.
"""
_iterated = False
_started = False
DEFAULT_STATUS_CODE = 200
def __init__(self, status=None, content=None, response_headers=None,
content_type=None, encoding=None, environ=None,
can_store_cookies=True):
self.environ = environ
self.status_code = status or self.DEFAULT_STATUS_CODE
self.encoding = encoding
self.cookies = SimpleCookie()
self.headers = Headers(response_headers, kind='server')
self.content = content
self._can_store_cookies = can_store_cookies
if content_type is not None:
self.content_type = content_type
@property
def started(self):
return self._started
@property
def iterated(self):
return self._iterated
@property
def path(self):
if self.environ:
return self.environ.get('PATH_INFO', '')
@property
def method(self):
if self.environ:
return self.environ.get('REQUEST_METHOD')
@property
def connection(self):
if self.environ:
return self.environ.get('pulsar.connection')
@property
def content(self):
return self._content
@content.setter
def content(self, content):
if not self._iterated:
if content is None:
content = ()
else:
if isinstance(content, str):
if not self.encoding: # use utf-8 if not set
self.encoding = 'utf-8'
content = content.encode(self.encoding)
if isinstance(content, bytes):
content = (content,)
self._content = content
else:
raise RuntimeError('Cannot set content. Already iterated')
#.........这里部分代码省略.........
开发者ID:yl849646685,项目名称:pulsar,代码行数:101,代码来源:wrappers.py
注:本文中的pulsar.utils.httpurl.Headers类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论