<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import <EOL> import logging <EOL> import cgi <EOL> from collections import namedtuple <EOL> import itertools <EOL> import sys <EOL> import os <EOL> import re <EOL> import mimetypes <EOL> import posixpath <EOL> import warnings <EOL> from pip . _vendor . six . moves . urllib import parse as urllib_parse <EOL> from pip . _vendor . six . moves . urllib import request as urllib_request <EOL> from pip . compat import ipaddress <EOL> from pip . utils import ( <EOL> Inf , cached_property , normalize_name , splitext , normalize_path , <EOL> ARCHIVE_EXTENSIONS , SUPPORTED_EXTENSIONS ) <EOL> from pip . utils . deprecation import RemovedInPip8Warning <EOL> from pip . utils . logging import indent_log <EOL> from pip . exceptions import ( <EOL> DistributionNotFound , BestVersionAlreadyInstalled , InvalidWheelFilename , <EOL> UnsupportedWheel , <EOL> ) <EOL> from pip . download import HAS_TLS , url_to_path , path_to_url <EOL> from pip . models import PyPI <EOL> from pip . wheel import Wheel , wheel_ext <EOL> from pip . pep425tags import supported_tags , supported_tags_noarch , get_platform <EOL> from pip . _vendor import html5lib , requests , pkg_resources , six <EOL> from pip . _vendor . packaging . version import parse as parse_version <EOL> from pip . _vendor . requests . exceptions import SSLError <EOL> __all__ = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> SECURE_ORIGINS = [ <EOL> ( "<STR_LIT>" , "<STR_LIT:*>" , "<STR_LIT:*>" ) , <EOL> ( "<STR_LIT:*>" , "<STR_LIT:localhost>" , "<STR_LIT:*>" ) , <EOL> ( "<STR_LIT:*>" , "<STR_LIT>" , "<STR_LIT:*>" ) , <EOL> ( "<STR_LIT:*>" , "<STR_LIT>" , "<STR_LIT:*>" ) , <EOL> ( "<STR_LIT:file>" , "<STR_LIT:*>" , None ) , <EOL> ] <EOL> logger = logging . getLogger ( __name__ ) <EOL> class InstallationCandidate ( object ) : <EOL> def __init__ ( self , project , version , location ) : <EOL> self . project = project <EOL> self . version = parse_version ( version ) <EOL> self . location = location <EOL> self . _key = ( self . project , self . version , self . location ) <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" . format ( <EOL> self . project , self . version , self . location , <EOL> ) <EOL> def __hash__ ( self ) : <EOL> return hash ( self . _key ) <EOL> def __lt__ ( self , other ) : <EOL> return self . _compare ( other , lambda s , o : s < o ) <EOL> def __le__ ( self , other ) : <EOL> return self . _compare ( other , lambda s , o : s <= o ) <EOL> def __eq__ ( self , other ) : <EOL> return self . _compare ( other , lambda s , o : s == o ) <EOL> def __ge__ ( self , other ) : <EOL> return self . _compare ( other , lambda s , o : s >= o ) <EOL> def __gt__ ( self , other ) : <EOL> return self . _compare ( other , lambda s , o : s > o ) <EOL> def __ne__ ( self , other ) : <EOL> return self . _compare ( other , lambda s , o : s != o ) <EOL> def _compare ( self , other , method ) : <EOL> if not isinstance ( other , InstallationCandidate ) : <EOL> return NotImplemented <EOL> return method ( self . _key , other . _key ) <EOL> class PackageFinder ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , find_links , index_urls , <EOL> allow_external = ( ) , allow_unverified = ( ) , <EOL> allow_all_external = False , allow_all_prereleases = False , <EOL> trusted_hosts = None , process_dependency_links = False , <EOL> session = None , format_control = None ) : <EOL> """<STR_LIT>""" <EOL> if session is None : <EOL> raise TypeError ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) <EOL> self . find_links = [ ] <EOL> for link in find_links : <EOL> if link . startswith ( '<STR_LIT>' ) : <EOL> new_link = normalize_path ( link ) <EOL> if os . path . exists ( new_link ) : <EOL> link = new_link <EOL> self . find_links . append ( link ) <EOL> self . index_urls = index_urls <EOL> self . dependency_links = [ ] <EOL> self . logged_links = set ( ) <EOL> self . format_control = format_control or FormatControl ( set ( ) , set ( ) ) <EOL> self . allow_external = set ( normalize_name ( n ) for n in allow_external ) <EOL> self . allow_unverified = set ( <EOL> normalize_name ( n ) for n in allow_unverified <EOL> ) <EOL> self . allow_external |= self . allow_unverified <EOL> self . allow_all_external = allow_all_external <EOL> self . secure_origins = [ <EOL> ( "<STR_LIT:*>" , host , "<STR_LIT:*>" ) <EOL> for host in ( trusted_hosts if trusted_hosts else [ ] ) <EOL> ] <EOL> self . need_warn_external = False <EOL> self . need_warn_unverified = False <EOL> self . allow_all_prereleases = allow_all_prereleases <EOL> self . process_dependency_links = process_dependency_links <EOL> self . session = session <EOL> if not HAS_TLS : <EOL> for link in itertools . chain ( self . index_urls , self . find_links ) : <EOL> parsed = urllib_parse . urlparse ( link ) <EOL> if parsed . scheme == "<STR_LIT>" : <EOL> logger . warning ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) <EOL> break <EOL> def add_dependency_links ( self , links ) : <EOL> if self . process_dependency_links : <EOL> warnings . warn ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> RemovedInPip8Warning , <EOL> ) <EOL> self . dependency_links . extend ( links ) <EOL> @ staticmethod <EOL> def _sort_locations ( locations , expand_dir = False ) : <EOL> """<STR_LIT>""" <EOL> files = [ ] <EOL> urls = [ ] <EOL> def sort_path ( path ) : <EOL> url = path_to_url ( path ) <EOL> if mimetypes . guess_type ( url , strict = False ) [ <NUM_LIT:0> ] == '<STR_LIT>' : <EOL> urls . append ( url ) <EOL> else : <EOL> files . append ( url ) <EOL> for url in locations : <EOL> is_local_path = os . path . exists ( url ) <EOL> is_file_url = url . startswith ( '<STR_LIT>' ) <EOL> if is_local_path or is_file_url : <EOL> if is_local_path : <EOL> path = url <EOL> else : <EOL> path = url_to_path ( url ) <EOL> if os . path . isdir ( path ) : <EOL> if expand_dir : <EOL> path = os . path . realpath ( path ) <EOL> for item in os . listdir ( path ) : <EOL> sort_path ( os . path . join ( path , item ) ) <EOL> elif is_file_url : <EOL> urls . append ( url ) <EOL> elif os . path . isfile ( path ) : <EOL> sort_path ( path ) <EOL> else : <EOL> urls . append ( url ) <EOL> return files , urls <EOL> def _candidate_sort_key ( self , candidate ) : <EOL> """<STR_LIT>""" <EOL> support_num = len ( supported_tags ) <EOL> if candidate . location == INSTALLED_VERSION : <EOL> pri = <NUM_LIT:1> <EOL> elif candidate . location . is_wheel : <EOL> wheel = Wheel ( candidate . location . filename ) <EOL> if not wheel . supported ( ) : <EOL> raise UnsupportedWheel ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % wheel . filename <EOL> ) <EOL> pri = - ( wheel . support_index_min ( ) ) <EOL> else : <EOL> pri = - ( support_num ) <EOL> return ( candidate . version , pri ) <EOL> def _sort_versions ( self , applicable_versions ) : <EOL> """<STR_LIT>""" <EOL> return sorted ( <EOL> applicable_versions , <EOL> key = self . _candidate_sort_key , <EOL> reverse = True <EOL> ) <EOL> def _validate_secure_origin ( self , logger , location ) : <EOL> parsed = urllib_parse . urlparse ( str ( location ) ) <EOL> origin = ( parsed . scheme , parsed . hostname , parsed . port ) <EOL> for secure_origin in ( SECURE_ORIGINS + self . secure_origins ) : <EOL> if origin [ <NUM_LIT:0> ] != secure_origin [ <NUM_LIT:0> ] and secure_origin [ <NUM_LIT:0> ] != "<STR_LIT:*>" : <EOL> continue <EOL> try : <EOL> addr = ipaddress . ip_address ( <EOL> origin [ <NUM_LIT:1> ] <EOL> if ( <EOL> isinstance ( origin [ <NUM_LIT:1> ] , six . text_type ) or <EOL> origin [ <NUM_LIT:1> ] is None <EOL> ) <EOL> else origin [ <NUM_LIT:1> ] . decode ( "<STR_LIT:utf8>" ) <EOL> ) <EOL> network = ipaddress . ip_network ( <EOL> secure_origin [ <NUM_LIT:1> ] <EOL> if isinstance ( secure_origin [ <NUM_LIT:1> ] , six . text_type ) <EOL> else secure_origin [ <NUM_LIT:1> ] . decode ( "<STR_LIT:utf8>" ) <EOL> ) <EOL> except ValueError : <EOL> if origin [ <NUM_LIT:1> ] != secure_origin [ <NUM_LIT:1> ] and secure_origin [ <NUM_LIT:1> ] != "<STR_LIT:*>" : <EOL> continue <EOL> else : <EOL> if addr not in network : <EOL> continue <EOL> if ( origin [ <NUM_LIT:2> ] != secure_origin [ <NUM_LIT:2> ] and <EOL> secure_origin [ <NUM_LIT:2> ] != "<STR_LIT:*>" and <EOL> secure_origin [ <NUM_LIT:2> ] is not None ) : <EOL> continue <EOL> return True <EOL> logger . warning ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> parsed . hostname , <EOL> parsed . hostname , <EOL> ) <EOL> return False <EOL> def _get_index_urls_locations ( self , project_name ) : <EOL> """<STR_LIT>""" <EOL> def mkurl_pypi_url ( url ) : <EOL> loc = posixpath . join ( url , project_url_name ) <EOL> if not loc . endswith ( '<STR_LIT:/>' ) : <EOL> loc = loc + '<STR_LIT:/>' <EOL> return loc <EOL> project_url_name = urllib_parse . quote ( project_name . lower ( ) ) <EOL> if self . index_urls : <EOL> main_index_url = Link ( <EOL> mkurl_pypi_url ( self . index_urls [ <NUM_LIT:0> ] ) , <EOL> trusted = True , <EOL> ) <EOL> page = self . _get_page ( main_index_url ) <EOL> if page is None and PyPI . netloc not in str ( main_index_url ) : <EOL> warnings . warn ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % ( project_name , main_index_url ) , <EOL> RemovedInPip8Warning , <EOL> ) <EOL> project_url_name = self . _find_url_name ( <EOL> Link ( self . index_urls [ <NUM_LIT:0> ] , trusted = True ) , <EOL> project_url_name , <EOL> ) or project_url_name <EOL> if project_url_name is not None : <EOL> return [ mkurl_pypi_url ( url ) for url in self . index_urls ] <EOL> return [ ] <EOL> def _find_all_versions ( self , project_name ) : <EOL> """<STR_LIT>""" <EOL> index_locations = self . _get_index_urls_locations ( project_name ) <EOL> index_file_loc , index_url_loc = self . _sort_locations ( index_locations ) <EOL> fl_file_loc , fl_url_loc = self . _sort_locations ( <EOL> self . find_links , expand_dir = True ) <EOL> dep_file_loc , dep_url_loc = self . _sort_locations ( self . dependency_links ) <EOL> file_locations = ( <EOL> Link ( url ) for url in itertools . chain ( <EOL> index_file_loc , fl_file_loc , dep_file_loc ) <EOL> ) <EOL> url_locations = [ <EOL> link for link in itertools . chain ( <EOL> ( Link ( url , trusted = True ) for url in index_url_loc ) , <EOL> ( Link ( url , trusted = True ) for url in fl_url_loc ) , <EOL> ( Link ( url ) for url in dep_url_loc ) , <EOL> ) <EOL> if self . _validate_secure_origin ( logger , link ) <EOL> ] <EOL> logger . debug ( '<STR_LIT>' , <EOL> len ( url_locations ) , project_name ) <EOL> for location in url_locations : <EOL> logger . debug ( '<STR_LIT>' , location ) <EOL> canonical_name = pkg_resources . safe_name ( project_name ) . lower ( ) <EOL> formats = fmt_ctl_formats ( self . format_control , canonical_name ) <EOL> search = Search ( project_name . lower ( ) , canonical_name , formats ) <EOL> find_links_versions = self . _package_versions ( <EOL> ( Link ( url , '<STR_LIT>' , trusted = True ) for url in self . find_links ) , <EOL> search <EOL> ) <EOL> page_versions = [ ] <EOL> for page in self . _get_pages ( url_locations , project_name ) : <EOL> logger . debug ( '<STR_LIT>' , page . url ) <EOL> with indent_log ( ) : <EOL> page_versions . extend ( <EOL> self . _package_versions ( page . links , search ) <EOL> ) <EOL> dependency_versions = self . _package_versions ( <EOL> ( Link ( url ) for url in self . dependency_links ) , search <EOL> ) <EOL> if dependency_versions : <EOL> logger . debug ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:U+002CU+0020>' . join ( [ <EOL> version . location . url for version in dependency_versions <EOL> ] ) <EOL> ) <EOL> file_versions = self . _package_versions ( file_locations , search ) <EOL> if file_versions : <EOL> file_versions . sort ( reverse = True ) <EOL> logger . debug ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:U+002CU+0020>' . join ( [ <EOL> url_to_path ( candidate . location . url ) <EOL> for candidate in file_versions <EOL> ] ) <EOL> ) <EOL> return ( <EOL> file_versions + find_links_versions + page_versions + <EOL> dependency_versions <EOL> ) <EOL> def find_requirement ( self , req , upgrade ) : <EOL> """<STR_LIT>""" <EOL> all_versions = self . _find_all_versions ( req . name ) <EOL> _versions = set ( <EOL> req . specifier . filter ( <EOL> [ str ( x . version ) for x in all_versions ] , <EOL> prereleases = ( <EOL> self . allow_all_prereleases <EOL> if self . allow_all_prereleases else None <EOL> ) , <EOL> ) <EOL> ) <EOL> applicable_versions = [ <EOL> x for x in all_versions if str ( x . version ) in _versions <EOL> ] <EOL> if req . satisfied_by is not None : <EOL> applicable_versions . insert ( <EOL> <NUM_LIT:0> , <EOL> InstallationCandidate ( <EOL> req . name , <EOL> req . satisfied_by . version , <EOL> INSTALLED_VERSION , <EOL> ) <EOL> ) <EOL> existing_applicable = True <EOL> else : <EOL> existing_applicable = False <EOL> applicable_versions = self . _sort_versions ( applicable_versions ) <EOL> if not upgrade and existing_applicable : <EOL> if applicable_versions [ <NUM_LIT:0> ] . location is INSTALLED_VERSION : <EOL> logger . debug ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> req . satisfied_by . version , <EOL> ) <EOL> else : <EOL> logger . debug ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> req . satisfied_by . version , <EOL> applicable_versions [ <NUM_LIT:0> ] [ <NUM_LIT:2> ] , <EOL> ) <EOL> return None <EOL> if not applicable_versions : <EOL> logger . critical ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> req , <EOL> '<STR_LIT:U+002CU+0020>' . join ( <EOL> sorted ( <EOL> set ( str ( i . version ) for i in all_versions ) , <EOL> key = parse_version , <EOL> ) <EOL> ) <EOL> ) <EOL> if self . need_warn_external : <EOL> logger . warning ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> req . name , <EOL> ) <EOL> if self . need_warn_unverified : <EOL> logger . warning ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> req . name , <EOL> ) <EOL> raise DistributionNotFound ( <EOL> '<STR_LIT>' % req <EOL> ) <EOL> if applicable_versions [ <NUM_LIT:0> ] . location is INSTALLED_VERSION : <EOL> logger . debug ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> req . satisfied_by . version , <EOL> '<STR_LIT:U+002CU+0020>' . join ( str ( i . version ) for i in applicable_versions [ <NUM_LIT:1> : ] ) or <EOL> "<STR_LIT:none>" , <EOL> ) <EOL> raise BestVersionAlreadyInstalled <EOL> if len ( applicable_versions ) > <NUM_LIT:1> : <EOL> logger . debug ( <EOL> '<STR_LIT>' , <EOL> applicable_versions [ <NUM_LIT:0> ] . version , <EOL> '<STR_LIT:U+002CU+0020>' . join ( str ( i . version ) for i in applicable_versions ) <EOL> ) <EOL> selected_version = applicable_versions [ <NUM_LIT:0> ] . location <EOL> if ( selected_version . verifiable is not None and not <EOL> selected_version . verifiable ) : <EOL> logger . warning ( <EOL> "<STR_LIT>" , req . name , <EOL> ) <EOL> return selected_version <EOL> def _find_url_name ( self , index_url , url_name ) : <EOL> """<STR_LIT>""" <EOL> if not index_url . url . endswith ( '<STR_LIT:/>' ) : <EOL> index_url . url += '<STR_LIT:/>' <EOL> page = self . _get_page ( index_url ) <EOL> if page is None : <EOL> logger . critical ( '<STR_LIT>' , index_url ) <EOL> return <EOL> norm_name = normalize_name ( url_name ) <EOL> for link in page . links : <EOL> base = posixpath . basename ( link . path . rstrip ( '<STR_LIT:/>' ) ) <EOL> if norm_name == normalize_name ( base ) : <EOL> logger . debug ( <EOL> '<STR_LIT>' , url_name , base , <EOL> ) <EOL> return base <EOL> return None <EOL> def _get_pages ( self , locations , project_name ) : <EOL> """<STR_LIT>""" <EOL> all_locations = list ( locations ) <EOL> seen = set ( ) <EOL> normalized = normalize_name ( project_name ) <EOL> while all_locations : <EOL> location = all_locations . pop ( <NUM_LIT:0> ) <EOL> if location in seen : <EOL> continue <EOL> seen . add ( location ) <EOL> page = self . _get_page ( location ) <EOL> if page is None : <EOL> continue <EOL> yield page <EOL> for link in page . rel_links ( ) : <EOL> if ( normalized not in self . allow_external and not <EOL> self . allow_all_external ) : <EOL> self . need_warn_external = True <EOL> logger . debug ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> link , <EOL> ) <EOL> continue <EOL> if ( link . trusted is not None and not <EOL> link . trusted and <EOL> normalized not in self . allow_unverified ) : <EOL> logger . debug ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> link , <EOL> ) <EOL> self . need_warn_unverified = True <EOL> continue <EOL> all_locations . append ( link ) <EOL> _py_version_re = re . compile ( r'<STR_LIT>' ) <EOL> def _sort_links ( self , links ) : <EOL> """<STR_LIT>""" <EOL> eggs , no_eggs = [ ] , [ ] <EOL> seen = set ( ) <EOL> for link in links : <EOL> if link not in seen : <EOL> seen . add ( link ) <EOL> if link . egg_fragment : <EOL> eggs . append ( link ) <EOL> else : <EOL> no_eggs . append ( link ) <EOL> return no_eggs + eggs <EOL> def _package_versions ( self , links , search ) : <EOL> result = [ ] <EOL> for link in self . _sort_links ( links ) : <EOL> v = self . _link_package_versions ( link , search ) <EOL> if v is not None : <EOL> result . append ( v ) <EOL> return result <EOL> def _log_skipped_link ( self , link , reason ) : <EOL> if link not in self . logged_links : <EOL> logger . debug ( '<STR_LIT>' , link , reason ) <EOL> self . logged_links . add ( link ) <EOL> def _link_package_versions ( self , link , search ) : <EOL> """<STR_LIT>""" <EOL> platform = get_platform ( ) <EOL> version = None <EOL> if link . egg_fragment : <EOL> egg_info = link . egg_fragment <EOL> ext = link . ext <EOL> else : <EOL> egg_info , ext = link . splitext ( ) <EOL> if not ext : <EOL> self . _log_skipped_link ( link , '<STR_LIT>' ) <EOL> return <EOL> if ext not in SUPPORTED_EXTENSIONS : <EOL> self . _log_skipped_link ( <EOL> link , '<STR_LIT>' % ext ) <EOL> return <EOL> if "<STR_LIT>" not in search . formats and ext == wheel_ext : <EOL> self . _log_skipped_link ( <EOL> link , '<STR_LIT>' % search . supplied ) <EOL> return <EOL> if "<STR_LIT>" in link . path and ext == '<STR_LIT>' : <EOL> self . _log_skipped_link ( link , '<STR_LIT>' ) <EOL> return <EOL> if ext == wheel_ext : <EOL> try : <EOL> wheel = Wheel ( link . filename ) <EOL> except InvalidWheelFilename : <EOL> self . _log_skipped_link ( link , '<STR_LIT>' ) <EOL> return <EOL> if ( pkg_resources . safe_name ( wheel . name ) . lower ( ) != <EOL> search . canonical ) : <EOL> self . _log_skipped_link ( <EOL> link , '<STR_LIT>' % search . supplied ) <EOL> return <EOL> if not wheel . supported ( ) : <EOL> self . _log_skipped_link ( <EOL> link , '<STR_LIT>' ) <EOL> return <EOL> comes_from = getattr ( link , "<STR_LIT>" , None ) <EOL> if ( <EOL> ( <EOL> not platform . startswith ( '<STR_LIT>' ) and not <EOL> platform . startswith ( '<STR_LIT>' ) and not <EOL> platform == '<STR_LIT>' <EOL> ) and <EOL> comes_from is not None and <EOL> urllib_parse . urlparse ( <EOL> comes_from . url <EOL> ) . netloc . endswith ( PyPI . netloc ) ) : <EOL> if not wheel . supported ( tags = supported_tags_noarch ) : <EOL> self . _log_skipped_link ( <EOL> link , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> ) <EOL> return <EOL> version = wheel . version <EOL> if "<STR_LIT:source>" not in search . formats and ext != wheel_ext : <EOL> self . _log_skipped_link ( <EOL> link , '<STR_LIT>' % search . supplied ) <EOL> return <EOL> if not version : <EOL> version = egg_info_matches ( egg_info , search . supplied , link ) <EOL> if version is None : <EOL> self . _log_skipped_link ( <EOL> link , '<STR_LIT>' % search . supplied ) <EOL> return <EOL> if ( link . internal is not None and not <EOL> link . internal and not <EOL> normalize_name ( search . supplied ) . lower ( ) <EOL> in self . allow_external and not <EOL> self . allow_all_external ) : <EOL> self . _log_skipped_link ( link , '<STR_LIT>' ) <EOL> self . need_warn_external = True <EOL> return <EOL> if ( link . verifiable is not None and not <EOL> link . verifiable and not <EOL> ( normalize_name ( search . supplied ) . lower ( ) <EOL> in self . allow_unverified ) ) : <EOL> self . _log_skipped_link ( <EOL> link , '<STR_LIT>' ) <EOL> self . need_warn_unverified = True <EOL> return <EOL> match = self . _py_version_re . search ( version ) <EOL> if match : <EOL> version = version [ : match . start ( ) ] <EOL> py_version = match . group ( <NUM_LIT:1> ) <EOL> if py_version != sys . version [ : <NUM_LIT:3> ] : <EOL> self . _log_skipped_link ( <EOL> link , '<STR_LIT>' ) <EOL> return <EOL> logger . debug ( '<STR_LIT>' , link , version ) <EOL> return InstallationCandidate ( search . supplied , version , link ) <EOL> def _get_page ( self , link ) : <EOL> return HTMLPage . get_page ( link , session = self . session ) <EOL> def egg_info_matches ( <EOL> egg_info , search_name , link , <EOL> _egg_info_re = re . compile ( r'<STR_LIT>' , re . I ) ) : <EOL> """<STR_LIT>""" <EOL> match = _egg_info_re . search ( egg_info ) <EOL> if not match : <EOL> logger . debug ( '<STR_LIT>' , link ) <EOL> return None <EOL> if search_name is None : <EOL> full_match = match . group ( <NUM_LIT:0> ) <EOL> return full_match [ full_match . index ( '<STR_LIT:->' ) : ] <EOL> name = match . group ( <NUM_LIT:0> ) . lower ( ) <EOL> name = name . replace ( '<STR_LIT:_>' , '<STR_LIT:->' ) <EOL> look_for = search_name . lower ( ) + "<STR_LIT:->" <EOL> if name . startswith ( look_for ) : <EOL> return match . group ( <NUM_LIT:0> ) [ len ( look_for ) : ] <EOL> else : <EOL> return None <EOL> class HTMLPage ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , content , url , headers = None , trusted = None ) : <EOL> encoding = None <EOL> if headers and "<STR_LIT:Content-Type>" in headers : <EOL> content_type , params = cgi . parse_header ( headers [ "<STR_LIT:Content-Type>" ] ) <EOL> if "<STR_LIT>" in params : <EOL> encoding = params [ '<STR_LIT>' ] <EOL> self . content = content <EOL> self . parsed = html5lib . parse ( <EOL> self . content , <EOL> encoding = encoding , <EOL> namespaceHTMLElements = False , <EOL> ) <EOL> self . url = url <EOL> self . headers = headers <EOL> self . trusted = trusted <EOL> def __str__ ( self ) : <EOL> return self . url <EOL> @ classmethod <EOL> def get_page ( cls , link , skip_archives = True , session = None ) : <EOL> if session is None : <EOL> raise TypeError ( <EOL> "<STR_LIT>" <EOL> ) <EOL> url = link . url <EOL> url = url . split ( '<STR_LIT:#>' , <NUM_LIT:1> ) [ <NUM_LIT:0> ] <EOL> from pip . vcs import VcsSupport <EOL> for scheme in VcsSupport . schemes : <EOL> if url . lower ( ) . startswith ( scheme ) and url [ len ( scheme ) ] in '<STR_LIT>' : <EOL> logger . debug ( '<STR_LIT>' , scheme , link ) <EOL> return None <EOL> try : <EOL> if skip_archives : <EOL> filename = link . filename <EOL> for bad_ext in ARCHIVE_EXTENSIONS : <EOL> if filename . endswith ( bad_ext ) : <EOL> content_type = cls . _get_content_type ( <EOL> url , session = session , <EOL> ) <EOL> if content_type . lower ( ) . startswith ( '<STR_LIT>' ) : <EOL> break <EOL> else : <EOL> logger . debug ( <EOL> '<STR_LIT>' , <EOL> link , <EOL> content_type , <EOL> ) <EOL> return <EOL> logger . debug ( '<STR_LIT>' , url ) <EOL> ( scheme , netloc , path , params , query , fragment ) = urllib_parse . urlparse ( url ) <EOL> if ( scheme == '<STR_LIT:file>' and <EOL> os . path . isdir ( urllib_request . url2pathname ( path ) ) ) : <EOL> if not url . endswith ( '<STR_LIT:/>' ) : <EOL> url += '<STR_LIT:/>' <EOL> url = urllib_parse . urljoin ( url , '<STR_LIT>' ) <EOL> logger . debug ( '<STR_LIT>' , url ) <EOL> resp = session . get ( <EOL> url , <EOL> headers = { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> } , <EOL> ) <EOL> resp . raise_for_status ( ) <EOL> content_type = resp . headers . get ( '<STR_LIT:Content-Type>' , '<STR_LIT>' ) <EOL> if not content_type . lower ( ) . startswith ( "<STR_LIT>" ) : <EOL> logger . debug ( <EOL> '<STR_LIT>' , <EOL> link , <EOL> content_type , <EOL> ) <EOL> return <EOL> inst = cls ( <EOL> resp . content , resp . url , resp . headers , <EOL> trusted = link . trusted , <EOL> ) <EOL> except requests . HTTPError as exc : <EOL> level = <NUM_LIT:2> if exc . response . status_code == <NUM_LIT> else <NUM_LIT:1> <EOL> cls . _handle_fail ( link , exc , url , level = level ) <EOL> except requests . ConnectionError as exc : <EOL> cls . _handle_fail ( link , "<STR_LIT>" % exc , url ) <EOL> except requests . Timeout : <EOL> cls . _handle_fail ( link , "<STR_LIT>" , url ) <EOL> except SSLError as exc : <EOL> reason = ( "<STR_LIT>" <EOL> "<STR_LIT:%s>" % exc ) <EOL> cls . _handle_fail ( link , reason , url , level = <NUM_LIT:2> , meth = logger . info ) <EOL> else : <EOL> return inst <EOL> @ staticmethod <EOL> def _handle_fail ( link , reason , url , level = <NUM_LIT:1> , meth = None ) : <EOL> if meth is None : <EOL> meth = logger . debug <EOL> meth ( "<STR_LIT>" , link , reason ) <EOL> @ staticmethod <EOL> def _get_content_type ( url , session ) : <EOL> """<STR_LIT>""" <EOL> scheme , netloc , path , query , fragment = urllib_parse . urlsplit ( url ) <EOL> if scheme not in ( '<STR_LIT:http>' , '<STR_LIT>' ) : <EOL> return '<STR_LIT>' <EOL> resp = session . head ( url , allow_redirects = True ) <EOL> resp . raise_for_status ( ) <EOL> return resp . headers . get ( "<STR_LIT:Content-Type>" , "<STR_LIT>" ) <EOL> @ cached_property <EOL> def api_version ( self ) : <EOL> metas = [ <EOL> x for x in self . parsed . findall ( "<STR_LIT>" ) <EOL> if x . get ( "<STR_LIT:name>" , "<STR_LIT>" ) . lower ( ) == "<STR_LIT>" <EOL> ] <EOL> if metas : <EOL> try : <EOL> return int ( metas [ <NUM_LIT:0> ] . get ( "<STR_LIT:value>" , None ) ) <EOL> except ( TypeError , ValueError ) : <EOL> pass <EOL> return None <EOL> @ cached_property <EOL> def base_url ( self ) : <EOL> bases = [ <EOL> x for x in self . parsed . findall ( "<STR_LIT>" ) <EOL> if x . get ( "<STR_LIT>" ) is not None <EOL> ] <EOL> if bases and bases [ <NUM_LIT:0> ] . get ( "<STR_LIT>" ) : <EOL> return bases [ <NUM_LIT:0> ] . get ( "<STR_LIT>" ) <EOL> else : <EOL> return self . url <EOL> @ property <EOL> def links ( self ) : <EOL> """<STR_LIT>""" <EOL> for anchor in self . parsed . findall ( "<STR_LIT>" ) : <EOL> if anchor . get ( "<STR_LIT>" ) : <EOL> href = anchor . get ( "<STR_LIT>" ) <EOL> url = self . clean_link ( <EOL> urllib_parse . urljoin ( self . base_url , href ) <EOL> ) <EOL> internal = None <EOL> if self . api_version and self . api_version >= <NUM_LIT:2> : <EOL> internal = bool ( <EOL> anchor . get ( "<STR_LIT>" ) and <EOL> "<STR_LIT>" in anchor . get ( "<STR_LIT>" ) . split ( ) <EOL> ) <EOL> yield Link ( url , self , internal = internal ) <EOL> def rel_links ( self , rels = ( '<STR_LIT>' , '<STR_LIT>' ) ) : <EOL> """<STR_LIT>""" <EOL> rels = set ( rels ) <EOL> for anchor in self . parsed . findall ( "<STR_LIT>" ) : <EOL> if anchor . get ( "<STR_LIT>" ) and anchor . get ( "<STR_LIT>" ) : <EOL> found_rels = set ( anchor . get ( "<STR_LIT>" ) . split ( ) ) <EOL> if found_rels & rels : <EOL> href = anchor . get ( "<STR_LIT>" ) <EOL> url = self . clean_link ( <EOL> urllib_parse . urljoin ( self . base_url , href ) <EOL> ) <EOL> yield Link ( url , self , trusted = False ) <EOL> _clean_re = re . compile ( r'<STR_LIT>' , re . I ) <EOL> def clean_link ( self , url ) : <EOL> """<STR_LIT>""" <EOL> return self . _clean_re . sub ( <EOL> lambda match : '<STR_LIT>' % ord ( match . group ( <NUM_LIT:0> ) ) , url ) <EOL> class Link ( object ) : <EOL> def __init__ ( self , url , comes_from = None , internal = None , trusted = None ) : <EOL> if url != Inf and url . startswith ( '<STR_LIT>' ) : <EOL> url = path_to_url ( url ) <EOL> self . url = url <EOL> self . comes_from = comes_from <EOL> self . internal = internal <EOL> self . trusted = trusted <EOL> def __str__ ( self ) : <EOL> if self . comes_from : <EOL> return '<STR_LIT>' % ( self . url , self . comes_from ) <EOL> else : <EOL> return str ( self . url ) <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % self <EOL> def __eq__ ( self , other ) : <EOL> if not isinstance ( other , Link ) : <EOL> return NotImplemented <EOL> return self . url == other . url <EOL> def __ne__ ( self , other ) : <EOL> if not isinstance ( other , Link ) : <EOL> return NotImplemented <EOL> return self . url != other . url <EOL> def __lt__ ( self , other ) : <EOL> if not isinstance ( other , Link ) : <EOL> return NotImplemented <EOL> return self . url < other . url <EOL> def __le__ ( self , other ) : <EOL> if not isinstance ( other , Link ) : <EOL> return NotImplemented <EOL> return self . url <= other . url <EOL> def __gt__ ( self , other ) : <EOL> if not isinstance ( other , Link ) : <EOL> return NotImplemented <EOL> return self . url > other . url <EOL> def __ge__ ( self , other ) : <EOL> if not isinstance ( other , Link ) : <EOL> return NotImplemented <EOL> return self . url >= other . url <EOL> def __hash__ ( self ) : <EOL> return hash ( self . url ) <EOL> @ property <EOL> def filename ( self ) : <EOL> _ , netloc , path , _ , _ = urllib_parse . urlsplit ( self . url ) <EOL> name = posixpath . basename ( path . rstrip ( '<STR_LIT:/>' ) ) or netloc <EOL> name = urllib_parse . unquote ( name ) <EOL> assert name , ( '<STR_LIT>' % self . url ) <EOL> return name <EOL> @ property <EOL> def scheme ( self ) : <EOL> return urllib_parse . urlsplit ( self . url ) [ <NUM_LIT:0> ] <EOL> @ property <EOL> def netloc ( self ) : <EOL> return urllib_parse . urlsplit ( self . url ) [ <NUM_LIT:1> ] <EOL> @ property <EOL> def path ( self ) : <EOL> return urllib_parse . unquote ( urllib_parse . urlsplit ( self . url ) [ <NUM_LIT:2> ] ) <EOL> def splitext ( self ) : <EOL> return splitext ( posixpath . basename ( self . path . rstrip ( '<STR_LIT:/>' ) ) ) <EOL> @ property <EOL> def ext ( self ) : <EOL> return self . splitext ( ) [ <NUM_LIT:1> ] <EOL> @ property <EOL> def url_without_fragment ( self ) : <EOL> scheme , netloc , path , query , fragment = urllib_parse . urlsplit ( self . url ) <EOL> return urllib_parse . urlunsplit ( ( scheme , netloc , path , query , None ) ) <EOL> _egg_fragment_re = re . compile ( r'<STR_LIT>' ) <EOL> @ property <EOL> def egg_fragment ( self ) : <EOL> match = self . _egg_fragment_re . search ( self . url ) <EOL> if not match : <EOL> return None <EOL> return match . group ( <NUM_LIT:1> ) <EOL> _hash_re = re . compile ( <EOL> r'<STR_LIT>' <EOL> ) <EOL> @ property <EOL> def hash ( self ) : <EOL> match = self . _hash_re . search ( self . url ) <EOL> if match : <EOL> return match . group ( <NUM_LIT:2> ) <EOL> return None <EOL> @ property <EOL> def hash_name ( self ) : <EOL> match = self . _hash_re . search ( self . url ) <EOL> if match : <EOL> return match . group ( <NUM_LIT:1> ) <EOL> return None <EOL> @ property <EOL> def show_url ( self ) : <EOL> return posixpath . basename ( self . url . split ( '<STR_LIT:#>' , <NUM_LIT:1> ) [ <NUM_LIT:0> ] . split ( '<STR_LIT:?>' , <NUM_LIT:1> ) [ <NUM_LIT:0> ] ) <EOL> @ property <EOL> def verifiable ( self ) : <EOL> """<STR_LIT>""" <EOL> trusted = self . trusted or getattr ( self . comes_from , "<STR_LIT>" , None ) <EOL> if trusted is not None and trusted : <EOL> try : <EOL> api_version = getattr ( self . comes_from , "<STR_LIT>" , None ) <EOL> api_version = int ( api_version ) <EOL> except ( ValueError , TypeError ) : <EOL> api_version = None <EOL> if api_version is None or api_version <= <NUM_LIT:1> : <EOL> return <EOL> if self . hash : <EOL> return True <EOL> else : <EOL> return False <EOL> elif trusted is not None : <EOL> return False <EOL> @ property <EOL> def is_wheel ( self ) : <EOL> return self . ext == wheel_ext <EOL> @ property <EOL> def is_artifact ( self ) : <EOL> """<STR_LIT>""" <EOL> from pip . vcs import vcs <EOL> if self . scheme in vcs . all_schemes : <EOL> return False <EOL> return True <EOL> INSTALLED_VERSION = Link ( Inf ) <EOL> FormatControl = namedtuple ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> """<STR_LIT>""" <EOL> def fmt_ctl_handle_mutual_exclude ( value , target , other ) : <EOL> new = value . split ( '<STR_LIT:U+002C>' ) <EOL> while '<STR_LIT>' in new : <EOL> other . clear ( ) <EOL> target . clear ( ) <EOL> target . add ( '<STR_LIT>' ) <EOL> del new [ : new . index ( '<STR_LIT>' ) + <NUM_LIT:1> ] <EOL> if '<STR_LIT>' not in new : <EOL> return <EOL> for name in new : <EOL> if name == '<STR_LIT>' : <EOL> target . clear ( ) <EOL> continue <EOL> name = pkg_resources . safe_name ( name ) . lower ( ) <EOL> other . discard ( name ) <EOL> target . add ( name ) <EOL> def fmt_ctl_formats ( fmt_ctl , canonical_name ) : <EOL> result = set ( [ "<STR_LIT>" , "<STR_LIT:source>" ] ) <EOL> if canonical_name in fmt_ctl . only_binary : <EOL> result . discard ( '<STR_LIT:source>' ) <EOL> elif canonical_name in fmt_ctl . no_binary : <EOL> result . discard ( '<STR_LIT>' ) <EOL> elif '<STR_LIT>' in fmt_ctl . only_binary : <EOL> result . discard ( '<STR_LIT:source>' ) <EOL> elif '<STR_LIT>' in fmt_ctl . no_binary : <EOL> result . discard ( '<STR_LIT>' ) <EOL> return frozenset ( result ) <EOL> def fmt_ctl_no_binary ( fmt_ctl ) : <EOL> fmt_ctl_handle_mutual_exclude ( <EOL> '<STR_LIT>' , fmt_ctl . no_binary , fmt_ctl . only_binary ) <EOL> def fmt_ctl_no_use_wheel ( fmt_ctl ) : <EOL> fmt_ctl_no_binary ( fmt_ctl ) <EOL> warnings . warn ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , DeprecationWarning , <EOL> stacklevel = <NUM_LIT:2> ) <EOL> Search = namedtuple ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> """<STR_LIT>""" </s>
