@@ -150,41 +150,13 @@ def open_workbook(filename=None,
150
150
:returns: An instance of the :class:`~xlrd.book.Book` class.
151
151
"""
152
152
153
- peeksz = 4
154
- if file_contents :
155
- peek = file_contents [:peeksz ]
156
- else :
157
- filename = os .path .expanduser (filename )
158
- with open (filename , "rb" ) as f :
159
- peek = f .read (peeksz )
160
- if peek == b"PK\x03 \x04 " : # a ZIP file
161
- if file_contents :
162
- zf = zipfile .ZipFile (timemachine .BYTES_IO (file_contents ))
163
- else :
164
- zf = zipfile .ZipFile (filename )
165
-
166
- def convert_filename (name ):
167
- return name .replace ('\\ ' , '/' ).lower ()
168
-
169
- # Workaround for some third party files that use forward slashes and
170
- # lower case names. We map the expected name in lowercase to the
171
- # actual filename in the zip container.
172
- component_names = dict ([(convert_filename (name ), name )
173
- for name in zf .namelist ()])
153
+ file_format = inspect_format (filename , file_contents )
154
+ # We have to let unknown file formats pass through here, as some ancient
155
+ # files that xlrd can parse don't start with the expected signature.
156
+ if file_format and file_format != 'xls' :
157
+ raise XLRDError (FILE_FORMAT_DESCRIPTIONS [file_format ]+ '; not supported' )
174
158
175
- if verbosity :
176
- logfile .write ('ZIP component_names:\n ' )
177
- pprint .pprint (component_names , logfile )
178
- if 'xl/workbook.xml' in component_names :
179
- raise NotImplementedError ('no xlsx!' )
180
- if 'xl/workbook.bin' in component_names :
181
- raise XLRDError ('Excel 2007 xlsb file; not supported' )
182
- if 'content.xml' in component_names :
183
- raise XLRDError ('Openoffice.org ODS file; not supported' )
184
- raise XLRDError ('ZIP file contents not a known type of workbook' )
185
-
186
- from . import book
187
- bk = book .open_workbook_xls (
159
+ bk = open_workbook_xls (
188
160
filename = filename ,
189
161
logfile = logfile ,
190
162
verbosity = verbosity ,
@@ -196,6 +168,7 @@ def convert_filename(name):
196
168
ragged_rows = ragged_rows ,
197
169
ignore_workbook_corruption = ignore_workbook_corruption ,
198
170
)
171
+
199
172
return bk
200
173
201
174
0 commit comments