コード例 #1
0
    def do_rewrite(cls, statusline, headers):
        writer = BufferWARCWriter()

        http_headers = StatusAndHeaders(statusline, headers, protocol='HTTP/1.0')

        record = writer.create_warc_record('http://example.com/', 'response',
                                           http_headers=http_headers)

        return cls.get_rwinfo(record)
コード例 #2
0
ファイル: test_content_rewriter.py プロジェクト: peterk/pywb
    def _create_response_record(self, url, headers, payload, warc_headers):
        writer = BufferWARCWriter()

        warc_headers = warc_headers or {}

        payload = payload.encode('utf-8')

        http_headers = StatusAndHeaders('200 OK', headers, protocol='HTTP/1.0')

        return writer.create_warc_record(url, 'response',
                                         payload=BytesIO(payload),
                                         length=len(payload),
                                         http_headers=http_headers,
                                         warc_headers_dict=warc_headers)
コード例 #3
0
    def _create_response_record(self, url, headers, payload, warc_headers):
        writer = BufferWARCWriter()

        warc_headers = warc_headers or {}

        if isinstance(payload, six.text_type):
            payload = payload.encode('utf-8')

        http_headers = StatusAndHeaders('200 OK', headers, protocol='HTTP/1.0')

        return writer.create_warc_record(url, 'response',
                                         payload=BytesIO(payload),
                                         length=len(payload),
                                         http_headers=http_headers,
                                         warc_headers_dict=warc_headers)
コード例 #4
0
ファイル: test_writer.py プロジェクト: vitgou/warcio
    def test_identity(self):
        """ read(write(record)) should yield record """
        payload = b'foobar'
        writer = BufferWARCWriter(gzip=True)
        httpHeaders = StatusAndHeaders('GET / HTTP/1.1', {},
                                       is_http_request=True)
        warcHeaders = {'Foo': 'Bar'}
        record = writer.create_warc_record('http://example.com/',
                                           'request',
                                           payload=BytesIO(payload),
                                           warc_headers_dict=warcHeaders,
                                           http_headers=httpHeaders)

        writer.write_record(record)

        for new_rec in ArchiveIterator(writer.get_stream()):
            assert new_rec.rec_type == record.rec_type
            assert new_rec.rec_headers == record.rec_headers
            assert new_rec.content_type == record.content_type
            assert new_rec.length == record.length
            assert new_rec.http_headers == record.http_headers
            assert new_rec.raw_stream.read() == payload