88
99import xml .etree .ElementTree as ET
1010
11- from tableaudocumentapi import Datasource , archivefile
11+ from tableaudocumentapi import Datasource , containerfile
1212
1313###########################################################################
1414#
@@ -37,7 +37,7 @@ def __init__(self, filename):
3737
3838 # Determine if this is a twb or twbx and get the xml root
3939 if zipfile .is_zipfile (self ._filename ):
40- self ._workbookTree = archivefile .get_xml_from_archive (
40+ self ._workbookTree = containerfile .get_xml_from_archive (
4141 self ._filename )
4242 else :
4343 self ._workbookTree = ET .parse (self ._filename )
@@ -74,13 +74,7 @@ def save(self):
7474 """
7575
7676 # save the file
77-
78- if zipfile .is_zipfile (self ._filename ):
79- archivefile .save_into_archive (
80- self ._workbookTree , filename = self ._filename )
81- else :
82- self ._workbookTree .write (
83- self ._filename , encoding = "utf-8" , xml_declaration = True )
77+ containerfile ._save_file (self ._filename , self ._workbookTree )
8478
8579 def save_as (self , new_filename ):
8680 """
@@ -93,13 +87,8 @@ def save_as(self, new_filename):
9387 Nothing.
9488
9589 """
96-
97- if zipfile .is_zipfile (self ._filename ):
98- archivefile .save_into_archive (
99- self ._workbookTree , self ._filename , new_filename )
100- else :
101- self ._workbookTree .write (
102- new_filename , encoding = "utf-8" , xml_declaration = True )
90+ containerfile ._save_file (
91+ self ._filename , self ._workbookTree , new_filename )
10392
10493 ###########################################################################
10594 #
@@ -115,8 +104,3 @@ def _prepare_datasources(self, xmlRoot):
115104 datasources .append (ds )
116105
117106 return datasources
118-
119- @staticmethod
120- def _is_valid_file (filename ):
121- fileExtension = os .path .splitext (filename )[- 1 ].lower ()
122- return fileExtension in ('.twb' , '.tds' )
0 commit comments