8000 Code cleanup by scuml · Pull Request #618 · tableau/server-client-python · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion tableauserverclient/datetime_helpers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import datetime

# This code below is from the python documentation for tzinfo: https://docs.python.org/2.3/lib/datetime-tzinfo.html
# This code below is from the python documentation for
# tzinfo: https://docs.python.org/2.3/lib/datetime-tzinfo.html

ZERO = datetime.timedelta(0)
HOUR = datetime.timedelta(hours=1)

Expand Down
3 changes: 1 addition & 2 deletions tableauserverclient/models/column_item.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import xml.etree.ElementTree as ET

from .property_decorators import property_is_enum, property_not_empty
from .exceptions import UnpopulatedPropertyError
from .property_decorators import property_not_empty


class ColumnItem(object):
Expand Down
12 changes: 8 additions & 4 deletions tableauserverclient/models/connection_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ def connection_type(self):
return self._connection_type

def __repr__(self):
return "<ConnectionItem#{_id} embed={embed_password} type={_connection_type} username={username}>"\
.format(**self.__dict__)
return (
"<ConnectionItem#{_id} embed={embed_password} "
"type={_connection_type} username={username}>".format(**self.__dict__)
)

@classmethod
def from_response(cls, resp, ns):
Expand Down Expand Up @@ -76,11 +78,13 @@ def from_xml_element(cls, parsed_response, ns):
connection_item.server_address = connection_xml.get('serverAddress', None)
connection_item.server_port = connection_xml.get('serverPort', None)

connection_credentials = connection_xml.find('.//t:connectionCredentials', namespaces=ns)
connection_credentials = connection_xml.find(
'.//t:connectionCredentials', namespaces=ns)

if connection_credentials is not None:

connection_item.connection_credentials = ConnectionCredentials.from_xml_element(connection_credentials)
connection_item.connection_credentials = ConnectionCredentials.from_xml_element(
connection_credentials)

return all_connection_items

Expand Down
4 changes: 0 additions & 4 deletions tableauserverclient/models/data_acceleration_report_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ def site(self):
def sheet_uri(self):
return self._sheet_uri

@property
def site(self):
return self._site

@property
def unaccelerated_session_count(self):
return self._unaccelerated_session_count
Expand Down
2 changes: 0 additions & 2 deletions tableauserverclient/models/database_item.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import xml.etree.ElementTree as ET

from .permissions_item import Permission

from .property_decorators import property_is_enum, property_not_empty, property_is_boolean
from .exceptions import UnpopulatedPropertyError

Expand Down
2 changes: 1 addition & 1 deletion tableauserverclient/models/flow_item.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import xml.etree.ElementTree as ET
from .exceptions import UnpopulatedPropertyError
from .property_decorators import property_not_nullable, property_is_boolean
from .property_decorators import property_not_nullable
from .tag_item import TagItem
from ..datetime_helpers import parse_datetime
import copy
Expand Down
2 changes: 1 addition & 1 deletion tableauserverclient/models/interval_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def interval(self, interval_value):
try:
if not (1 <= int(interval_value) <= 31):
raise ValueError(error)
except ValueError as e:
except ValueError:
if interval_value != "LastDay":
raise ValueError(error)

Expand Down
2 changes: 0 additions & 2 deletions tableauserverclient/models/job_item.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import xml.etree.ElementTree as ET
from ..datetime_helpers import parse_datetime
from .target import Target
from ..datetime_helpers import parse_datetime


class JobItem(object):
Expand Down
6 changes: 3 additions & 3 deletions tableauserverclient/models/pagination_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ def from_response(cls, resp, ns):
return pagination_item

@classmethod
def from_single_page_list(cls, l):
def from_single_page_list(cls, single_page_list):
item = cls()
item._page_number = 1
item._page_size = len(l)
item._total_available = len(l)
item._page_size = len(single_page_list)
item._total_available = len(single_page_list)

return item
9 changes: 7 additions & 2 deletions tableauserverclient/models/personal_access_token_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ def __init__(self, token_name, personal_access_token, site_id=''):

@property
def credentials(self):
return {'personalAccessTokenName': self.token_name, 'personalAccessTokenSecret': self.personal_access_token}
return {
'personalAccessTokenName': self.token_name,
'personalAccessTokenSecret': self.personal_access_token
}

def __repr__(self):
return "<PersonalAccessToken name={} token={}>".format(self.token_name, self.personal_access_token)
return "<PersonalAccessToken name={} token={}>".format(
self.token_name, self.personal_access_token
)
4 changes: 2 additions & 2 deletions tableauserverclient/models/project_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ def name(self, value):
def is_default(self):
return self.name.lower() == 'default'

def _parse_common_tags(self, project_xml):
def _parse_common_tags(self, project_xml, ns):
if not isinstance(project_xml, ET.Element):
project_xml = ET.fromstring(project_xml).find('.//t:project', namespaces=NAMESPACE)
project_xml = ET.fromstring(project_xml).find('.//t:project', namespaces=ns)

if project_xml is not None:
(_, name, description, content_permissions, parent_id) = self._parse_element(project_xml)
Expand Down
1 change: 0 additions & 1 deletion tableauserverclient/models/subscription_item.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import xml.etree.ElementTree as ET
from .exceptions import UnpopulatedPropertyError
from .target import Target


Expand Down
5 changes: 1 addition & 4 deletions tableauserverclient/models/table_item.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import xml.etree.ElementTree as ET

from .permissions_item import Permission
from .column_item import ColumnItem

from .property_decorators import property_is_enum, property_not_empty, property_is_boolean
from .property_decorators import property_not_empty, property_is_boolean
from .exceptions import UnpopulatedPropertyError


Expand Down
1 change: 0 additions & 1 deletion tableauserverclient/models/task_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ def from_response(cls, xml, ns, task_type=Type.ExtractRefresh):

@classmethod
def _parse_element(cls, element, ns):
schedule_id = None
schedule_item = None
target = None
last_run_at = None
Expand Down
10 changes: 3 additions & 7 deletions tableauserverclient/models/webhook_item.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import xml.etree.ElementTree as ET
from .exceptions import UnpopulatedPropertyError
from .property_decorators import property_not_nullable, property_is_boolean, property_is_data_acceleration_config
from .tag_item import TagItem
from .view_item import ViewItem
from .permissions_item import PermissionsRule
from ..datetime_helpers import parse_datetime

import re


Expand Down Expand Up @@ -86,4 +81,5 @@ def _parse_element(webhook_xml, ns):
return id, name, url, event, owner_id

def __repr__(self):
return "<Webhook id={} name={} url={} event={}>".format(self.id, self.name, self.url, self.event)
return "<Webhook id={} name={} url={} event={}>".format(
self.id, self.name, self.url, self.event)
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ def __init__(self, parent_srv):

@property
def baseurl(self):
return "{0}/sites/{1}/dataAccelerationReport".format(self.parent_srv.baseurl, self.parent_srv.site_id)
return "{0}/sites/{1}/dataAccelerationReport".format(
self.parent_srv.baseurl, self.parent_srv.site_id)

@api(version="3.8")
def get(self, req_options=None):
Expand Down
2 changes: 1 addition & 1 deletion tableauserverclient/server/endpoint/databases_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from .permissions_e D37C ndpoint import _PermissionsEndpoint
from .default_permissions_endpoint import _DefaultPermissionsEndpoint

from .. import RequestFactory, DatabaseItem, PaginationItem, PermissionsRule, Permission
from .. import RequestFactory, DatabaseItem, TableItem, PaginationItem, Permission

import logging

Expand Down
7 changes: 3 additions & 4 deletions tableauserverclient/server/endpoint/datasources_endpoint.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
from .endpoint import Endpoint, api, parameter_added_in
from .exceptions import InternalServerError, MissingRequiredFieldError
from .endpoint import api, parameter_added_in, Endpoint
from .permissions_endpoint import _PermissionsEndpoint
from .exceptions import MissingRequiredFieldError
from .fileuploads_endpoint import Fileuploads
from .resource_tagger import _ResourceTagger
from .. import RequestFactory, DatasourceItem, PaginationItem, ConnectionItem
from ...filesys_helpers import to_filename, make_download_path
from ...models.tag_item import TagItem
from ...models.job_item import JobItem

import os
import logging
import copy
Expand Down Expand Up @@ -129,7 +127,8 @@ def update(self, datasource_item):
server_response = self.put_request(url, update_req)
logger.info('Updated datasource item (ID: {0})'.format(datasource_item.id))
updated_datasource = copy.copy(datasource_item)
return updated_datasource._parse_common_elements(server_response.content, self.parent_srv.namespace)
return updated_datasource._parse_common_elements(
server_response.content, self.parent_srv.namespace)

# Update datasource connections
@api(version="2.3")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,22 @@
from .. import RequestFactory
from ...models import PermissionsRule

from .endpoint import Endpoint, api
from .endpoint import Endpoint
from .exceptions import MissingRequiredFieldError


logger = logging.getLogger(__name__)


class _DefaultPermissionsEndpoint(Endpoint):
''' Adds default-permission model to another endpoint
""" Adds default-permission model to another endpoint

Tableau default-permissions model applies only to databases and projects
and then takes an object type in the uri to set the defaults.
This class is meant to be instantated inside a parent endpoint which
has these supported endpoints
'''
"""

def __init__(self, parent_srv, owner_baseurl):
super(_DefaultPermissionsEndpoint, self).__init__(parent_srv)

Expand Down
2 changes: 1 addition & 1 deletion tableauserverclient/server/endpoint/endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def _check_status(self, server_response):
# we convert this to a better exception and pass through the raw
# response body
raise NonXMLResponseError(server_response.content)
except Exception as e:
except Exception:
# anything else re-raise here
raise

Expand Down
6 changes: 2 additions & 4 deletions tableauserverclient/server/endpoint/flows_endpoint.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
from .endpoint import Endpoint, api, parameter_added_in
from .endpoint import Endpoint, api
from .exceptions import InternalServerError, MissingRequiredFieldError
from .endpoint import api, parameter_added_in, Endpoint
from .permissions_endpoint import _PermissionsEndpoint
from .exceptions import MissingRequiredFieldError
from .fileuploads_endpoint import Fileuploads
from .resource_tagger import _ResourceTagger
from .. import RequestFactory, FlowItem, PaginationItem, ConnectionItem
from ...filesys_helpers import to_filename, make_download_path
from ...models.tag_item import TagItem
from ...models.job_item import JobItem

import os
import logging
import copy
Expand Down
2 changes: 1 addition & 1 deletion tableauserverclient/server/endpoint/groups_endpoint.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from .endpoint import Endpoint, api
from .exceptions import MissingRequiredFieldError
from ...models.exceptions import UnpopulatedPropertyError
from .. import RequestFactory, GroupItem, UserItem, PaginationItem
from ..pager import Pager

import logging

logger = logging.getLogger('tableau.endpoint.groups')
Expand Down
1 change: 1 addition & 0 deletions tableauserverclient/server/endpoint/jobs_endpoint.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from .endpoint import Endpoint, api
from .. import JobItem, BackgroundJobItem, PaginationItem
from ..request_options import RequestOptionsBase

import logging

try:
Expand Down
1 change: 1 addition & 0 deletions tableauserverclient/server/endpoint/metadata_endpoint.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from .endpoint import Endpoint, api
from .exceptions import GraphQLError

import logging
import json

Expand Down
7 changes: 4 additions & 3 deletions tableauserverclient/server/endpoint/permissions_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,22 @@

from .. import RequestFactory, PermissionsRule

from .endpoint import Endpoint, api
from .endpoint import Endpoint
from .exceptions import MissingRequiredFieldError


logger = logging.getLogger(__name__)


class _PermissionsEndpoint(Endpoint):
''' Adds permission model to another endpoint
""" Adds permission model to another endpoint

Tableau permissions model is identical between objects but they are nested under
the parent object endpoint (i.e. permissions for workbooks are under
/workbooks/:id/permission). This class is meant to be instantated inside a
parent endpoint which has these supported endpoints
'''
"""

def __init__(self, parent_srv, owner_baseurl):
super(_PermissionsEndpoint, self).__init__(parent_srv)

Expand Down
2 changes: 1 addition & 1 deletion tableauserverclient/server/endpoint/projects_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from .permissions_endpoint import _PermissionsEndpoint
from .default_permissions_endpoint import _DefaultPermissionsEndpoint

from .. import RequestFactory, ProjectItem, PaginationItem, PermissionsRule, Permission
from .. import RequestFactory, ProjectItem, PaginationItem, Permission

import logging

Expand Down
2 changes: 1 addition & 1 deletion tableauserverclient/server/endpoint/schedules_endpoint.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from .endpoint import Endpoint, api
from .exceptions import MissingRequiredFieldError
from .. import RequestFactory, PaginationItem, ScheduleItem, WorkbookItem, DatasourceItem, TaskItem
from .. import RequestFactory, PaginationItem, ScheduleItem, TaskItem
import logging
import copy
from collections import namedtuple
Expand Down
3 changes: 2 additions & 1 deletion tableauserverclient/server/endpoint/sites_endpoint.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from .endpoint import Endpoint, api
from .exceptions import MissingRequiredFieldError
from .. import RequestFactory, SiteItem, PaginationItem
import logging

import copy
import logging

logger = logging.getLogger('tableau.endpoint.sites')

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from .endpoint import Endpoint, api
from .exceptions import MissingRequiredFieldError
from .. import RequestFactory, SubscriptionItem, PaginationItem

import logging

logger = logging.getLogger('tableau.endpoint.subscriptions')
Expand Down
3 changes: 1 addition & 2 deletions tableauserverclient/server/endpoint/tables_endpoint.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from .endpoint import api, Endpoint
from .exceptions import MissingRequiredFieldError
from .permissions_endpoint import _PermissionsEndpoint
from .default_permissions_endpoint import _DefaultPermissionsEndpoint
from ..pager import Pager

from .. import RequestFactory, TableItem, ColumnItem, PaginationItem, PermissionsRule, Permission
from .. import RequestFactory, TableItem, ColumnItem, PaginationItem

import logging

Expand Down
1 change: 1 addition & 0 deletions tableauserverclient/server/endpoint/tasks_endpoint.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from .endpoint import Endpoint, api
from .exceptions import MissingRequiredFieldError
from .. import TaskItem, PaginationItem, RequestFactory

import logging

logger = logging.getLogger('tableau.endpoint.tasks')
Expand Down
3 changes: 2 additions & 1 deletion tableauserverclient/server/endpoint/users_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
from .exceptions import MissingRequiredFieldError
from .. import RequestFactory, UserItem, WorkbookItem, PaginationItem
from ..pager import Pager
import logging

import copy
import logging

logger = logging.getLogger('tableau.endpoint.users')

Expand Down
Loading
0