Skip to content

Commit

Permalink
FIX: Sanitization
Browse files Browse the repository at this point in the history
  • Loading branch information
larsoner committed Feb 8, 2024
1 parent 3fda5a8 commit 89c2e1f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
27 changes: 15 additions & 12 deletions tvtk/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,21 @@ def get_tvtk_name(vtk_name):
'XMLDataReader'
"""
if vtk_name[:3] == 'vtk':
name = vtk_name[3:]
dig2name = {'1': 'One', '2': 'Two', '3': 'Three', '4': 'Four',
'5': 'Five', '6': 'Six', '7': 'Seven', '8': 'Eight',
'9': 'Nine', '0': 'Zero'}

if name[0] in string.digits:
return dig2name[name[0]] + name[1:]
else:
return name
else:
return vtk_name
name = vtk_name
if name.startswith('vtk'):
name = name[3:]
return _sanitize_name(name)


def _sanitize_name(name):
"""Turn a VTK name (like a class or method def) into a valid Python var name."""
dig2name = {'1': 'One', '2': 'Two', '3': 'Three', '4': 'Four',
'5': 'Five', '6': 'Six', '7': 'Seven', '8': 'Eight',
'9': 'Nine', '0': 'Zero'}

if name[0].isdigit():
name = dig2name[name[0]] + name[1:]
return name


def is_version_9():
Expand Down
5 changes: 4 additions & 1 deletion tvtk/wrapper_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

# Local imports (these are relative imports because the package is not
# installed when these modules are imported).
from .common import get_tvtk_name, camel2enthought, vtk_major_version
from .common import get_tvtk_name, camel2enthought, vtk_major_version, _sanitize_name

from . import vtk_parser
from . import indenter
Expand Down Expand Up @@ -948,6 +948,7 @@ def _reform_name(self, name, method=False):
# are usually special methods.
return name

name = _sanitize_name(name)
res = camel2enthought(name)
if keyword.iskeyword(res):
return res + '_'
Expand Down Expand Up @@ -1415,6 +1416,8 @@ def _write_property(self, out, t_name, vtk_get_meth, vtk_set_meth,
setter is treated as if it accepts a list of parameters. If
not the setter is treated as if it accepts a single parameter.
"""
assert t_name # nonempty
assert not t_name[0].isdigit(), t_name # would be a SyntaxError
indent = self.indent
getter = '_get_%s'%t_name
vtk_get_name = vtk_get_meth.__name__
Expand Down

0 comments on commit 89c2e1f

Please sign in to comment.