mirror of
https://github.com/webrecorder/pywb.git
synced 2025-03-15 08:04:49 +01:00
- merge pywb.urlrewrite -> pywb.rewrite, remove obsolete stuff (rewrite_content.py, rewrite_live.py, dsrules.py) - move wbrequestresponse -> pywb.apps - move pywb.webapp.handlers -> pywb.apps.static_handler - remove pywb.webapp, pywb.framework packages - disable old header_rewriter, content_rewriter tests - finish renaming from previous warcserver refactor - all other tests passing!
46 lines
1.2 KiB
Python
46 lines
1.2 KiB
Python
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
# full seq
|
|
#>>> print RewriteContent._decode_buff(b'\xce\xb4\xce\xbf\xce\xba', BytesIO(b''), 'utf-8')
|
|
δοκ
|
|
|
|
# read split bytes, read rest
|
|
#>>> b = BytesIO('\xbf\xce\xba')
|
|
#>>> sys.stdout.write(RewriteContent._decode_buff(b'\xce\xb4\xce', b, 'utf-8')); sys.stdout.write(RewriteContent._decode_buff(b.read(), b, 'utf-8'))
|
|
δοκ
|
|
|
|
# invalid seq
|
|
#>>> print RewriteContent._decode_buff(b'\xce\xb4\xce', BytesIO(b'\xfe'), 'utf-8')
|
|
Traceback (most recent call last):
|
|
"UnicodeDecodeError: 'utf8' codec can't decode byte 0xce in position 2: invalid continuation byte"
|
|
|
|
|
|
"""
|
|
|
|
from pywb.rewrite.rewrite_content import RewriteContent
|
|
from io import BytesIO
|
|
import sys
|
|
|
|
|
|
|
|
def test_type_detect_1():
|
|
text_type, stream = RewriteContent._resolve_text_type('js', 'html', BytesIO(b' <html></html>'))
|
|
assert(text_type == 'html')
|
|
assert(stream.read() == b' <html></html>')
|
|
|
|
|
|
def test_type_detect_2():
|
|
text_type, stream = RewriteContent._resolve_text_type('js', 'html', BytesIO(b' function() { return 0; }'))
|
|
assert(text_type == 'js')
|
|
assert(stream.read() == b' function() { return 0; }')
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
import doctest
|
|
doctest.testmod()
|