Exemplo n.º 1
0
    def _normPyStr(self, valu):

        info = {}
        norm = str(valu)

        if self.opts['lower']:
            norm = norm.lower()

        if self.opts['strip']:
            norm = norm.strip()

        if self.opts['onespace']:
            norm = s_chop.onespace(norm)

        if self.envals is not None:
            if norm not in self.envals:
                raise s_exc.BadTypeValu(valu=valu,
                                        name=self.name,
                                        enums=self.info.get('enums'),
                                        mesg='Value not in enums')

        if self.regex is not None:

            match = self.regex.match(norm)
            if match is None:
                raise s_exc.BadTypeValu(name=self.name,
                                        valu=valu,
                                        mesg='regex does not match')

            subs = match.groupdict()
            if subs:
                info['subs'] = subs

        return norm, info
Exemplo n.º 2
0
 def test_chop_onespace(self):
     tvs = [
         ('asdfasdf  asdfasdf ', 'asdfasdf asdfasdf'),
         ('asdfasdf ', 'asdfasdf'),
         ('asdf', 'asdf'),
         ('  asdfasdf  ', 'asdfasdf'),
         (' asdf  asdf    asdf \t \t asdf asdf   ', 'asdf asdf asdf asdf asdf'),
         (' ', ''),
         ('foo   bar baz', 'foo bar baz'),
     ]
     for iv, ev in tvs:
         rv = s_chop.onespace(iv)
         self.eq(rv, ev)
Exemplo n.º 3
0
 def test_chop_onespace(self):
     tvs = [
         ('asdfasdf  asdfasdf ', 'asdfasdf asdfasdf'),
         ('asdfasdf ', 'asdfasdf'),
         ('asdf', 'asdf'),
         ('  asdfasdf  ', 'asdfasdf'),
         (' asdf  asdf    asdf \t \t asdf asdf   ', 'asdf asdf asdf asdf asdf'),
         (' ', ''),
         ('foo   bar baz', 'foo bar baz'),
     ]
     for iv, ev in tvs:
         rv = s_chop.onespace(iv)
         self.eq(rv, ev)
Exemplo n.º 4
0
    def indxByPref(self, valu):

        # doesnt have to be normable...
        if self.opts.get('lower'):
            valu = valu.lower()

        # Only strip the left side of the string for prefix match
        if self.opts.get('strip'):
            valu = valu.lstrip()

        if self.opts.get('onespace'):
            valu = s_chop.onespace(valu)

        return StrBase.indxByPref(self, valu)