blob: 14e8e87f3a0c4fbff8def403ac20d1197aeafbe4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
"""String class definition lives here"""
from .param import Param
import re
class String(Param):
"""String param class definition
Args:
value: a string
classname: name of the class to which the param instance will belong
"""
def __init__(self, value, classname=""):
super(String, self).__init__(classname=classname)
if value:
try:
self.value = self.sanitize(value)
except Exception as e:
self.err_warn("Unable to sanitize: %s\nreason:%s" % (str(value), str(e)))
else:
self.value = ""
def sanitize(self, s):
"""Removes non-word characters from the string for security reasons"""
return re.sub(r'\W+', '', s)
|