本文整理汇总了Python中requests.structures.CaseInsensitiveDict.__str__方法的典型用法代码示例。如果您正苦于以下问题:Python CaseInsensitiveDict.__str__方法的具体用法?Python CaseInsensitiveDict.__str__怎么用?Python CaseInsensitiveDict.__str__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类requests.structures.CaseInsensitiveDict
的用法示例。
在下文中一共展示了CaseInsensitiveDict.__str__方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: CommandResponseStatus
# 需要导入模块: from requests.structures import CaseInsensitiveDict [as 别名]
# 或者: from requests.structures.CaseInsensitiveDict import __str__ [as 别名]
class CommandResponseStatus(Command, metaclass=CommandRegister):
pretty_name = "RESPONSE STATUS"
def __init__(self, result_collector):
super(CommandResponseStatus, self).__init__(result_collector)
self.mapping = CaseInsensitiveDict()
self.mapping["Ok"] = 200
self.mapping["Not found"] = 404
def map_status_code(self, status):
"""
author Damian Mirecki
:param status
:return:
:rtype: int
:raise LookupError: When status is not implemented yet.
"""
if status not in self.mapping:
raise LookupError("Status " + status + " not found in " + self.mapping.__str__())
return self.mapping[status]
def parse(self, path):
response = self.result_collector.get_response()
if response is None:
raise ParsingException(self, result.ERROR_RESPONSE_NOT_FOUND)
actual = response.status_code
if len(path) == 0:
return actual, ParsedValue(self, None, "")
status = path[0]
if not status.isdigit():
try:
status = self.map_status_code(status)
except LookupError as e:
raise ParsingException(self, Error.from_exception(self, e))
else:
if int(status) not in _codes.keys():
raise ParsingException(self, result.ERROR_INVALID_STATUS_CODE)
expected = int(status)
return actual, ParsedValue(self, expected, "")