Exemplo n.º 1
0
    def test_trans_except(self):
        """trans_except should return trans table mapping non-good chars to x"""
        a = trans_except('Aa', '-')
        none = trans_except('', '*')
        some = trans_except('zxcvbnm,.zxcvbnm,.', 'V')

        self.assertEqual('abcABA'.translate(a), 'a--A-A')
        self.assertEqual(''.translate(a), '')
        self.assertEqual('12345678'.translate(a), '--------')

        self.assertEqual(''.translate(none), '')
        self.assertEqual('abcdeEFGHI12345&*(!@'.translate(none), '*'*20)

        self.assertEqual('qazwsxedcrfv'.translate(some),'VVzVVxVVcVVv') 
Exemplo n.º 2
0
    def test_trans_except(self):
        """trans_except should return trans table mapping non-good chars to x"""
        a = trans_except('Aa', '-')
        none = trans_except('', '*')
        some = trans_except('zxcvbnm,.zxcvbnm,.', 'V')

        self.assertEqual('abcABA'.translate(a), 'a--A-A')
        self.assertEqual(''.translate(a), '')
        self.assertEqual('12345678'.translate(a), '--------')

        self.assertEqual(''.translate(none), '')
        self.assertEqual('abcdeEFGHI12345&*(!@'.translate(none), '*' * 20)

        self.assertEqual('qazwsxedcrfv'.translate(some), 'VVzVVxVVcVVv')
Exemplo n.º 3
0
    def test_trans_except(self):
        """trans_except should return trans table mapping non-good chars to x"""
        a = trans_except("Aa", "-")
        none = trans_except("", "*")
        some = trans_except("zxcvbnm,.zxcvbnm,.", "V")

        self.assertEqual("abcABA".translate(a), "a--A-A")
        self.assertEqual("".translate(a), "")
        self.assertEqual("12345678".translate(a), "--------")

        self.assertEqual("".translate(none), "")
        self.assertEqual("abcdeEFGHI12345&*(!@".translate(none), "*" * 20)

        self.assertEqual("qazwsxedcrfv".translate(some), "VVzVVxVVcVVv")
Exemplo n.º 4
0
    def __init__(self, chars, name=None, invert_charset=False, strip_f=strip, default_char=None):

        """Returns new CharFilter object."""
        self.Chars = chars
        self.Name = name
        self.Invert = invert_charset
        if invert_charset:
            if default_char:
                trans_table = trans_all(chars, default_char)
                self.Filter = lambda s: s.translate(trans_table)
            else:
                self.Filter = exclude_chars(chars)
        else:
            if default_char:
                trans_table = trans_except(chars, default_char)
                self.Filter = lambda s: s.translate(trans_table)
            else:
                self.Filter = keep_chars(chars)
        self.stripF = strip_f
Exemplo n.º 5
0
 def __init__(self,
              chars,
              name=None,
              invert_charset=False,
              strip_f=strip,
              default_char=None):
     """Returns new CharFilter object."""
     self.Chars = chars
     self.Name = name
     self.Invert = invert_charset
     if invert_charset:
         if default_char:
             trans_table = trans_all(chars, default_char)
             self.Filter = lambda s: s.translate(trans_table)
         else:
             self.Filter = exclude_chars(chars)
     else:
         if default_char:
             trans_table = trans_except(chars, default_char)
             self.Filter = lambda s: s.translate(trans_table)
         else:
             self.Filter = keep_chars(chars)
     self.stripF = strip_f