prepend_scheme_if_needed() — requests Function Reference
Architecture documentation for the prepend_scheme_if_needed() function in utils.py from the requests codebase.
Entity Profile
Dependency Diagram
graph TD 9e0e1cd7_43e2_1740_9ce8_96012bdf42f7["prepend_scheme_if_needed()"] 2c39b9da_e317_5e6c_bbac_8362bac2110c["utils.py"] 9e0e1cd7_43e2_1740_9ce8_96012bdf42f7 -->|defined in| 2c39b9da_e317_5e6c_bbac_8362bac2110c b63a634d_66d8_29cd_773b_da0e87ccd411["get_connection_with_tls_context()"] b63a634d_66d8_29cd_773b_da0e87ccd411 -->|calls| 9e0e1cd7_43e2_1740_9ce8_96012bdf42f7 a177b992_27e6_4822_1c3a_48567aa04e20["get_connection()"] a177b992_27e6_4822_1c3a_48567aa04e20 -->|calls| 9e0e1cd7_43e2_1740_9ce8_96012bdf42f7 style 9e0e1cd7_43e2_1740_9ce8_96012bdf42f7 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
src/requests/utils.py lines 977–1003
def prepend_scheme_if_needed(url, new_scheme):
"""Given a URL that may or may not have a scheme, prepend the given scheme.
Does not replace a present scheme with the one provided as an argument.
:rtype: str
"""
parsed = parse_url(url)
scheme, auth, host, port, path, query, fragment = parsed
# A defect in urlparse determines that there isn't a netloc present in some
# urls. We previously assumed parsing was overly cautious, and swapped the
# netloc and path. Due to a lack of tests on the original defect, this is
# maintained with parse_url for backwards compatibility.
netloc = parsed.netloc
if not netloc:
netloc, path = path, netloc
if auth:
# parse_url doesn't provide the netloc with auth
# so we'll add it ourselves.
netloc = "@".join([auth, netloc])
if scheme is None:
scheme = new_scheme
if path is None:
path = ""
return urlunparse((scheme, netloc, path, "", query, fragment))
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does prepend_scheme_if_needed() do?
prepend_scheme_if_needed() is a function in the requests codebase, defined in src/requests/utils.py.
Where is prepend_scheme_if_needed() defined?
prepend_scheme_if_needed() is defined in src/requests/utils.py at line 977.
What calls prepend_scheme_if_needed()?
prepend_scheme_if_needed() is called by 2 function(s): get_connection, get_connection_with_tls_context.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free