diff --git a/libmproxy/contentviews.py b/libmproxy/contentviews.py index 9af080335..8d5aadfce 100644 --- a/libmproxy/contentviews.py +++ b/libmproxy/contentviews.py @@ -515,6 +515,14 @@ def get_by_shortcut(c): return i +def add(obj): + for i in views: + if i.name == obj.name: + raise ContentViewException("Duplicate view: " + obj.name) + + views.append(obj) + + def get(name): for i in views: if i.name == name: diff --git a/test/test_contentview.py b/test/test_contentview.py index 976085209..68272fca3 100644 --- a/test/test_contentview.py +++ b/test/test_contentview.py @@ -210,6 +210,19 @@ Larry assert "decoded gzip" in r[0] assert "Raw" in r[0] + def test_add_cv(self): + class TestContentView(cv.View): + name = "test" + + tcv = TestContentView() + cv.add(tcv) + + tutils.raises( + ContentViewException, + cv.add, + tcv + ) + if pyamf: def test_view_amf_request():