Skip to content
This repository has been archived by the owner on May 4, 2020. It is now read-only.

changes in Bitmap._process_bitmap #61

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions xlwt/Bitmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from BIFFRecords import BiffRecord
from struct import pack, unpack

import glob

def _size_col(sheet, col):
return sheet.col_width(col)
Expand Down Expand Up @@ -192,12 +193,20 @@ def _process_bitmap(bitmap):

"""
# Open file and binmode the data in case the platform needs it.
fh = file(bitmap, "rb")
try:
# Slurp the file into a string.
data = fh.read()
finally:
fh.close()
if hasattr(getattr(bitmap, "read",None),'__call__'):#StringIO object
data=bitmap.read()
elif glob.glob(bitmap):#just file - Open file and binmode the data in case the platform needs it.
fh = file(bitmap, "rb")
try:
# Slurp the file into a string.
data=fh.read()
finally:
fh.close()
elif bitmap[:4]=='424d':#hex data - BMP signature
data=bitmap.decode("hex")
else:#binary data
data=bitmap

# Check that the file is big enough to be a bitmap.
if len(data) <= 0x36:
raise Exception("bitmap doesn't contain enough data.")
Expand Down