当前位置: 首页>>代码示例>>Python>>正文


Python HTTPResponse.from_dict方法代码示例

本文整理汇总了Python中w3af.core.data.url.HTTPResponse.HTTPResponse.from_dict方法的典型用法代码示例。如果您正苦于以下问题:Python HTTPResponse.from_dict方法的具体用法?Python HTTPResponse.from_dict怎么用?Python HTTPResponse.from_dict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在w3af.core.data.url.HTTPResponse.HTTPResponse的用法示例。


在下文中一共展示了HTTPResponse.from_dict方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_from_dict_encodings

# 需要导入模块: from w3af.core.data.url.HTTPResponse import HTTPResponse [as 别名]
# 或者: from w3af.core.data.url.HTTPResponse.HTTPResponse import from_dict [as 别名]
    def test_from_dict_encodings(self):
        for body, charset in TEST_RESPONSES.values():
            html = body.encode(charset)
            resp = self.create_resp(Headers([("Content-Type", "text/xml")]), html)

            msg = msgpack.dumps(resp.to_dict())
            loaded_dict = msgpack.loads(msg)

            loaded_resp = HTTPResponse.from_dict(loaded_dict)

            self.assertEquals(
                smart_unicode(html, DEFAULT_CHARSET, ESCAPED_CHAR, on_error_guess=False), loaded_resp.body
            )
开发者ID:masterapocalyptic,项目名称:Tortazo-spanishtranslate,代码行数:15,代码来源:test_HTTPResponse.py

示例2: _load_from_file

# 需要导入模块: from w3af.core.data.url.HTTPResponse import HTTPResponse [as 别名]
# 或者: from w3af.core.data.url.HTTPResponse.HTTPResponse import from_dict [as 别名]
    def _load_from_file(self, id):
        fname = self._get_fname_for_id(id)
        WAIT_TIME = 0.05

        #
        #    Due to some concurrency issues, we need to perform these checks
        #
        for _ in xrange(int(1 / WAIT_TIME)):
            if not os.path.exists(fname):
                time.sleep(WAIT_TIME)
                continue

            # Ok... the file exists, but it might still be being written
            req_res = open(fname, 'rb')

            try:
                data = msgpack.load(req_res, use_list=True)
            except ValueError:
                # ValueError: Extra data. returned when msgpack finds invalid
                # data in the file
                req_res.close()
                time.sleep(WAIT_TIME)
                continue

            try:
                request_dict, response_dict, canary = data
            except TypeError:
                # https://github.com/andresriancho/w3af/issues/1101
                # 'NoneType' object is not iterable
                req_res.close()
                time.sleep(WAIT_TIME)
                continue

            if not canary == self._MSGPACK_CANARY:
                # read failed, most likely because the file write is not
                # complete but for some reason it was a valid msgpack file
                req_res.close()
                time.sleep(WAIT_TIME)
                continue

            # Success!
            req_res.close()

            request = HTTPRequest.from_dict(request_dict)
            response = HTTPResponse.from_dict(response_dict)
            return request, response

        else:
            msg = 'Timeout expecting trace file to be ready "%s"' % fname
            raise IOError(msg)
开发者ID:0x554simon,项目名称:w3af,代码行数:52,代码来源:history.py

示例3: test_from_dict

# 需要导入模块: from w3af.core.data.url.HTTPResponse import HTTPResponse [as 别名]
# 或者: from w3af.core.data.url.HTTPResponse.HTTPResponse import from_dict [as 别名]
    def test_from_dict(self):
        html = "header <b>ABC</b>-<b>DEF</b>-<b>XYZ</b> footer"
        headers = Headers([("Content-Type", "text/html")])
        orig_resp = self.create_resp(headers, html)

        msg = msgpack.dumps(orig_resp.to_dict())
        loaded_dict = msgpack.loads(msg)

        loaded_resp = HTTPResponse.from_dict(loaded_dict)

        self.assertEqual(orig_resp, loaded_resp)

        orig_resp.__dict__.pop("_body_lock")
        loaded_resp.__dict__.pop("_body_lock")

        self.assertEqual(orig_resp.__dict__.values(), loaded_resp.__dict__.values())
开发者ID:masterapocalyptic,项目名称:Tortazo-spanishtranslate,代码行数:18,代码来源:test_HTTPResponse.py

示例4: test_from_dict

# 需要导入模块: from w3af.core.data.url.HTTPResponse import HTTPResponse [as 别名]
# 或者: from w3af.core.data.url.HTTPResponse.HTTPResponse import from_dict [as 别名]
    def test_from_dict(self):
        html = 'header <b>ABC</b>-<b>DEF</b>-<b>XYZ</b> footer'
        headers = Headers([('Content-Type', 'text/html')])
        orig_resp = self.create_resp(headers, html)
        
        msg = msgpack.dumps(orig_resp.to_dict())
        loaded_dict = msgpack.loads(msg)
        
        loaded_resp = HTTPResponse.from_dict(loaded_dict)
        
        self.assertEqual(orig_resp, loaded_resp)

        cmp_attrs = list(orig_resp.__slots__)
        cmp_attrs.remove('_body_lock')

        self.assertEqual({k: getattr(orig_resp, k) for k in cmp_attrs},
                         {k: getattr(loaded_resp, k) for k in cmp_attrs})
开发者ID:everping,项目名称:w3af,代码行数:19,代码来源:test_HTTPResponse.py

示例5: load_http_response_from_temp_file

# 需要导入模块: from w3af.core.data.url.HTTPResponse import HTTPResponse [as 别名]
# 或者: from w3af.core.data.url.HTTPResponse.HTTPResponse import from_dict [as 别名]
def load_http_response_from_temp_file(filename, remove=True):
    """
    :param filename: The filename that holds the HTTP response as msgpack
    :param remove: Remove the file after reading
    :return: An HTTP response instance
    """
    # Importing here to prevent import cycle
    from w3af.core.data.url.HTTPResponse import HTTPResponse

    try:
        data = msgpack.load(file(filename, 'rb'), raw=False)
        result = HTTPResponse.from_dict(data)
    except:
        if remove:
            remove_file_if_exists(filename)
        raise
    else:
        if remove:
            remove_file_if_exists(filename)
        return result
开发者ID:andresriancho,项目名称:w3af,代码行数:22,代码来源:serialization.py

示例6: load

# 需要导入模块: from w3af.core.data.url.HTTPResponse import HTTPResponse [as 别名]
# 或者: from w3af.core.data.url.HTTPResponse.HTTPResponse import from_dict [as 别名]
 def load(serialized_object):
     data = msgpack.loads(serialized_object, raw=False)
     return HTTPResponse.from_dict(data)
开发者ID:andresriancho,项目名称:w3af,代码行数:5,代码来源:test_disk_list.py


注:本文中的w3af.core.data.url.HTTPResponse.HTTPResponse.from_dict方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。