(pattern, repl, flags=0)
return call
Construct a method that can be used as a replace method for `sub`, `subn`, etc.
Construct a method that can be used as a replace method for `sub`, `subn`, etc.
Construct a method that can be used as a replace method for sub subn etc .
def compile_replace(pattern, repl, flags=0):
    """Construct a method that can be used as a replace method for `sub`, `subn`, etc."""

    call = None
    if pattern is not None and isinstance(pattern, _RE_TYPE):
        if isinstance(repl, (_util.string_type, _util.binary_type)):
            if not (pattern.flags & DEBUG):
                call = _cached_replace_compile(pattern, repl, flags, type(repl))
            else:  # pragma: no cover
                call = _bre_parse._ReplaceParser().parse(pattern, repl, bool(flags & FORMAT))
        elif isinstance(repl, ReplaceTemplate):
            if flags:
                raise ValueError("Cannot process flags argument with a ReplaceTemplate!")
            if repl.pattern_hash != hash(pattern):
                raise ValueError("Pattern hash doesn't match hash in compiled replace!")
            call = repl
        else:
            raise TypeError("Not a valid type!")
    else:
        raise TypeError("Pattern must be a compiled regular expression!")
    return call
def compile_replace ( pattern , repl , flags = 0 ) : call = None if pattern is not None and isinstance ( pattern , _RE_TYPE ) : if isinstance ( repl , ( _util . string_type , _util . binary_type ) ) : if not ( pattern . flags & DEBUG ) : call = _cached_replace_compile ( pattern , repl , flags , type ( repl ) ) else : # pragma: no cover call = _bre_parse . _ReplaceParser ( ) . parse ( pattern , repl , bool ( flags & FORMAT ) ) elif isinstance ( repl , ReplaceTemplate ) : if flags : raise ValueError ( "Cannot process flags argument with a ReplaceTemplate!" ) if repl . pattern_hash != hash ( pattern ) : raise ValueError ( "Pattern hash doesn't match hash in compiled replace!" ) call = repl else : raise TypeError ( "Not a valid type!" ) else : raise TypeError ( "Pattern must be a compiled regular expression!" ) return call