Custom urljoin replacement supporting : before / in url.
(base, url)
| 966 | |
| 967 | |
| 968 | def _urljoin(base, url): |
| 969 | """Custom urljoin replacement supporting : before / in url.""" |
| 970 | # In general, it's unsafe to simply join base and url. However, for |
| 971 | # the case of discovery documents, we know: |
| 972 | # * base will never contain params, query, or fragment |
| 973 | # * url will never contain a scheme or net_loc. |
| 974 | # In general, this means we can safely join on /; we just need to |
| 975 | # ensure we end up with precisely one / joining base and url. The |
| 976 | # exception here is the case of media uploads, where url will be an |
| 977 | # absolute url. |
| 978 | if url.startswith("http://") or url.startswith("https://"): |
| 979 | return urllib.parse.urljoin(base, url) |
| 980 | new_base = base if base.endswith("/") else base + "/" |
| 981 | new_url = url[1:] if url.startswith("/") else url |
| 982 | return new_base + new_url |
| 983 | |
| 984 | |
| 985 | # TODO(dhermes): Convert this class to ResourceMethod and make it callable |
no outgoing calls
searching dependent graphs…