#
#	dp for Tornado
#		YoungYong Park (youngyongpark@gmail.com)
#		2014.11.11
#


from __future__ import absolute_import
from engine.helper import Helper as dpHelper

import string
import random


class StringHelper(dpHelper):
    def random_string(self, length):
        return ''.join(random.sample(string.ascii_letters, length))

    def username_from_email(self, email):
        pos = email.find('@')

        if pos != -1:
            return email[:pos]
        else:
            return None

    def check_username_length_from_email(self, email, length):
        username = self.username_from_email(email)

        if username:
            return True if len(username) <= length else False
        else:
            return False
@@ -722,12 +722,903 @@
 return False
+%0A%0A    def check_exist_repeated_text(self, s, criteria=3):%0A        if not self.is_string(s):%0A            return None%0A%0A        k = s%5B0%5D%0A        n = 0%0A%0A        for c in s:%0A            if c == k:%0A                n += 1%0A%0A                if n %3E= criteria:%0A                    return True%0A%0A            else:%0A                k = c%0A                n = 1%0A%0A        return False%0A%0A    def to_str(self, s, preserve_none=True):%0A        if s is None:%0A            return s%0A%0A        if not self.is_string(s):%0A            s = str(s)%0A%0A        if type(s) == unicode_type:%0A            return s.encode('UTF-8')%0A        else:%0A            return s%0A%0A    def to_unicode(self, s, preserve_none=True):%0A        if s is None:%0A            return s%0A%0A        if not self.is_string(s):%0A            s = str(s)%0A%0A        if type(s) != unicode_type:%0A            return s.decode('unicode-escape')%0A        else:%0A            return s

Add some functions for string helper.