(url, unquote=None)
| 515 | |
| 516 | |
| 517 | def fixurl(url, unquote=None): |
| 518 | old = url |
| 519 | url = urllib.unquote(url) |
| 520 | |
| 521 | if unquote is None: |
| 522 | unquote = url == old |
| 523 | |
| 524 | url = decode(url) |
| 525 | |
| 526 | #: 'unicode-escape' that work with unicode strings too |
| 527 | url = re.sub(r'\\u(\d{4})', lambda x: unichr(int(x.group(1))), url, flags=re.I) |
| 528 | |
| 529 | url = html_unescape(url) |
| 530 | |
| 531 | #: '//' becomes '/' |
| 532 | url = re.sub(r'(?<!:)/{2,}', '/', url).strip().lstrip('.') |
| 533 | |
| 534 | if not unquote: |
| 535 | url = urllib.quote(url) |
| 536 | |
| 537 | return url |
| 538 | |
| 539 | |
| 540 | def truncate(name, length): |
no test coverage detected