Extract the first PDF-like URL from arbitrary user text.
(text: Any)
| 1086 | |
| 1087 | |
| 1088 | def extract_pdf_url(text: Any) -> Optional[str]: |
| 1089 | """Extract the first PDF-like URL from arbitrary user text.""" |
| 1090 | for match in GENERIC_HTTP_URL_RE.finditer(str(text or "")): |
| 1091 | url = str(match.group("url") or "").strip().rstrip(".,);]\u3002\uff0c\uff1b") |
| 1092 | if not url: |
| 1093 | continue |
| 1094 | if "://" not in url: |
| 1095 | url = f"https://{url.lstrip('/')}" |
| 1096 | if looks_like_pdf_http_url(url): |
| 1097 | return url |
| 1098 | return None |
| 1099 | |
| 1100 | |
| 1101 | def strip_pdf_url(text: Any) -> str: |
no test coverage detected