>>> PrintableString().allowable_chars
frozenset([' ', "'", ..., 'z'])
+ >>> obj = PrintableString("foo*bar", allow_asterisk=True)
+ PrintableString PrintableString foo*bar
+ >>> obj.allow_asterisk, obj.allow_ampersand
+ (True, False)
"""
__slots__ = ()
tag_default = tag_encode(19)
value, bounds, impl, expl, default, optional, _decoded,
)
+ @property
+ def allow_asterisk(self):
+ """Is asterisk character allowed?
+ """
+ return self._asterisk <= self._allowable_chars
+
+ @property
+ def allow_ampersand(self):
+ """Is ampersand character allowed?
+ """
+ return self._ampersand <= self._allowable_chars
+
def _value_sanitize(self, value):
value = super(PrintableString, self)._value_sanitize(value)
if not frozenset(value) <= self._allowable_chars:
expl=self._expl if expl is None else expl,
default=self.default if default is None else default,
optional=self.optional if optional is None else optional,
- allow_asterisk=self._asterisk <= self._allowable_chars,
- allow_ampersand=self._ampersand <= self._allowable_chars,
+ allow_asterisk=self.allow_asterisk,
+ allow_ampersand=self.allow_ampersand,
)
("&", {"allow_ampersand": True}),
("&*", {"allow_asterisk": True, "allow_ampersand": True}),
):
- s = "hello invalid " + c
+ s = "hello invalid"
+ obj = self.base_klass(s)
+ for prop in kwargs.keys():
+ self.assertFalse(getattr(obj, prop))
+ s += c
with assertRaisesRegex(self, DecodeError, "non-printable"):
self.base_klass(s)
self.base_klass(s, **kwargs)
klass = self.base_klass(**kwargs)
obj = klass(s)
+ for prop in kwargs.keys():
+ self.assertTrue(getattr(obj, prop))
obj = copy(obj)
obj(s)
+ for prop in kwargs.keys():
+ self.assertTrue(getattr(obj, prop))
class TestTeletexString(