本文整理汇总了Python中requests.structures.CaseInsensitiveDict.copy方法的典型用法代码示例。如果您正苦于以下问题:Python CaseInsensitiveDict.copy方法的具体用法?Python CaseInsensitiveDict.copy怎么用?Python CaseInsensitiveDict.copy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类requests.structures.CaseInsensitiveDict
的用法示例。
在下文中一共展示了CaseInsensitiveDict.copy方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_copy
# 需要导入模块: from requests.structures import CaseInsensitiveDict [as 别名]
# 或者: from requests.structures.CaseInsensitiveDict import copy [as 别名]
def test_copy(self):
cid = CaseInsensitiveDict({
'Accept': 'application/json',
'user-Agent': 'requests',
})
cid_copy = cid.copy()
assert cid == cid_copy
cid['changed'] = True
assert cid != cid_copy
示例2: setup
# 需要导入模块: from requests.structures import CaseInsensitiveDict [as 别名]
# 或者: from requests.structures.CaseInsensitiveDict import copy [as 别名]
class TestCaseInsensitiveDict:
@pytest.fixture(autouse=True)
def setup(self):
"""
CaseInsensitiveDict instance with "Accept" header.
"""
self.case_insensitive_dict = CaseInsensitiveDict()
self.case_insensitive_dict['Accept'] = 'application/json'
def test_list(self):
assert list(self.case_insensitive_dict) == ['Accept']
possible_keys = pytest.mark.parametrize('key', ('accept', 'ACCEPT', 'aCcEpT', 'Accept'))
@possible_keys
def test_getitem(self, key):
assert self.case_insensitive_dict[key] == 'application/json'
@possible_keys
def test_delitem(self, key):
del self.case_insensitive_dict[key]
assert key not in self.case_insensitive_dict
def test_lower_items(self):
assert list(self.case_insensitive_dict.lower_items()) == [('accept', 'application/json')]
def test_repr(self):
assert repr(self.case_insensitive_dict) == "{'Accept': 'application/json'}"
def test_copy(self):
copy = self.case_insensitive_dict.copy()
assert copy is not self.case_insensitive_dict
assert copy == self.case_insensitive_dict
@pytest.mark.parametrize(
'other, result', (
({'AccePT': 'application/json'}, True),
({}, False),
(None, False)
)
)
def test_instance_equality(self, other, result):
assert (self.case_insensitive_dict == other) is result
示例3: Site
# 需要导入模块: from requests.structures import CaseInsensitiveDict [as 别名]
# 或者: from requests.structures.CaseInsensitiveDict import copy [as 别名]
#.........这里部分代码省略.........
:param user:
:param password:
:param onDemand: if True, will postpone login until an actual API request is made
:return:
"""
self.tokens = {}
if onDemand:
self._loginOnDemand = (user, password)
return
res = self('login', lgname=user, lgpassword=password)['login']
if res['result'] == 'NeedToken':
res = self('login', lgname=user, lgpassword=password, lgtoken=res['token'])['login']
if res['result'] != 'Success':
raise ApiError('Login failed', res)
self._loginOnDemand = False
def query(self, **kwargs):
"""
Call Query API with given parameters, and yield all results returned
by the server, properly handling result continuation.
"""
if 'rawcontinue' in kwargs:
raise ValueError("rawcontinue is not supported with query() function, use object's __call__()")
if 'continue' not in kwargs:
kwargs['continue'] = ''
req = kwargs
while True:
result = self('query', **req)
if 'query' in result:
yield result['query']
if 'continue' not in result:
break
# re-send all continue values in the next call
req = kwargs.copy()
req.update(result['continue'])
def queryPages(self, **kwargs):
"""
Query the server and return all page objects individually.
"""
incomplete = {}
changed = set()
for result in self.query(**kwargs):
if 'pages' not in result:
raise ApiError('Missing pages element in query result', result)
finished = incomplete.copy()
for pageId, page in result['pages'].items():
if pageId in changed:
continue
if pageId in incomplete:
del finished[pageId] # If server returned it => not finished
p = incomplete[pageId]
if 'lastrevid' in page and p['lastrevid'] != page['lastrevid']:
# someone else modified this page, it must be requested anew separately
changed.add(pageId)
del incomplete[pageId]
continue
self._mergePage(p, page)
else:
p = page
incomplete[pageId] = p
for pageId, page in finished.items():
if pageId not in changed:
yield page