From 82917e4af717f53b8806ea1cdc7f0bde2ab0d0f5 Mon Sep 17 00:00:00 2001 From: Bryant Howell Date: Fri, 3 Jan 2020 14:51:35 -0600 Subject: [PATCH] Bugfixes on logger and replaced the isinstance() type checking with type( ).__name__ so no need to import classes to check --- logger.py | 8 ++++---- tableau_rest_api/published_content.py | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/logger.py b/logger.py index 503898b..d291acd 100644 --- a/logger.py +++ b/logger.py @@ -53,7 +53,7 @@ def start_log_block(self): short_class = short_class[:-2] cur_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()).encode('utf-8') - log_line = '{}vv-- {} : {} {} started --------vv\n'.format(" "*self.log_depth, cur_time, short_class, caller_function_name) + log_line = '{}vv-- {} : {} {} started --------vv\n'.format(" "*self.log_depth, str(cur_time), short_class, caller_function_name) # Only move the log depth in debug mode if self._log_modes['debug'] is True: self.log_depth += 2 @@ -68,7 +68,7 @@ def end_log_block(self): cur_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()).encode('utf-8') if self._log_modes['debug'] is True: self.log_depth -= 2 - log_line = '{}^^-- {} : {} {} ended --------^^\n'.format(" "*self.log_depth, cur_time, short_class, caller_function_name) + log_line = '{}^^-- {} : {} {} ended --------^^\n'.format(" "*self.log_depth, str(cur_time), short_class, caller_function_name) self.__log_handle.write(log_line.encode('utf-8')) @@ -78,9 +78,9 @@ def log_uri(self, uri: str, verb: str): def log_xml_request(self, xml: Union[ET.Element, str], verb: str, uri: str): if self._log_modes['request'] is True: if isinstance(xml, str): - self.log('[{}}] \n{}'.format(verb.upper(), xml)) + self.log('[{}] \n{}'.format(verb.upper(), xml)) else: - self.log('[{}}] \n{}'.format(verb.upper(), ET.tostring(xml))) + self.log('[{}] \n{}'.format(verb.upper(), ET.tostring(xml))) else: self.log('[{}] {}'.format(verb.upper(), uri)) diff --git a/tableau_rest_api/published_content.py b/tableau_rest_api/published_content.py index a7ab699..9aa64a2 100644 --- a/tableau_rest_api/published_content.py +++ b/tableau_rest_api/published_content.py @@ -950,18 +950,18 @@ def are_permissions_locked(self) -> bool: def lock_permissions(self): self.start_log_block() if self.permissions_locked is False: - if(type(self.t_rest_api).__name__.contains('TableauRestApiConnection')): + if(type(self.t_rest_api).__name__.find('TableauRestApiConnection') != -1): self.t_rest_api.update_project(self.luid, locked_permissions=True) - if(type(self.t_rest_api).__name__.contains('TableauServerRest')): + if(type(self.t_rest_api).__name__.find('TableauServerRest') != -1): self.t_rest_api.projects.update_project(self.luid, locked_permissions=True) self.end_log_block() def unlock_permissions(self): self.start_log_block() if self.permissions_locked is True: - if(isinstance(self.t_rest_api, TableauRestApiConnection)): + if(type(self.t_rest_api).__name__.find('TableauRestApiConnection') != -1): self.t_rest_api.update_project(self.luid, locked_permissions=False) - if(isinstance(self.t_rest_api, TableauServerRest)): + if(type(self.t_rest_api).__name__.find('TableauServerRest') != -1): self.t_rest_api.projects.update_project(self.luid, locked_permissions=False) self.end_log_block() @@ -1047,9 +1047,9 @@ def parent_project_luid(self) -> str: def query_child_projects(self) -> ET.Element: self.start_log_block() - if (isinstance(self.t_rest_api, TableauRestApiConnection)): + if (type(self.t_rest_api).__name__.find('TableauRestApiConnection') != -1): projects = self.t_rest_api.query_projects() - elif (isinstance(self.t_rest_api, TableauServerRest)): + elif(type(self.t_rest_api).__name__.find('TableauServerRest') != -1): projects = self.t_rest_api.projects.query_projects() else: raise InvalidOptionException('t_rest_api needs to be either TableauRestApiConnection or TableauServerRest descended')