Commits

Anonymous committed 9a1c72b

Allow use of UrlHelper instance as argument to UrlHelper constructor

Comments (0)

Files changed (3)

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
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.