This repository was archived by the owner on Apr 20, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathpdf_decoder.py
More file actions
103 lines (87 loc) · 2.36 KB
/
pdf_decoder.py
File metadata and controls
103 lines (87 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
pdf_decoder.py
TODO
"""
__author__ = 'Binjo'
__version__ = '0.1'
__date__ = '2009-07-28 14:56:01'
class Decoders(object):
"""
"""
def __init__(self, data=None):
"""
Arguments:
- `data`:
"""
self._data = data
if hasattr( data, 'read' ):
self._data = data.read()
def ascii85decode(self, raw=''):
"""decode /ASCII85Decode
Arguments:
- `self`:
- `raw`:
"""
data = self._data
if raw != '':
data = raw
n = b = 0
out = ''
import struct
for c in data:
if '!' <= c and c <= 'u':
n += 1
b = b*85+(ord(c)-33)
if n == 5:
out += struct.pack('>L',b)
n = b = 0
elif c == 'z':
assert n == 0
out += '\0\0\0\0'
elif c == '~':
if n:
for _ in range(5-n):
b = b*85+84
out += struct.pack('>L',b)[:n-1]
break
return out
def asciihexdecode(self, raw=''):
"""decode /ASCIIHexDecode
Arguments:
- `self`:
- `raw`:
"""
data = self._data
if raw != '':
data = raw
import re
hex_re = re.compile(r'([a-f\d]{2})', re.IGNORECASE)
trail_re = re.compile(r'^(?:[a-f\d]{2}|\s)*([a-f\d])[\s>]*$', re.IGNORECASE)
decode = (lambda hx: chr(int(hx, 16)))
out = map(decode, hex_re.findall(data))
m = trail_re.search(data)
if m:
out.append(decode("%c0" % m.group(1)))
return ''.join(out)
def flatedecode(self, raw=''):
"""decode /FlateDecode
Arguments:
- `self`:
- `raw`:
"""
data = self._data
if raw != '':
data = raw
import zlib
return zlib.decompress(data)
def main():
"""TODO
"""
pass
#-------------------------------------------------------------------------------
if __name__ == '__main__':
main()
#-------------------------------------------------------------------------------
# EOF