# HG changeset patch # User Jeff Hammel # Date 1309184206 25200 # Node ID 0cd69fa6751c66a39db84cbb2432709b6df6de4d # Parent 6b99523536ee7e1e004ed8a43361ffef79926563 add test for decomposition; stub diff, will have to move to 2-tuples to do this properly diff -r 6b99523536ee -r 0cd69fa6751c tests/doctest.txt --- a/tests/doctest.txt Fri Jun 17 10:52:29 2011 -0700 +++ b/tests/doctest.txt Mon Jun 27 07:16:46 2011 -0700 @@ -20,6 +20,12 @@ >>> sorted(matcher.match('example')) # -> example.* ['http://www.example.com/foo/bar/fleem', 'http://www.example.com/foo/blah', 'https://www.example.com/foo/', 'https://www.example.net/foo/'] +Test decomposition:: + + >>> matcher = UrlMatcher() + >>> sorted(matcher.decompose('http://www.example.com/foo').items()) + [('domain', ['example', 'com', 'www']), ('path', ['foo']), ('scheme', 'http')] + Test url diffs:: >>> matcher = UrlMatcher() diff -r 6b99523536ee -r 0cd69fa6751c urlmatch.py --- a/urlmatch.py Fri Jun 17 10:52:29 2011 -0700 +++ b/urlmatch.py Mon Jun 27 07:16:46 2011 -0700 @@ -52,7 +52,18 @@ url2 = self.decompose(url) # TODO: finish - raise NotImplementedError + for i in self.order: + if i in url1 and i in url2: + if url1[i] == url2[i]: + continue + if isinstance(url1[i], basestring): + raise NotImplementedError + else: + retval = url1.get(i, url2[i]) + if isinstance(retval, basestring): + return {i: retval} + return {i: retval[0]} + def match(self, url): if '://' not in url: