MCPcopy Index your code
hub / github.com/googleapis/google-api-python-client / _urljoin

Function _urljoin

googleapiclient/discovery.py:968–982  ·  view source on GitHub ↗

Custom urljoin replacement supporting : before / in url.

(base, url)

Source from the content-addressed store, hash-verified

966
967
968def _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

Callers 2

test_urljoinMethod · 0.90
methodFunction · 0.85

Calls

no outgoing calls

Tested by 1

test_urljoinMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…