Source code for dp_tornado.helper.string.check

# -*- coding: utf-8 -*-


from dp_tornado.engine.helper import Helper as dpHelper


[docs]class CheckHelper(dpHelper):
[docs] def exist_repeated_text(self, s, criteria=3): if not self.helper.misc.type.check.string(s): return False k = s[0] n = 0 for c in s: if c == k: n += 1 if n >= criteria: return True else: k = c n = 1 return False
[docs] def alphanumericpunc(self, s, add=None): return self._check( s, self.helper.string.digits + self.helper.string.ascii_letters + self.helper.string.punctuation, add)
[docs] def alphanumeric(self, s, add=None): return self._check(s, self.helper.string.digits + self.helper.string.ascii_letters, add)
[docs] def alphabet(self, s, add=None): return self._check(s, self.helper.string.ascii_letters, add)
[docs] def numeric(self, s, add=None): return self._check(s, self.helper.string.digits, add)
def _check(self, s, criteria, add): if not self.helper.misc.type.check.string(s): return False add = add if add else '' v = any(char not in set(c for c in criteria + add) for char in s) return True if not v else False