Repository: mitmproxy/mitmproxy

Issue:
Crash when clearing event log
##### Steps to reproduce the problem:

1. Press `E` 
2. Press `z`
```
...
  File "/home/ujjwal/Github/mitmproxy/venv/lib/python3.5/site-packages/urwid/raw_display.py", line 393, in <lambda>
    event_loop, callback, self.get_available_raw_input())
  File "/home/ujjwal/Github/mitmproxy/venv/lib/python3.5/site-packages/urwid/raw_display.py", line 493, in parse_input
    callback(processed, processed_codes)
  File "/home/ujjwal/Github/mitmproxy/venv/lib/python3.5/site-packages/urwid/main_loop.py", line 403, in _update
    self.process_input(keys)
  File "/home/ujjwal/Github/mitmproxy/venv/lib/python3.5/site-packages/urwid/main_loop.py", line 503, in process_input
    k = self._topmost_widget.keypress(self.screen_size, k)
  File "/home/ujjwal/Github/mitmproxy/mitmproxy/tools/console/window.py", line 226, in keypress
    k = fs.keypress(size, k)
  File "/home/ujjwal/Github/mitmproxy/mitmproxy/tools/console/eventlog.py", line 26, in keypress
    self.master.clear_events()
AttributeError: 'ConsoleMaster' object has no attribute 'clear_events'
```


##### Any other comments? What have you tried so far?
Caused by:
https://github.com/mitmproxy/mitmproxy/commit/0f4d94b31c02171c1cc39bf90426b61e5c2a05e1
##### System information
Mitmproxy version: 3.0.0 (2.0.0dev0564-0x0d7b718) 
Python version: 3.5.2
Platform: Linux-4.9.0-040900-generic-x86_64-with-elementary-0.4.1-loki
SSL version: OpenSSL 1.0.2g  1 Mar 2016
Linux distro: "elementary" 0.4.1 loki


<!--
    Cut and paste the output of "mitmproxy --version".

    If you're using an older version if mitmproxy, please specify the version
    and OS.
-->

Crash when using mouse in mitmproxy
##### Steps to reproduce the problem:

1.Open mitmproxy
2.Click on any flow for flow details
3.
```
...
  File "/home/ujjwal/Github/mitmproxy/mitmproxy/tools/console/window.py", line 206, in mouse_event
    k = super().mouse_event(*args, **kwargs)
  File "/home/ujjwal/Github/mitmproxy/venv/lib/python3.5/site-packages/urwid/container.py", line 1169, in mouse_event
    event, button, col, row-htrim, focus )
  File "/home/ujjwal/Github/mitmproxy/venv/lib/python3.5/site-packages/urwid/listbox.py", line 1566, in mouse_event
    focus)
  File "/home/ujjwal/Github/mitmproxy/mitmproxy/tools/console/flowlist.py", line 72, in mouse_event
    self.master.view_flow(self.flow)
AttributeError: 'ConsoleMaster' object has no attribute 'view_flow'
```



##### System information
Mitmproxy version: 3.0.0 (2.0.0dev0424-0x81d68aa) 
Python version: 3.5.2
Platform: Linux-4.9.0-040900-generic-x86_64-with-elementary-0.4-loki
SSL version: OpenSSL 1.0.2g  1 Mar 2016
Linux distro: "elementary" 0.4 loki


<!--
    Cut and paste the output of "mitmproxy --version".

    If you're using an older version if mitmproxy, please specify the version
    and OS.
-->



Discussion:
https://github.com/mitmproxy/mitmproxy/commit/0f4d94b31c02171c1cc39bf90426b61e5c2a05e1#diff-7905b817459f7672d33cc35b365d34eaR26
Change `self.master.clear_events()` to `self.clear_events()`
Yes, this is a reproducible crash!

Resolving patch:
diff --git a/mitmproxy/tools/console/eventlog.py b/mitmproxy/tools/console/eventlog.py
--- a/mitmproxy/tools/console/eventlog.py
+++ b/mitmproxy/tools/console/eventlog.py
@@ -23,7 +23,7 @@ def set_focus(self, index):
 
     def keypress(self, size, key):
         if key == "z":
-            self.master.clear_events()
+            self.clear_events()
             key = None
         elif key == "m_end":
             self.set_focus(len(self.walker) - 1)
diff --git a/mitmproxy/tools/console/flowlist.py b/mitmproxy/tools/console/flowlist.py
--- a/mitmproxy/tools/console/flowlist.py
+++ b/mitmproxy/tools/console/flowlist.py
@@ -69,7 +69,7 @@ def selectable(self):
     def mouse_event(self, size, event, button, col, row, focus):
         if event == "mouse press" and button == 1:
             if self.flow.request:
-                self.master.view_flow(self.flow)
+                self.master.commands.call("console.view.flow @focus")
                 return True
 
     def keypress(self, xxx_todo_changeme, key):


Test patch: