本文整理汇总了Python中requests.structures.CaseInsensitiveDict.setdefault方法的典型用法代码示例。如果您正苦于以下问题:Python CaseInsensitiveDict.setdefault方法的具体用法?Python CaseInsensitiveDict.setdefault怎么用?Python CaseInsensitiveDict.setdefault使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类requests.structures.CaseInsensitiveDict
的用法示例。
在下文中一共展示了CaseInsensitiveDict.setdefault方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_setdefault
# 需要导入模块: from requests.structures import CaseInsensitiveDict [as 别名]
# 或者: from requests.structures.CaseInsensitiveDict import setdefault [as 别名]
def test_setdefault(self):
cid = CaseInsensitiveDict({'Spam': 'blueval'})
self.assertEqual(
cid.setdefault('spam', 'notblueval'),
'blueval'
)
self.assertEqual(
cid.setdefault('notspam', 'notblueval'),
'notblueval'
)
示例2: _prepare_request
# 需要导入模块: from requests.structures import CaseInsensitiveDict [as 别名]
# 或者: from requests.structures.CaseInsensitiveDict import setdefault [as 别名]
def _prepare_request(self, command, json=True, opcode_name='command',
fetch_list=False, **kwargs):
params = CaseInsensitiveDict(**kwargs)
params.update({
'apiKey': self.key,
opcode_name: command,
})
if json:
params['response'] = 'json'
if 'page' in kwargs or fetch_list:
params.setdefault('pagesize', PAGE_SIZE)
if 'expires' not in params and self.expiration.total_seconds() >= 0:
params['signatureVersion'] = '3'
tz = pytz.utc
expires = tz.localize(datetime.utcnow() + self.expiration)
params['expires'] = expires.astimezone(tz).strftime(EXPIRES_FORMAT)
kind = 'params' if self.method == 'get' else 'data'
return kind, dict(params.items())
示例3: test_setdefault
# 需要导入模块: from requests.structures import CaseInsensitiveDict [as 别名]
# 或者: from requests.structures.CaseInsensitiveDict import setdefault [as 别名]
def test_setdefault(self):
cid = CaseInsensitiveDict({"Spam": "blueval"})
assert cid.setdefault("spam", "notblueval") == "blueval"
assert cid.setdefault("notspam", "notblueval") == "notblueval"
示例4: test_setdefault
# 需要导入模块: from requests.structures import CaseInsensitiveDict [as 别名]
# 或者: from requests.structures.CaseInsensitiveDict import setdefault [as 别名]
def test_setdefault(self):
cid = CaseInsensitiveDict({"Spam": "blueval"})
self.assertEqual(cid.setdefault("spam", "notblueval"), "blueval")
self.assertEqual(cid.setdefault("notspam", "notblueval"), "notblueval")