(url: str, fragments_allowed=True)
| 140 | |
| 141 | |
| 142 | def is_valid_url(url: str, fragments_allowed=True): |
| 143 | try: |
| 144 | parsed = urlparse.urlparse(url) |
| 145 | except ValueError: |
| 146 | return False |
| 147 | |
| 148 | # The userinfo component can disguise the actual host, |
| 149 | # as in "https://provider.test@attacker.test/". |
| 150 | if "@" in parsed.netloc: |
| 151 | return False |
| 152 | |
| 153 | return bool( |
| 154 | parsed.scheme and parsed.hostname and (fragments_allowed or not parsed.fragment) |
| 155 | ) |
no outgoing calls