forked from bryanthowell-tableau/tableau_tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated the samples to show the new get_permissions_obj() method acro…
…ss the board. Also added a TableauRestXml class to hold static info and methods that various other objects might want to access. This is similar to the old TableauBase class but there is not not a need for everything to descend from it
- Loading branch information
Bryant Howell
committed
Dec 11, 2019
1 parent
5d55b87
commit 3635a1c
Showing
7 changed files
with
117 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
# This is intended to be full of static helper methods | ||
import xml.etree.ElementTree as ET | ||
from typing import Union, Optional, List, Dict, Tuple | ||
import re | ||
|
||
class TableauRestXml: | ||
tableau_namespace = 'http://tableau.com/api' | ||
ns_map = {'t': 'http://tableau.com/api'} | ||
ns_prefix = '{' + ns_map['t'] + '}' | ||
# ET.register_namespace('t', ns_map['t']) | ||
# Generic method for XML lists for the "query" actions to name -> id dict | ||
@staticmethod | ||
def convert_xml_list_to_name_id_dict(xml_obj: ET.Element) -> Dict: | ||
d = {} | ||
for element in xml_obj: | ||
e_id = element.get("id") | ||
# If list is collection, have to run one deeper | ||
if e_id is None: | ||
for list_element in element: | ||
e_id = list_element.get("id") | ||
name = list_element.get("name") | ||
d[name] = e_id | ||
else: | ||
name = element.get("name") | ||
d[name] = e_id | ||
return d | ||
|
||
# Repeat of above method with shorter name | ||
@staticmethod | ||
def xml_list_to_dict(xml_obj: ET.Element) -> Dict: | ||
d = {} | ||
for element in xml_obj: | ||
e_id = element.get("id") | ||
# If list is collection, have to run one deeper | ||
if e_id is None: | ||
for list_element in element: | ||
e_id = list_element.get("id") | ||
name = list_element.get("name") | ||
d[name] = e_id | ||
else: | ||
name = element.get("name") | ||
d[name] = e_id | ||
return d | ||
|
||
@staticmethod | ||
def luid_name_dict_from_xml(xml_obj: ET.Element) -> Dict: | ||
d = {} | ||
for element in xml_obj: | ||
e_id = element.get("id") | ||
# If list is collection, have to run one deeper | ||
if e_id is None: | ||
for list_element in element: | ||
e_id = list_element.get("id") | ||
name = list_element.get("name") | ||
d[e_id] = name | ||
else: | ||
name = element.get("name") | ||
d[e_id] = name | ||
return d | ||
|
||
@staticmethod | ||
def luid_content_url_dict_from_xml(xml_obj: ET.Element) -> Dict: | ||
d = {} | ||
for element in xml_obj: | ||
e_id = element.get("id") | ||
# If list is collection, have to run one deeper | ||
if e_id is None: | ||
for list_element in element: | ||
e_id = list_element.get("id") | ||
name = list_element.get("contentUrl") | ||
d[e_id] = name | ||
else: | ||
name = element.get("contentUrl") | ||
d[e_id] = name | ||
return d | ||
|
||
# This corrects for the first element in any response by the plural collection tag, which leads to differences | ||
# with the XPath search currently | ||
@staticmethod | ||
def make_xml_list_iterable(xml_obj: ET.Element) -> List[ET.Element]: | ||
pass | ||
|
||
# 32 hex characters with 4 dashes | ||
@staticmethod | ||
def is_luid(val: str) -> bool: | ||
luid_pattern = r"[0-9a-fA-F]*-[0-9a-fA-F]*-[0-9a-fA-F]*-[0-9a-fA-F]*-[0-9a-fA-F]*" | ||
if len(val) == 36: | ||
if re.match(luid_pattern, val) is not None: | ||
return True | ||
else: | ||
return False | ||
else: | ||
return False |