Expose the sanitize method, since it's necessary for accessing columns.

This commit is contained in:
Mike Auty
2018-03-14 01:07:58 +00:00
parent dd41ea1cd1
commit cbce5c6184
2 changed files with 8 additions and 3 deletions
@@ -127,6 +127,11 @@ class TreeGrid(object, metaclass = ABCMeta):
:param generator: A generator that populates the tree/grid structure
"""
@staticmethod
@abstractmethod
def sanitize_name(text: str) -> str:
"""Method used to sanitize column names for TreeNodes"""
@abstractmethod
def populate(self,
func: VisitorSignature = None,
+3 -3
View File
@@ -150,7 +150,7 @@ class TreeGrid(interfaces.renderers.TreeGrid):
"Column {}'s type is not a simple type: {}".format(name, column_type.__class__.__name__))
converted_columns.append(interfaces.renderers.Column(len(converted_columns), name, column_type))
self.RowStructure = collections.namedtuple("RowStructure",
[self._sanitize(column.name) for column in converted_columns])
[self.sanitize_name(column.name) for column in converted_columns])
self._columns = converted_columns
if generator is None:
generator = []
@@ -159,11 +159,11 @@ class TreeGrid(interfaces.renderers.TreeGrid):
self._generator = generator
@staticmethod
def _sanitize(text: str) -> str:
def sanitize_name(text: str) -> str:
output = ""
for letter in text.lower():
if letter != ' ':
output += (letter if letter in 'abcdefghiljklmnopqrstuvwxyz_' else '_')
output += (letter if letter in 'abcdefghiljklmnopqrstuvwxyz_0123456789' else '_')
return output
def populate(self,