本文整理汇总了Python中swift.common.swob.HeaderKeyDict.update方法的典型用法代码示例。如果您正苦于以下问题:Python HeaderKeyDict.update方法的具体用法?Python HeaderKeyDict.update怎么用?Python HeaderKeyDict.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类swift.common.swob.HeaderKeyDict
的用法示例。
在下文中一共展示了HeaderKeyDict.update方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: generate_request_headers
# 需要导入模块: from swift.common.swob import HeaderKeyDict [as 别名]
# 或者: from swift.common.swob.HeaderKeyDict import update [as 别名]
def generate_request_headers(self, orig_req=None, additional=None, transfer=False):
"""
Create a list of headers to be used in backend requets
:param orig_req: the original request sent by the client to the proxy
:param additional: additional headers to send to the backend
:param transfer: If True, transfer headers from original client request
:returns: a dictionary of headers
"""
# Use the additional headers first so they don't overwrite the headers
# we require.
headers = HeaderKeyDict(additional) if additional else HeaderKeyDict()
if transfer:
self.transfer_headers(orig_req.headers, headers)
if "x-timestamp" not in headers:
headers["x-timestamp"] = normalize_timestamp(time.time())
if orig_req:
referer = orig_req.as_referer()
else:
referer = ""
headers.update(
{
"x-trans-id": self.trans_id,
"connection": "close",
"user-agent": "proxy-server %s" % os.getpid(),
"referer": referer,
}
)
return headers
示例2: test_fake_swift_sysmeta
# 需要导入模块: from swift.common.swob import HeaderKeyDict [as 别名]
# 或者: from swift.common.swob.HeaderKeyDict import update [as 别名]
def test_fake_swift_sysmeta(self):
swift = FakeSwift()
orig_headers = HeaderKeyDict()
orig_headers.update({sysmeta_header('container', 'acl'): 'test',
'x-container-meta-foo': 'bar'})
swift.register(self.method, self.path, MagicMock(), orig_headers, None)
self._check_headers(swift, self.method, self.path, orig_headers)
new_headers = orig_headers.copy()
del new_headers[sysmeta_header('container', 'acl').title()]
swift.register(self.method, self.path, MagicMock(), new_headers, None)
self._check_headers(swift, self.method, self.path, orig_headers)
示例3: FakeConn
# 需要导入模块: from swift.common.swob import HeaderKeyDict [as 别名]
# 或者: from swift.common.swob.HeaderKeyDict import update [as 别名]
class FakeConn(object):
def __init__(self, status, headers=None, body='', **kwargs):
self.status = status
try:
self.reason = RESPONSE_REASONS[self.status][0]
except Exception:
self.reason = 'Fake'
self.body = body
self.resp_headers = HeaderKeyDict()
if headers:
self.resp_headers.update(headers)
self.with_exc = False
self.etag = None
def _update_raw_call_args(self, *args, **kwargs):
capture_attrs = ('host', 'port', 'method', 'path', 'req_headers',
'query_string')
for attr, value in zip(capture_attrs, args[:len(capture_attrs)]):
setattr(self, attr, value)
return self
def getresponse(self):
if self.etag:
self.resp_headers['etag'] = str(self.etag.hexdigest())
if self.with_exc:
raise Exception('test')
return self
def getheader(self, header, default=None):
return self.resp_headers.get(header, default)
def getheaders(self):
return self.resp_headers.items()
def read(self, amt=None):
if amt is None:
return self.body
elif isinstance(self.body, six.StringIO):
return self.body.read(amt)
else:
return Exception('Not a StringIO entry')
def send(self, data):
if not self.etag:
self.etag = md5()
self.etag.update(data)
示例4: generate_request_headers
# 需要导入模块: from swift.common.swob import HeaderKeyDict [as 别名]
# 或者: from swift.common.swob.HeaderKeyDict import update [as 别名]
def generate_request_headers(self, orig_req=None, additional=None,
transfer=False):
# Use the additional headers first so they don't overwrite the headers
# we require.
headers = HeaderKeyDict(additional) if additional else HeaderKeyDict()
if transfer:
self.transfer_headers(orig_req.headers, headers)
if 'x-timestamp' not in headers:
headers['x-timestamp'] = normalize_timestamp(time.time())
if orig_req:
referer = orig_req.as_referer()
else:
referer = ''
headers.update({'x-trans-id': self.trans_id,
'connection': 'close',
'user-agent': 'proxy-server %s' % os.getpid(),
'referer': referer})
return headers