Exemplo n.º 1
0
 def assert_at_least_version(self, version):
     server_version = Version(self.version or "0.0")
     minimum_supported = Version(version)
     if server_version < minimum_supported:
         error = "This endpoint is not available in API version {}. Requires {}".format(
             server_version, minimum_supported)
         raise EndpointUnavailableError(error)
Exemplo n.º 2
0
 def wrapper(self, *args, **kwargs):
     server_version = Version(self.parent_srv.version)
     minimum_supported = Version(version)
     if server_version < minimum_supported:
         error = "This endpoint is not available in API version {}. Requires {}".format(
             server_version, minimum_supported)
         raise EndpointUnavailableError(error)
     return func(self, *args, **kwargs)
Exemplo n.º 3
0
 def wrapper(self, *args, **kwargs):
     import warnings
     server_ver = Version(self.parent_srv.version or "0.0")
     params_to_check = set(params) & set(kwargs)
     for p in params_to_check:
         min_ver = Version(str(params[p]))
         if server_ver < min_ver:
             error = "{!r} not available in {}, it will be ignored. Added in {}".format(p, server_ver, min_ver)
             warnings.warn(error)
     return func(self, *args, **kwargs)
Exemplo n.º 4
0
def xml_open(filename):
    # Determine if this is a twb or twbx and get the xml root
    if zipfile.is_zipfile(filename):
        tree = get_xml_from_archive(filename)
    else:
        tree = ET.parse(filename)
    file_version = Version(tree.getroot().attrib.get('version', '0.0'))
    if file_version < MIN_SUPPORTED_VERSION:
        raise TableauVersionNotSupportedException(file_version)
    return tree
Exemplo n.º 5
0
def xml_open(filename, expected_root=None):

    if zipfile.is_zipfile(filename):
        tree = get_xml_from_archive(filename)
    else:
        tree = ET.parse(filename)

    tree_root = tree.getroot()

    file_version = Version(tree_root.attrib.get('version', '0.0'))

    if file_version < MIN_SUPPORTED_VERSION:
        raise TableauVersionNotSupportedException(file_version)

    if expected_root and (expected_root != tree_root.tag):
        raise TableauInvalidFileException(
            "'{}'' is not a valid '{}' file".format(filename, expected_root))

    return tree
def xml_open(filename, expected_root=None):
    """Opens the provided 'filename'. Handles detecting if the file is an archive,
    detecting the document version, and validating the root tag."""

    # Is the file a zip (.twbx or .tdsx)
    if zipfile.is_zipfile(filename):
        tree = get_xml_from_archive(filename)
    else:
        tree = ET.parse(filename)

    # Is the file a supported version
    tree_root = tree.getroot()
    file_version = Version(tree_root.attrib.get('version', '0.0'))

    if file_version < MIN_SUPPORTED_VERSION:
        raise TableauVersionNotSupportedException(file_version)

    # Does the root tag match the object type (workbook or data source)
    if expected_root and (expected_root != tree_root.tag):
        raise TableauInvalidFileException(
            "'{}'' is not a valid '{}' file".format(filename, expected_root))

    return tree
import contextlib
import os
import shutil
import tempfile
import zipfile
import xml.etree.ElementTree as ET

try:
    from distutils2.version import NormalizedVersion as Version
except ImportError:
    from distutils.version import LooseVersion as Version

MIN_SUPPORTED_VERSION = Version("9.0")


class TableauVersionNotSupportedException(Exception):
    pass


class TableauInvalidFileException(Exception):
    pass


def xml_open(filename, expected_root=None):
    """Opens the provided 'filename'. Handles detecting if the file is an archive,
    detecting the document version, and validating the root tag."""

    # Is the file a zip (.twbx or .tdsx)
    if zipfile.is_zipfile(filename):
        tree = get_xml_from_archive(filename)
    else: