Commits

Anonymous committed 9a1c72b

Allow use of UrlHelper instance as argument to UrlHelper constructor

  • Participants
  • Parent commits 1b30558

Comments (0)

Files changed (3)

runtests.py

File contents unchanged.

tests/test_url_helper.py

         u = UrlHelper('/foo/bar?foo=1&bar=2')
         u.del_params()
         self.assertEqual(u.get_full_path(), '/foo/bar')
+
+    def test_url_helper_instance_as_argument(self):
+        u1 = UrlHelper('/foo/bar?foo=1&bar=2')
+        u2 = UrlHelper(u1)
+        self.assertEqual(u2.get_full_path(), '/foo/bar?foo=1&bar=2')

url_tools/helper.py

     from django.http.request import QueryDict
 except ImportError: # django 1.4.2
     from django.http import QueryDict
+
 from django.utils.encoding import iri_to_uri
 
 
 class UrlHelper(object):
     def __init__(self, full_path):
+        # If full_path is an UrlHelper instance, extract the full path from it
+        if type(full_path) is UrlHelper:
+            full_path = full_path.get_full_path()
+
         # parse the path
         r = urlparse.urlparse(full_path)
         self.path = r.path