88from werkzeug .datastructures import FileStorage as FlaskFileStorage
99from cgi import FieldStorage
1010
11+ from ckan .plugins .toolkit import _
12+
1113from ckanext .recombinant .datatypes import canonicalize
1214from ckanext .recombinant .errors import BadExcelData
1315
1719
1820
1921def read_excel (f : Union [str , FlaskFileStorage , FieldStorage ],
20- expected_sheet_names : List [str ],
22+ expected_sheet_names : List [str ] = [],
23+ bad_sheet_names : List [str ] = [],
2124 file_contents : Optional [str ] = None ) -> Iterator [Any ]:
2225 """
2326 Return a generator that opens the excel file f (name or file object)
@@ -36,6 +39,12 @@ def read_excel(f: Union[str, FlaskFileStorage, FieldStorage],
3639 for sheetname in wb .sheetnames :
3740 if sheetname == 'reference' :
3841 return
42+ if sheetname in bad_sheet_names :
43+ raise BadExcelData (_ ('Invalid file for this data type. ' +
44+ 'Sheet must be labeled "{0}", ' +
45+ 'but you supplied a sheet labeled "{1}"' ).format (
46+ '"/"' .join (sorted (expected_sheet_names )),
47+ sheetname ))
3948 if sheetname not in expected_sheet_names :
4049 # NOTE: some Excel extensions and Macros create fully hidden
4150 # worksheets that act as a sort of database/index cache
0 commit comments