예제 #1
0
    def test_exclude_chars(self):
        """exclude_chars returns string containing only chars not in exclude"""
        
        f = exclude_chars('ab c3*[')
        self.assertEqual(f(''),'') #empty
        self.assertRaises(AttributeError,f,None) #None
        
        #one character, case sensitive
        self.assertEqual(f('b'),'')
        self.assertEqual(f('g'),'g')
        self.assertEqual(f('xyz123'),'xyz12')
        self.assertEqual(f('xyz  123'),'xyz12')
        
        #more characters, case sensitive
        self.assertEqual(f('axxxbxxxcxxx'),'xxxxxxxxx')

        # case insensitive
        f = exclude_chars('AbC',False)
        self.assertEqual(f('abcdef'),'def')
        self.assertEqual(f('ABCDEF'),'DEF')
        self.assertEqual(f('aBcDeF'),'DeF')
예제 #2
0
    def test_exclude_chars(self):
        """exclude_chars returns string containing only chars not in exclude"""

        f = exclude_chars('ab c3*[')
        self.assertEqual(f(''), '')  #empty
        self.assertRaises(AttributeError, f, None)  #None

        #one character, case sensitive
        self.assertEqual(f('b'), '')
        self.assertEqual(f('g'), 'g')
        self.assertEqual(f('xyz123'), 'xyz12')
        self.assertEqual(f('xyz  123'), 'xyz12')

        #more characters, case sensitive
        self.assertEqual(f('axxxbxxxcxxx'), 'xxxxxxxxx')

        # case insensitive
        f = exclude_chars('AbC', False)
        self.assertEqual(f('abcdef'), 'def')
        self.assertEqual(f('ABCDEF'), 'DEF')
        self.assertEqual(f('aBcDeF'), 'DeF')
예제 #3
0
    def test_exclude_chars(self):
        """exclude_chars returns string containing only chars not in exclude"""

        f = exclude_chars("ab c3*[")
        self.assertEqual(f(""), "")  # empty
        self.assertRaises(AttributeError, f, None)  # None

        # one character, case sensitive
        self.assertEqual(f("b"), "")
        self.assertEqual(f("g"), "g")
        self.assertEqual(f("xyz123"), "xyz12")
        self.assertEqual(f("xyz  123"), "xyz12")

        # more characters, case sensitive
        self.assertEqual(f("axxxbxxxcxxx"), "xxxxxxxxx")

        # case insensitive
        f = exclude_chars("AbC", False)
        self.assertEqual(f("abcdef"), "def")
        self.assertEqual(f("ABCDEF"), "DEF")
        self.assertEqual(f("aBcDeF"), "DeF")
예제 #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
예제 #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