mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-03-03 19:45:56 +03:00
Try to open the file in universal line ending mode, fallback to prev behavior
This commit is contained in:
parent
c2835350a8
commit
8193566ff1
|
@ -179,6 +179,20 @@ class PSFile:
|
||||||
self.char = None
|
self.char = None
|
||||||
return s.decode('latin-1') + "\n"
|
return s.decode('latin-1') + "\n"
|
||||||
|
|
||||||
|
class PSFpWrapper:
|
||||||
|
""" Wrapper for a filepointer that has been opened in universal mode """
|
||||||
|
def __init__(self,fp):
|
||||||
|
self.fp = fp
|
||||||
|
|
||||||
|
def __getattr__(self, attr):
|
||||||
|
""" Delegate everything that we're not wrapping """
|
||||||
|
return getattr(self.fp, attr)
|
||||||
|
|
||||||
|
def read(self, count):
|
||||||
|
return self.fp.read(count)
|
||||||
|
|
||||||
|
readbinary = read
|
||||||
|
|
||||||
|
|
||||||
def _accept(prefix):
|
def _accept(prefix):
|
||||||
return prefix[:4] == b"%!PS" or i32(prefix) == 0xC6D3D0C5
|
return prefix[:4] == b"%!PS" or i32(prefix) == 0xC6D3D0C5
|
||||||
|
@ -195,6 +209,10 @@ class EpsImageFile(ImageFile.ImageFile):
|
||||||
|
|
||||||
def _open(self):
|
def _open(self):
|
||||||
|
|
||||||
|
try:
|
||||||
|
fp = PSFpWrapper(open(self.fp.name, "Ur", 'latin-1'))
|
||||||
|
except:
|
||||||
|
print ("fallback to psfile")
|
||||||
fp = PSFile(self.fp)
|
fp = PSFile(self.fp)
|
||||||
|
|
||||||
# FIX for: Some EPS file not handled correctly / issue #302
|
# FIX for: Some EPS file not handled correctly / issue #302
|
||||||
|
|
Loading…
Reference in New Issue
Block a user