Commit 59d79cfa authored by anonym's avatar anonym

tor-controlport-filter: rethink rewrite_line() when no replacement matched.

Returning None isn't helpful. The only place (except in other rewrite_*
methods) we use it is in a situation where something *must*
match (otherwise there's a bug in our code!), so raising an exception
seems appropriate.
parent 29dee257
......@@ -139,6 +139,10 @@ DEFAULT_CONTROL_SOCKET_PATH = '/var/run/tor/control'
MAX_LINESIZE = 1024
class NoRewriteMatch(RuntimeError):
pass
def log(msg):
print(msg, file=sys.stderr)
sys.stderr.flush()
......@@ -308,13 +312,12 @@ def handle_controlport_session(controller, readh, writeh, client_desc, client_pi
match = re.match(r['pattern'] + "$", line)
if match:
return r['replacement'].format(*match.groups())
return None
raise NoRewriteMatch()
def rewrite_matched_line(replacers, line):
new_line = rewrite_line(replacers, line)
if new_line:
return new_line
else:
try:
return rewrite_line(replacers, line)
except NoRewriteMatch:
return line
def rewrite_matched_lines(replacers, lines):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment