| 60 | |
| 61 | |
| 62 | def 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 | |