2019-10-26 16:42:33 +00:00
|
|
|
"""Test of various compression/encoding modules (previously in doctests)
|
|
|
|
"""
|
|
|
|
import binascii
|
2014-09-04 07:36:19 +00:00
|
|
|
|
2019-12-29 20:20:20 +00:00
|
|
|
from pdfminer.arcfour import Arcfour
|
|
|
|
from pdfminer.ascii85 import asciihexdecode, ascii85decode
|
|
|
|
from pdfminer.lzw import lzwdecode
|
|
|
|
from pdfminer.runlength import rldecode
|
2019-10-26 16:42:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
def hex(b):
|
|
|
|
"""encode('hex')"""
|
|
|
|
return binascii.hexlify(b)
|
|
|
|
|
|
|
|
|
|
|
|
def dehex(b):
|
|
|
|
"""decode('hex')"""
|
|
|
|
return binascii.unhexlify(b)
|
2014-09-04 07:36:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestAscii85():
|
|
|
|
def test_ascii85decode(self):
|
2019-12-29 20:20:20 +00:00
|
|
|
"""The sample string is taken from:
|
|
|
|
http://en.wikipedia.org/w/index.php?title=Ascii85"""
|
2022-02-02 21:24:32 +00:00
|
|
|
assert ascii85decode(b'9jqo^BlbD-BleB1DJ+*+F(f,q') \
|
|
|
|
== b'Man is distinguished'
|
|
|
|
assert ascii85decode(b'E,9)oF*2M7/c~>') == b'pleasure.'
|
2019-10-26 16:42:33 +00:00
|
|
|
|
2014-09-04 07:36:19 +00:00
|
|
|
def test_asciihexdecode(self):
|
2022-02-02 21:24:32 +00:00
|
|
|
assert asciihexdecode(b'61 62 2e6364 65') == b'ab.cde'
|
|
|
|
assert asciihexdecode(b'61 62 2e6364 657>') == b'ab.cdep'
|
|
|
|
assert asciihexdecode(b'7>') == b'p'
|
2019-10-26 16:42:33 +00:00
|
|
|
|
2014-09-04 07:36:19 +00:00
|
|
|
|
|
|
|
class TestArcfour():
|
|
|
|
def test(self):
|
2022-02-02 21:24:32 +00:00
|
|
|
assert hex(Arcfour(b'Key').process(b'Plaintext')) \
|
|
|
|
== b'bbf316e8d940af0ad3'
|
|
|
|
assert hex(Arcfour(b'Wiki').process(b'pedia')) == b'1021bf0420'
|
|
|
|
assert hex(Arcfour(b'Secret').process(b'Attack at dawn')) \
|
|
|
|
== b'45a01f645fc35b383552544b9bf5'
|
2019-10-26 16:42:33 +00:00
|
|
|
|
2014-09-04 07:36:19 +00:00
|
|
|
|
|
|
|
class TestLzw():
|
|
|
|
def test_lzwdecode(self):
|
2022-02-02 21:24:32 +00:00
|
|
|
assert lzwdecode(b'\x80\x0b\x60\x50\x22\x0c\x0c\x85\x01') \
|
|
|
|
== b'\x2d\x2d\x2d\x2d\x2d\x41\x2d\x2d\x2d\x42'
|
2019-10-26 16:42:33 +00:00
|
|
|
|
|
|
|
|
2014-09-04 07:36:19 +00:00
|
|
|
class TestRunlength():
|
|
|
|
def test_rldecode(self):
|
2022-02-02 21:24:32 +00:00
|
|
|
assert rldecode(b'\x05123456\xfa7\x04abcde\x80junk') \
|
|
|
|
== b'1234567777777abcde'
|