comparison 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
comparison
equal deleted inserted replaced
9:8d47894191a0 10:b02420253bfd
36 urldict['scheme'] = scheme 36 urldict['scheme'] = scheme
37 37
38 # could do others 38 # could do others
39 39
40 return urldict 40 return urldict
41
42 @classmethod
43 def recompose(cls, url):
44 """reconstruct a deconstructed url"""
45
46 # must have a domain
47 assert 'domain' in url
48 assert url['domain']
49
50 # reconstruct domain
51 if len(url['domain']) == 1:
52 return url['domain'][0] # what else to do?
53 retval = '%s.%s' % tuple(url['domain'][:2])
54 if len(url['domain']) > 2:
55 retval = '.'.join(reversed(url['domain'][2:])) + '.' + retval
56
57 # add the scheme
58 if 'scheme' in url:
59 retval = url['scheme'] + '://' + retval
60
61 # add the path
62 if 'path' in url:
63 retval += '/' + '/'.join(url['path'])
64
65 return retval
41 66
42 def add(self, url): 67 def add(self, url):
43 if url not in self.urls: 68 if url not in self.urls:
44 self.urls[url] = self.decompose(url) 69 self.urls[url] = self.decompose(url)
45 70