Let us walk on the 3-isogeny graph
Loading...
Searching...
No Matches
pip._internal.models.link Namespace Reference

Data Structures

class  _CleanResult
 
class  Link
 
class  LinkHash
 
class  MetadataFile
 

Functions

Optional[Dict[str, str]] supported_hashes (Optional[Dict[str, str]] hashes)
 
str _clean_url_path_part (str part)
 
str _clean_file_url_path (str part)
 
str _clean_url_path (str path, bool is_local_path)
 
str _ensure_quoted_url (str url)
 
_CleanResult _clean_link (Link link)
 
bool links_equivalent (Link link1, Link link2)
 

Variables

 logger = logging.getLogger(__name__)
 
tuple _SUPPORTED_HASHES = ("sha512", "sha384", "sha256", "sha224", "sha1", "md5")
 
 _reserved_chars_re = re.compile("(@|%2F)", re.IGNORECASE)
 

Function Documentation

◆ _clean_file_url_path()

str _clean_file_url_path ( str  part)
protected
Clean the first part of a URL path that corresponds to a local
filesystem path (i.e. the first part after splitting on "@" characters).

Definition at line 128 of file link.py.

128def _clean_file_url_path(part: str) -> str:
129 """
130 Clean the first part of a URL path that corresponds to a local
131 filesystem path (i.e. the first part after splitting on "@" characters).
132 """
133 # We unquote prior to quoting to make sure nothing is double quoted.
134 # Also, on Windows the path part might contain a drive letter which
135 # should not be quoted. On Linux where drive letters do not
136 # exist, the colon should be quoted. We rely on urllib.request
137 # to do the right thing here.
139
140
141# percent-encoded: /
for i

References i.

◆ _clean_link()

_CleanResult _clean_link ( Link  link)
protected

Definition at line 553 of file link.py.

553def _clean_link(link: Link) -> _CleanResult:
554 parsed = link._parsed_url
555 netloc = parsed.netloc.rsplit("@", 1)[-1]
556 # According to RFC 8089, an empty host in file: means localhost.
557 if parsed.scheme == "file" and not netloc:
558 netloc = "localhost"
560 if "egg" in fragment:
561 logger.debug("Ignoring egg= fragment in %s", link)
562 try:
563 # If there are multiple subdirectory values, use the first one.
564 # This matches the behavior of Link.subdirectory_fragment.
565 subdirectory = fragment["subdirectory"][0]
566 except (IndexError, KeyError):
567 subdirectory = ""
568 # If there are multiple hash values under the same algorithm, use the
569 # first one. This matches the behavior of Link.hash_value.
570 hashes = {k: fragment[k][0] for k in _SUPPORTED_HASHES if k in fragment}
571 return _CleanResult(
572 parsed=parsed._replace(netloc=netloc, query="", fragment=""),
574 subdirectory=subdirectory,
575 hashes=hashes,
576 )
577
578
579@functools.lru_cache(maxsize=None)

References i.

Referenced by pip._internal.models.link.links_equivalent().

Here is the caller graph for this function:

◆ _clean_url_path()

str _clean_url_path ( str  path,
bool  is_local_path 
)
protected
Clean the path portion of a URL.

Definition at line 145 of file link.py.

145def _clean_url_path(path: str, is_local_path: bool) -> str:
146 """
147 Clean the path portion of a URL.
148 """
149 if is_local_path:
150 clean_func = _clean_file_url_path
151 else:
152 clean_func = _clean_url_path_part
153
154 # Split on the reserved characters prior to cleaning so that
155 # revision strings in VCS URLs are properly preserved.
156 parts = _reserved_chars_re.split(path)
157
158 cleaned_parts = []
159 for to_clean, reserved in pairwise(itertools.chain(parts, [""])):
161 # Normalize %xx escapes (e.g. %2f -> %2F)
163
164 return "".join(cleaned_parts)
165
166

References i.

Referenced by pip._internal.models.link._ensure_quoted_url().

Here is the caller graph for this function:

◆ _clean_url_path_part()

str _clean_url_path_part ( str  part)
protected
Clean a "part" of a URL path (i.e. after splitting on "@" characters).

Definition at line 120 of file link.py.

120def _clean_url_path_part(part: str) -> str:
121 """
122 Clean a "part" of a URL path (i.e. after splitting on "@" characters).
123 """
124 # We unquote prior to quoting to make sure nothing is double quoted.
126
127

References i.

◆ _ensure_quoted_url()

str _ensure_quoted_url ( str  url)
protected
Make sure a link is fully quoted.
For example, if ' ' occurs in the URL, it will be replaced with "%20",
and without double-quoting other characters.

Definition at line 167 of file link.py.

167def _ensure_quoted_url(url: str) -> str:
168 """
169 Make sure a link is fully quoted.
170 For example, if ' ' occurs in the URL, it will be replaced with "%20",
171 and without double-quoting other characters.
172 """
173 # Split the URL into parts according to the general structure
174 # `scheme://netloc/path;parameters?query#fragment`.
175 result = urllib.parse.urlparse(url)
176 # If the netloc is empty, then the URL refers to a local filesystem path.
177 is_local_path = not result.netloc
178 path = _clean_url_path(result.path, is_local_path=is_local_path)
180
181

References pip._internal.models.link._clean_url_path(), and i.

Referenced by Link.from_element(), and Link.from_json().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ links_equivalent()

bool links_equivalent ( Link  link1,
Link  link2 
)

Definition at line 580 of file link.py.

580def links_equivalent(link1: Link, link2: Link) -> bool:
581 return _clean_link(link1) == _clean_link(link2)

References pip._internal.models.link._clean_link().

Here is the call graph for this function:

◆ supported_hashes()

Optional[Dict[str, str]] supported_hashes ( Optional[Dict[str, str]]  hashes)

Definition at line 109 of file link.py.

109def supported_hashes(hashes: Optional[Dict[str, str]]) -> Optional[Dict[str, str]]:
110 # Remove any unsupported hash types from the mapping. If this leaves no
111 # supported hashes, return None
112 if hashes is None:
113 return None
114 hashes = {n: v for n, v in hashes.items() if n in _SUPPORTED_HASHES}
115 if not hashes:
116 return None
117 return hashes
118
119

References i.

Referenced by Link.from_element(), and Link.from_json().

Here is the caller graph for this function:

Variable Documentation

◆ _reserved_chars_re

_reserved_chars_re = re.compile("(@|%2F)", re.IGNORECASE)
protected

Definition at line 142 of file link.py.

◆ _SUPPORTED_HASHES

tuple _SUPPORTED_HASHES = ("sha512", "sha384", "sha256", "sha224", "sha1", "md5")
protected

Definition at line 41 of file link.py.

◆ logger

logger = logging.getLogger(__name__)

Definition at line 36 of file link.py.