Commit 9953e43e authored by anonym's avatar anonym

Improve formatting and add manual wrapping.

parent 642203eb
......@@ -107,7 +107,9 @@ def handle_controlport_session(controller, readh, writeh, allowed_commands, allo
if event in allowed_events:
def event_cb(event):
respond(event.raw_content(), raw = True)
controller.add_event_listener(event_cb, getattr(stem.control.EventType, event))
controller.add_event_listener(
event_cb, getattr(stem.control.EventType, event)
)
subscribed_event_listeners.append(event_cb)
respond("250 OK")
else:
......@@ -143,7 +145,9 @@ class FilteredControlPortProxyHandler(socketserver.StreamRequestHandler):
cookie = f.read(32)
# Connect to the real control port
controller = stem.control.Controller.from_socket_file(global_args.control_socket_path)
controller = stem.control.Controller.from_socket_file(
global_args.control_socket_path
)
try:
controller.authenticate(cookie)
except stem.SocketError:
......@@ -153,14 +157,19 @@ class FilteredControlPortProxyHandler(socketserver.StreamRequestHandler):
def handle(self):
try:
client_conn = next(conn for conn in psutil.net_connections() if conn.laddr == self.client_address)
client_conn = \
next(conn for conn in psutil.net_connections() \
if conn.laddr == self.client_address)
except StopIteration:
# Deal with the race between looking up the PID, and the
# client being killed before we find the PID.
return
client_exe_path = exe_path_of_pid(client_conn.pid)
try:
client_filter = next(filter for filter in self.filters if any(exe_path for exe_path in filter['match-exe-paths'] if client_exe_path == exe_path))
client_filter = \
next(filter for filter in self.filters \
if any(exe_path for exe_path in filter['match-exe-paths'] \
if client_exe_path == exe_path))
client_status = 'loaded matching filter'
except StopIteration:
client_filter = {}
......@@ -172,7 +181,8 @@ class FilteredControlPortProxyHandler(socketserver.StreamRequestHandler):
allowed_events = client_filter.get('events', [])
controller = self.connect_to_real_control_port()
try:
handle_controlport_session(controller, self.rfile, self.wfile, allowed_commands, allowed_events)
handle_controlport_session(controller, self.rfile, self.wfile,
allowed_commands, allowed_events)
finally:
controller.close()
......
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