Mercurial > hg > urlmatch
diff urlmatch.py @ 10:b02420253bfd default tip
add recomposition and a test for it
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Tue, 28 Jun 2011 18:39:18 -0700 |
parents | ef0553c4bbcd |
children |
line wrap: on
line diff
--- a/urlmatch.py Mon Jun 27 11:22:40 2011 -0700 +++ b/urlmatch.py Tue Jun 28 18:39:18 2011 -0700 @@ -39,6 +39,31 @@ return urldict + @classmethod + def recompose(cls, url): + """reconstruct a deconstructed url""" + + # must have a domain + assert 'domain' in url + assert url['domain'] + + # reconstruct domain + if len(url['domain']) == 1: + return url['domain'][0] # what else to do? + retval = '%s.%s' % tuple(url['domain'][:2]) + if len(url['domain']) > 2: + retval = '.'.join(reversed(url['domain'][2:])) + '.' + retval + + # add the scheme + if 'scheme' in url: + retval = url['scheme'] + '://' + retval + + # add the path + if 'path' in url: + retval += '/' + '/'.join(url['path']) + + return retval + def add(self, url): if url not in self.urls: self.urls[url] = self.decompose(url)