@@ -256,33 +256,33 @@ class _CleanResult(NamedTuple):
256
256
subdirectory : str
257
257
hashes : Dict [str , str ]
258
258
259
- @ classmethod
260
- def from_link ( cls , link : Link ) -> " _CleanResult" :
261
- parsed = link ._parsed_url
262
- netloc = parsed .netloc .rsplit ("@" , 1 )[- 1 ]
263
- # According to RFC 8089, an empty host in file: means localhost.
264
- if parsed .scheme == "file" and not netloc :
265
- netloc = "localhost"
266
- fragment = urllib .parse .parse_qs (parsed .fragment )
267
- if "egg" in fragment :
268
- logger .debug ("Ignoring egg= fragment in %s" , link )
269
- try :
270
- # If there are multiple subdirectory values, use the first one.
271
- # This matches the behavior of Link.subdirectory_fragment.
272
- subdirectory = fragment ["subdirectory" ][0 ]
273
- except (IndexError , KeyError ):
274
- subdirectory = ""
275
- # If there are multiple hash values under the same algorithm, use the
276
- # first one. This matches the behavior of Link.hash_value.
277
- hashes = {k : fragment [k ][0 ] for k in _SUPPORTED_HASHES if k in fragment }
278
- return cls (
279
- parsed = parsed ._replace (netloc = netloc , query = "" , fragment = "" ),
280
- query = urllib .parse .parse_qs (parsed .query ),
281
- subdirectory = subdirectory ,
282
- hashes = hashes ,
283
- )
259
+
260
+ def _clean_link ( link : Link ) -> _CleanResult :
261
+ parsed = link ._parsed_url
262
+ netloc = parsed .netloc .rsplit ("@" , 1 )[- 1 ]
263
+ # According to RFC 8089, an empty host in file: means localhost.
264
+ if parsed .scheme == "file" and not netloc :
265
+ netloc = "localhost"
266
+ fragment = urllib .parse .parse_qs (parsed .fragment )
267
+ if "egg" in fragment :
268
+ logger .debug ("Ignoring egg= fragment in %s" , link )
269
+ try :
270
+ # If there are multiple subdirectory values, use the first one.
271
+ # This matches the behavior of Link.subdirectory_fragment.
272
+ subdirectory = fragment ["subdirectory" ][0 ]
273
+ except (IndexError , KeyError ):
274
+ subdirectory = ""
275
+ # If there are multiple hash values under the same algorithm, use the
276
+ # first one. This matches the behavior of Link.hash_value.
277
+ hashes = {k : fragment [k ][0 ] for k in _SUPPORTED_HASHES if k in fragment }
278
+ return _CleanResult (
279
+ parsed = parsed ._replace (netloc = netloc , query = "" , fragment = "" ),
280
+ query = urllib .parse .parse_qs (parsed .query ),
281
+ subdirectory = subdirectory ,
282
+ hashes = hashes ,
283
+ )
284
284
285
285
286
286
@functools .lru_cache (maxsize = None )
287
287
def links_equivalent (link1 : Link , link2 : Link ) -> bool :
288
- return _CleanResult . from_link (link1 ) == _CleanResult . from_link (link2 )
288
+ return _clean_link (link1 ) == _clean_link (link2 )
0 commit comments