Skip to content
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
16 changes: 13 additions & 3 deletions tableaudocumentapi/xfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,22 @@ def temporary_directory(*args, **kwargs):


def find_file_in_zip(zip):
_VALID_ROOTS_AND_EXTS = {
'workbook': ('.twb', '.twbx'),
'datasource': ('.tds', '.tdsx')
}

for filename in zip.namelist():
_, file_extension = os.path.splitext(filename)

try:
with zip.open(filename) as xml_candidate:
ET.parse(xml_candidate).getroot().tag in (
'workbook', 'datasource')
return filename
root_tag = ET.parse(xml_candidate).getroot().tag
if root_tag in _VALID_ROOTS_AND_EXTS.keys() and \
file_extension in _VALID_ROOTS_AND_EXTS.get(root_tag, None):
return filename
else:
raise Exception # TableauInvalidFileException or something should go here
except ET.ParseError:
# That's not an XML file by gosh
pass
Expand Down