1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 """ A couple of functions to interpret and manage URIs."""
25 import re
26 import os
27 URI = re.compile(r'(?P<protocol> [\d\w]+)://(?P<host> [^:/]+):?(?P<port> \d*)(?P<path> /[^\#\?]*)? (?P<query> \?[^\#]+)? (?P<sharp> \#.+)?',re.I|re.X)
28 QUERYSEP = re.compile(r'(?P<path> [^#]+)\?(?P<querysep> [^\?]+)$',re.I|re.X)
29
31 s = QUERYSEP.search(uri)
32 if s == None or not s.groupdict().has_key('querysep'):
33 return ""
34 else:
35 return s.groupdict()['querysep']
36
37 first_slash = re.compile(r"^/+")
39 s=QUERYSEP.search(uri)
40 if s == None:
41 return uri
42 else:
43 return s.groups()
44
46 path = dictmatch['path']
47 if not (path is None) and path != '' and path != '/':
48 path = os.path.normpath(first_slash.sub("/",path))
49 else:
50 path = '/'
51 return "%s%s%s"%(path, dictmatch['query'] or '', dictmatch['sharp'] or '')
52
54 url = d['protocol'] + "://" + host
55 port = d['port']
56 if port: url = url + ":" + port
57 url = url + normlocation(d)
58 return url
59
61 m = URI.match(urlarg)
62 if m is None: return urlarg
63 d = m.groupdict()
64 return normurldict(d, d['host'])
65