MCPcopy Create free account
hub / github.com/ActiveState/code / norm

Function norm

recipes/Python/66422_URLNorm/recipe-66422.py:62–90  ·  view source on GitHub ↗
(urltuple=('','','','','',''))

Source from the content-addressed store, hash-verified

60
61
62def norm(urltuple=('','','','','','')):
63 (scheme, host, path, parameters, query, fragment) = urltuple
64 scheme = lower(scheme)
65 host = lower(host)
66
67 if _relative_scheme.get(scheme, 0):
68 last_path = path
69 while 1:
70 path = re.sub(_re_pat, '/', path, 1)
71 if last_path == path:
72 break
73 last_path = path
74
75 path = unquote(path)
76
77 colon_idx = rfind(host, ':')
78 if colon_idx > 0:
79 if host[colon_idx:] == _default_port.get(scheme, '#'):
80 host = host[:colon_idx]
81 if host[colon_idx - 1] == '.':
82 host = host[:colon_idx - 1] + host[colon_idx:]
83 else:
84 try:
85 if host[-1] == '.':
86 host = host[:-1]
87 except IndexError:
88 pass
89
90 return (scheme, host, path, parameters, query, fragment)
91
92
93

Callers 1

normsFunction · 0.70

Calls 4

lowerFunction · 0.85
unquoteFunction · 0.85
getMethod · 0.45
subMethod · 0.45

Tested by

no test coverage detected