aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUjjwal Verma <ujjwalverma1111@gmail.com>2017-02-10 20:53:28 +0530
committerUjjwal Verma <ujjwalverma1111@gmail.com>2017-02-10 22:21:12 +0530
commit809207195d9b4fe7b1f33f7bea8efa05a8895d56 (patch)
tree8e130943a795f0e9acfa644c1621394c7bfbe585
parentd4264cb719016e02527ce0a2cad533787798266f (diff)
downloadmitmproxy-809207195d9b4fe7b1f33f7bea8efa05a8895d56.tar.gz
mitmproxy-809207195d9b4fe7b1f33f7bea8efa05a8895d56.tar.bz2
mitmproxy-809207195d9b4fe7b1f33f7bea8efa05a8895d56.zip
closes #1828 script reloads on py file changes
-rw-r--r--mitmproxy/addons/script.py7
-rw-r--r--test/mitmproxy/addons/test_script.py7
2 files changed, 12 insertions, 2 deletions
diff --git a/mitmproxy/addons/script.py b/mitmproxy/addons/script.py
index b3a93571..a7d3a312 100644
--- a/mitmproxy/addons/script.py
+++ b/mitmproxy/addons/script.py
@@ -110,11 +110,16 @@ class ReloadHandler(watchdog.events.FileSystemEventHandler):
self.callback = callback
def filter(self, event):
+ """
+ Returns True only when .py file is changed
+ """
if event.is_directory:
return False
if os.path.basename(event.src_path).startswith("."):
return False
- return True
+ if event.src_path.endswith(".py"):
+ return True
+ return False
def on_modified(self, event):
if self.filter(event):
diff --git a/test/mitmproxy/addons/test_script.py b/test/mitmproxy/addons/test_script.py
index 96d7bd9e..5f196ebf 100644
--- a/test/mitmproxy/addons/test_script.py
+++ b/test/mitmproxy/addons/test_script.py
@@ -44,14 +44,19 @@ def test_reloadhandler():
rh = script.ReloadHandler(Called())
assert not rh.filter(watchdog.events.DirCreatedEvent("path"))
assert not rh.filter(watchdog.events.FileModifiedEvent("/foo/.bar"))
- assert rh.filter(watchdog.events.FileModifiedEvent("/foo/bar"))
+ assert not rh.filter(watchdog.events.FileModifiedEvent("/foo/bar"))
+ assert rh.filter(watchdog.events.FileModifiedEvent("/foo/bar.py"))
assert not rh.callback.called
rh.on_modified(watchdog.events.FileModifiedEvent("/foo/bar"))
+ assert not rh.callback.called
+ rh.on_modified(watchdog.events.FileModifiedEvent("/foo/bar.py"))
assert rh.callback.called
rh.callback.called = False
rh.on_created(watchdog.events.FileCreatedEvent("foo"))
+ assert not rh.callback.called
+ rh.on_created(watchdog.events.FileCreatedEvent("foo.py"))
assert rh.callback.called