Changed: StringIO -> io.BytesIO

pull/1/head
Yusuke Shinyama 2014-06-25 19:55:41 +09:00
parent a3ab6c253b
commit fe86b4e64e
8 changed files with 26 additions and 32 deletions

View File

@ -15,7 +15,10 @@ import sys
import os import os
import os.path import os.path
import gzip import gzip
import cPickle as pickle try:
import cPickle as pickle
except ImportError:
import pickle as pickle
import struct import struct
import logging import logging
from psparser import PSStackParser from psparser import PSStackParser

View File

@ -1,7 +1,7 @@
#!/usr/bin/env python #!/usr/bin/env python
import cStringIO
import struct import struct
import os, os.path import os, os.path
from io import BytesIO
from pdftypes import LITERALS_DCT_DECODE from pdftypes import LITERALS_DCT_DECODE
from pdfcolor import LITERAL_DEVICE_GRAY, LITERAL_DEVICE_RGB, LITERAL_DEVICE_CMYK from pdfcolor import LITERAL_DEVICE_GRAY, LITERAL_DEVICE_RGB, LITERAL_DEVICE_CMYK
@ -83,7 +83,7 @@ class ImageWriter(object):
if LITERAL_DEVICE_CMYK in image.colorspace: if LITERAL_DEVICE_CMYK in image.colorspace:
from PIL import Image from PIL import Image
from PIL import ImageChops from PIL import ImageChops
ifp = cStringIO.StringIO(raw_data) ifp = BytesIO(raw_data)
i = Image.open(ifp) i = Image.open(ifp)
i = ImageChops.invert(i) i = ImageChops.invert(i)
i = i.convert('RGB') i = i.convert('RGB')

View File

@ -1,10 +1,7 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
import logging import logging
try: from io import BytesIO
from cStringIO import StringIO
except ImportError:
from StringIO import StringIO
class CorruptDataError(Exception): class CorruptDataError(Exception):
@ -103,7 +100,7 @@ def lzwdecode(data):
>>> lzwdecode('\x80\x0b\x60\x50\x22\x0c\x0c\x85\x01') >>> lzwdecode('\x80\x0b\x60\x50\x22\x0c\x0c\x85\x01')
'\x2d\x2d\x2d\x2d\x2d\x41\x2d\x2d\x2d\x42' '\x2d\x2d\x2d\x2d\x2d\x41\x2d\x2d\x2d\x42'
""" """
fp = StringIO(data) fp = BytesIO(data)
return ''.join(LZWDecoder(fp).run()) return ''.join(LZWDecoder(fp).run())
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -1,10 +1,7 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
import struct import struct
try: from io import BytesIO
from cStringIO import StringIO
except ImportError:
from StringIO import StringIO
from cmapdb import CMapDB, CMapParser, FileUnicodeMap, CMap from cmapdb import CMapDB, CMapParser, FileUnicodeMap, CMap
from encodingdb import EncodingDB, name2unicode from encodingdb import EncodingDB, name2unicode
from psparser import PSStackParser from psparser import PSStackParser
@ -122,7 +119,7 @@ NIBBLES = ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.', 'e', 'e-', Non
## ##
def getdict(data): def getdict(data):
d = {} d = {}
fp = StringIO(data) fp = BytesIO(data)
stack = [] stack = []
while 1: while 1:
c = fp.read(1) c = fp.read(1)
@ -538,7 +535,7 @@ class PDFSimpleFont(PDFFont):
if 'ToUnicode' in spec: if 'ToUnicode' in spec:
strm = stream_value(spec['ToUnicode']) strm = stream_value(spec['ToUnicode'])
self.unicode_map = FileUnicodeMap() self.unicode_map = FileUnicodeMap()
CMapParser(self.unicode_map, StringIO(strm.get_data())).run() CMapParser(self.unicode_map, BytesIO(strm.get_data())).run()
PDFFont.__init__(self, descriptor, widths) PDFFont.__init__(self, descriptor, widths)
return return
@ -578,7 +575,7 @@ class PDFType1Font(PDFSimpleFont):
self.fontfile = stream_value(descriptor.get('FontFile')) self.fontfile = stream_value(descriptor.get('FontFile'))
length1 = int_value(self.fontfile['Length1']) length1 = int_value(self.fontfile['Length1'])
data = self.fontfile.get_data()[:length1] data = self.fontfile.get_data()[:length1]
parser = Type1FontHeaderParser(StringIO(data)) parser = Type1FontHeaderParser(BytesIO(data))
self.cid2unicode = parser.get_encoding() self.cid2unicode = parser.get_encoding()
return return
@ -651,12 +648,12 @@ class PDFCIDFont(PDFFont):
if 'FontFile2' in descriptor: if 'FontFile2' in descriptor:
self.fontfile = stream_value(descriptor.get('FontFile2')) self.fontfile = stream_value(descriptor.get('FontFile2'))
ttf = TrueTypeFont(self.basefont, ttf = TrueTypeFont(self.basefont,
StringIO(self.fontfile.get_data())) BytesIO(self.fontfile.get_data()))
self.unicode_map = None self.unicode_map = None
if 'ToUnicode' in spec: if 'ToUnicode' in spec:
strm = stream_value(spec['ToUnicode']) strm = stream_value(spec['ToUnicode'])
self.unicode_map = FileUnicodeMap() self.unicode_map = FileUnicodeMap()
CMapParser(self.unicode_map, StringIO(strm.get_data())).run() CMapParser(self.unicode_map, BytesIO(strm.get_data())).run()
elif self.cidcoding in ('Adobe-Identity', 'Adobe-UCS'): elif self.cidcoding in ('Adobe-Identity', 'Adobe-UCS'):
if ttf: if ttf:
try: try:

View File

@ -2,10 +2,7 @@
import sys import sys
import re import re
import logging import logging
try: from io import BytesIO
from cStringIO import StringIO
except ImportError:
from StringIO import StringIO
from cmapdb import CMapDB, CMap from cmapdb import CMapDB, CMap
from psparser import PSTypeError, PSEOF from psparser import PSTypeError, PSEOF
from psparser import PSKeyword, literal_name, keyword_name from psparser import PSKeyword, literal_name, keyword_name
@ -218,7 +215,7 @@ class PDFContentParser(PSStackParser):
self.istream += 1 self.istream += 1
else: else:
raise PSEOF('Unexpected EOF, file truncated?') raise PSEOF('Unexpected EOF, file truncated?')
self.fp = StringIO(strm.get_data()) self.fp = BytesIO(strm.get_data())
return return
def seek(self, pos): def seek(self, pos):

View File

@ -1,10 +1,7 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
import logging import logging
try: from io import BytesIO
from cStringIO import StringIO
except ImportError:
from StringIO import StringIO
from psparser import PSStackParser from psparser import PSStackParser
from psparser import PSSyntaxError, PSEOF from psparser import PSSyntaxError, PSEOF
from psparser import KWD, STRICT from psparser import KWD, STRICT
@ -147,7 +144,7 @@ class PDFStreamParser(PDFParser):
""" """
def __init__(self, data): def __init__(self, data):
PDFParser.__init__(self, StringIO(data)) PDFParser.__init__(self, BytesIO(data))
return return
def flush(self): def flush(self):

View File

@ -664,12 +664,12 @@ func/a/b{(c)do*}def
] ]
def get_tokens(self, s): def get_tokens(self, s):
import StringIO from io import BytesIO
class MyParser(PSBaseParser): class MyParser(PSBaseParser):
def flush(self): def flush(self):
self.add_results(*self.popall()) self.add_results(*self.popall())
parser = MyParser(StringIO.StringIO(s)) parser = MyParser(BytesIO(s))
r = [] r = []
try: try:
while 1: while 1:
@ -679,12 +679,12 @@ func/a/b{(c)do*}def
return r return r
def get_objects(self, s): def get_objects(self, s):
import StringIO from io import BytesIO
class MyParser(PSStackParser): class MyParser(PSStackParser):
def flush(self): def flush(self):
self.add_results(*self.popall()) self.add_results(*self.popall())
parser = MyParser(StringIO.StringIO(s)) parser = MyParser(BytesIO(s))
r = [] r = []
try: try:
while 1: while 1:

View File

@ -1,6 +1,9 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
import cPickle as pickle try:
import cPickle as pickle
except ImportError:
import pickle as pickle
## CMapConverter ## CMapConverter