提交 1b1092b7 编写于 作者: K Konstantin Lopuhin

add Headers.to_native_string_dict - useful when interfacing with other libraries

上级 467553cc
......@@ -85,15 +85,10 @@ class S3DownloadHandler(object):
request = request.replace(url=url)
elif self._signer is not None:
import botocore.awsrequest
from botocore.vendored.requests.structures import CaseInsensitiveDict
print(url, request.headers)
awsrequest = botocore.awsrequest.AWSRequest(
method=request.method,
url='%s://s3.amazonaws.com/%s%s' % (scheme, bucket, path),
# TODO - move to a header method
headers=CaseInsensitiveDict(
(to_unicode(key), to_unicode(b','.join(value)))
for key, value in request.headers.items()),
headers=request.headers.to_native_string_dict(),
data=request.body)
self._signer.add_auth(awsrequest)
request = request.replace(
......
import six
from w3lib.http import headers_dict_to_raw
from scrapy.utils.datatypes import CaselessDict
from scrapy.utils.python import to_unicode
class Headers(CaselessDict):
......@@ -78,6 +79,12 @@ class Headers(CaselessDict):
def to_string(self):
return headers_dict_to_raw(self)
def to_native_string_dict(self):
return CaselessDict(
(to_unicode(key, encoding=self.encoding),
to_unicode(b','.join(value), encoding=self.encoding))
for key, value in self.items())
def __copy__(self):
return self.__class__(self)
copy = __copy__
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册