本文整理汇总了Python中twisted.web.http_headers.Headers.iteritems方法的典型用法代码示例。如果您正苦于以下问题:Python Headers.iteritems方法的具体用法?Python Headers.iteritems怎么用?Python Headers.iteritems使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.web.http_headers.Headers
的用法示例。
在下文中一共展示了Headers.iteritems方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: makeRequest
# 需要导入模块: from twisted.web.http_headers import Headers [as 别名]
# 或者: from twisted.web.http_headers.Headers import iteritems [as 别名]
def makeRequest(self, bucket, key, method, action=None, params=None,
body=None, headers=None, processResponse=True,
responseContentType=None):
uri = self._uri(bucket, key, action, params)
if not headers:
headers = {}
if body and 'Content-Type' not in headers:
headers['Content-Type'] = getattr(body, 'contentType', None)
if hasattr(body, 'md5Hash') and 'Content-MD5' not in headers:
headers['Content-MD5'] = body.md5Hash()
headers = Headers({k: [v] for k, v in headers.iteritems()
if k and v is not None})
d = self._agent.request(method, uri, headers, body)
if processResponse:
d.addCallback(self.processResponse, responseContentType)
return d
示例2: send_request
# 需要导入模块: from twisted.web.http_headers import Headers [as 别名]
# 或者: from twisted.web.http_headers.Headers import iteritems [as 别名]
def send_request(self, method, url, headers, body):
"""
Send the request.
.. NOTE:: This should not be called directly. Use *self.request()*.
*method* (``str``) is the HTTP request method.
*url* (``str``) is the URL of the request.
*headers* (``dict``) are any headers to send. This can be ``None``.
*body* (``str`` or ``file``) is the body of the request. This can be
``None``.
Returns a deferred (``twisted.internet.defer.Deferred``) which is
fired with the response (``twisted.web.iweb.IResponse``) once all
response headers have been received.
"""
body_is_file = callable(getattr(body, 'read', None))
headers = Headers({key: [val] for key, val in headers.iteritems()}) if headers else None
#producer = FileBodyProducer(body if body_is_file else StringIO(body)) if body is not None else None
producer = XXXStringProducer(body.read() if body_is_file else body) if body is not None else None
return self.tx_agent.request(method, url, headers=headers, bodyProducer=producer)