Commits

Branko Vukelic committed 108dcb9

Added delete functions for query parameter removal

Comments (0)

Files changed (2)

tests/test_url_helper.py

         u = UrlHelper('/foo/bar')
         u.query = dict(foo=1)
         self.assertEqual(u.hash, '06f0a42bdd474f053fb1343165a31d42')
+
+    def test_delete_key(self):
+        u = UrlHelper('/foo/bar?foo=1&bar=2')
+        u.del_param('foo')
+        self.assertEqual(u.get_full_path(), '/foo/bar?bar=2')
+
+    def test_delete_multiple_keys(self):
+        u = UrlHelper('/foo/bar?foo=1&bar=2')
+        u.del_params('foo', 'bar')
+        self.assertEqual(u.get_full_path(), '/foo/bar')
+

url_tools/helper.py

     def get_full_quoted_path(self, **kwargs):
         return urllib.quote_plus(self.get_full_path(**kwargs), safe='/')
 
+    def del_param(self, param):
+        try:
+            del self.query_dict[param]
+        except KeyError:
+            pass # Fail silently
+
+    def del_params(self, *params):
+        for param in params:
+            self.del_param(param)
+
     @property
     def hash(self):
         if self._hash: