def expand(self, m):
        """Using the template, expand the string."""

        if m is None:
            raise ValueError("Match is None!")

        sep = m.string[:0]
        if isinstance(sep, bytes) != self._bytes:
            raise TypeError('Match string type does not match expander string type!')
        text = []
        # Expand string
        for x in range(0, len(self.literals)):
            index = x
            l = self.literals[x]
            if l is None:
                g_index = self._get_group_index(index)
                span_case, single_case, capture = self._get_group_attributes(index)
                if not self.use_format:
                    # Non format replace
                    try:
                        l = m.group(g_index)
                    except IndexError:  # pragma: no cover
                        raise IndexError("'%d' is out of range!" % capture)
                else:
                    # String format replace
                    try:
                        obj = m.captures(g_index)
                    except IndexError:  # pragma: no cover
                        raise IndexError("'%d' is out of range!" % g_index)
                    l = _util.format_string(m, obj, capture, self._bytes)
                if span_case is not None:
                    if span_case == _LOWER:
                        l = l.lower()
                    else:
                        l = l.upper()
                if single_case is not None:
                    if single_case == _LOWER:
                        l = l[0:1].lower() + l[1:]
                    else:
                        l = l[0:1].upper() + l[1:]
            text.append(l)

        return sep.join(text)
def expand ( self , m ) : if m is None : raise ValueError ( "Match is None!" ) sep = m . string [ : 0 ] if isinstance ( sep , bytes ) != self . _bytes : raise TypeError ( 'Match string type does not match expander string type!' ) text = [ ] for x in range ( 0 , len ( self . literals ) ) : index = x l = self . literals [ x ] if l is None : g_index = self . _get_group_index ( index ) span_case , single_case , capture = self . _get_group_attributes ( index ) if not self . use_format : try : l = m . group ( g_index ) except IndexError : raise IndexError ( "'%d' is out of range!" % capture ) else : try : obj = m . captures ( g_index ) except IndexError : raise IndexError ( "'%d' is out of range!" % g_index ) l = _util . format_string ( m , obj , capture , self . _bytes ) if span_case is not None : if span_case == _LOWER : l = l . lower ( ) else : l = l . upper ( ) if single_case is not None : if single_case == _LOWER : l = l [ 0 : 1 ] . lower ( ) + l [ 1 : ] else : l = l [ 0 : 1 ] . upper ( ) + l [ 1 : ] text . append ( l ) return sep . join ( text )
Using the template, expand the string.