<s> from __future__ import absolute_import <EOL> import logging <EOL> import os <EOL> import re <EOL> from pip . _vendor . six . moves . urllib import parse as urllib_parse <EOL> from pip . index import Link <EOL> from pip . utils import rmtree , display_path <EOL> from pip . utils . logging import indent_log <EOL> from pip . vcs import vcs , VersionControl <EOL> _svn_xml_url_re = re . compile ( '<STR_LIT>' ) <EOL> _svn_rev_re = re . compile ( '<STR_LIT>' ) <EOL> _svn_url_re = re . compile ( r'<STR_LIT>' ) <EOL> _svn_revision_re = re . compile ( r'<STR_LIT>' ) <EOL> _svn_info_xml_rev_re = re . compile ( r'<STR_LIT>' ) <EOL> _svn_info_xml_url_re = re . compile ( r'<STR_LIT>' ) <EOL> logger = logging . getLogger ( __name__ ) <EOL> class Subversion ( VersionControl ) : <EOL> name = '<STR_LIT>' <EOL> dirname = '<STR_LIT>' <EOL> repo_name = '<STR_LIT>' <EOL> schemes = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> def get_info ( self , location ) : <EOL> """<STR_LIT>""" <EOL> assert not location . rstrip ( '<STR_LIT:/>' ) . endswith ( self . dirname ) , '<STR_LIT>' % location <EOL> output = self . run_command ( <EOL> [ '<STR_LIT:info>' , location ] , <EOL> show_stdout = False , <EOL> extra_environ = { '<STR_LIT>' : '<STR_LIT:C>' } , <EOL> ) <EOL> match = _svn_url_re . search ( output ) <EOL> if not match : <EOL> logger . warning ( <EOL> '<STR_LIT>' , <EOL> display_path ( location ) , <EOL> ) <EOL> logger . debug ( '<STR_LIT>' , output ) <EOL> return None , None <EOL> url = match . group ( <NUM_LIT:1> ) . strip ( ) <EOL> match = _svn_revision_re . search ( output ) <EOL> if not match : <EOL> logger . warning ( <EOL> '<STR_LIT>' , <EOL> display_path ( location ) , <EOL> ) <EOL> logger . debug ( '<STR_LIT>' , output ) <EOL> return url , None <EOL> return url , match . group ( <NUM_LIT:1> ) <EOL> def export ( self , location ) : <EOL> """<STR_LIT>""" <EOL> url , rev = self . get_url_rev ( ) <EOL> rev_options = get_rev_options ( url , rev ) <EOL> logger . info ( '<STR_LIT>' , url , location ) <EOL> with indent_log ( ) : <EOL> if os . path . exists ( location ) : <EOL> rmtree ( location ) <EOL> self . run_command ( <EOL> [ '<STR_LIT>' ] + rev_options + [ url , location ] , <EOL> show_stdout = False ) <EOL> def switch ( self , dest , url , rev_options ) : <EOL> self . run_command ( [ '<STR_LIT>' ] + rev_options + [ url , dest ] ) <EOL> def update ( self , dest , rev_options ) : <EOL> self . run_command ( [ '<STR_LIT>' ] + rev_options + [ dest ] ) <EOL> def obtain ( self , dest ) : <EOL> url , rev = self . get_url_rev ( ) <EOL> rev_options = get_rev_options ( url , rev ) <EOL> if rev : <EOL> rev_display = '<STR_LIT>' % rev <EOL> else : <EOL> rev_display = '<STR_LIT>' <EOL> if self . check_destination ( dest , url , rev_options , rev_display ) : <EOL> logger . info ( <EOL> '<STR_LIT>' , <EOL> url , <EOL> rev_display , <EOL> display_path ( dest ) , <EOL> ) <EOL> self . run_command ( [ '<STR_LIT>' , '<STR_LIT>' ] + rev_options + [ url , dest ] ) <EOL> def get_location ( self , dist , dependency_links ) : <EOL> for url in dependency_links : <EOL> egg_fragment = Link ( url ) . egg_fragment <EOL> if not egg_fragment : <EOL> continue <EOL> if '<STR_LIT:->' in egg_fragment : <EOL> key = '<STR_LIT:->' . join ( egg_fragment . split ( '<STR_LIT:->' ) [ : - <NUM_LIT:1> ] ) . lower ( ) <EOL> else : <EOL> key = egg_fragment <EOL> if key == dist . key : <EOL> return url . split ( '<STR_LIT:#>' , <NUM_LIT:1> ) [ <NUM_LIT:0> ] <EOL> return None <EOL> def get_revision ( self , location ) : <EOL> """<STR_LIT>""" <EOL> revision = <NUM_LIT:0> <EOL> for base , dirs , files in os . walk ( location ) : <EOL> if self . dirname not in dirs : <EOL> dirs [ : ] = [ ] <EOL> continue <EOL> dirs . remove ( self . dirname ) <EOL> entries_fn = os . path . join ( base , self . dirname , '<STR_LIT>' ) <EOL> if not os . path . exists ( entries_fn ) : <EOL> continue <EOL> dirurl , localrev = self . _get_svn_url_rev ( base ) <EOL> if base == location : <EOL> base_url = dirurl + '<STR_LIT:/>' <EOL> elif not dirurl or not dirurl . startswith ( base_url ) : <EOL> dirs [ : ] = [ ] <EOL> continue <EOL> revision = max ( revision , localrev ) <EOL> return revision <EOL> def get_url_rev ( self ) : <EOL> url , rev = super ( Subversion , self ) . get_url_rev ( ) <EOL> if url . startswith ( '<STR_LIT>' ) : <EOL> url = '<STR_LIT>' + url <EOL> return url , rev <EOL> def get_url ( self , location ) : <EOL> orig_location = location <EOL> while not os . path . exists ( os . path . join ( location , '<STR_LIT>' ) ) : <EOL> last_location = location <EOL> location = os . path . dirname ( location ) <EOL> if location == last_location : <EOL> logger . warning ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> orig_location , <EOL> ) <EOL> return None <EOL> return self . _get_svn_url_rev ( location ) [ <NUM_LIT:0> ] <EOL> def _get_svn_url_rev ( self , location ) : <EOL> from pip . exceptions import InstallationError <EOL> with open ( os . path . join ( location , self . dirname , '<STR_LIT>' ) ) as f : <EOL> data = f . read ( ) <EOL> if ( data . startswith ( '<STR_LIT>' ) or <EOL> data . startswith ( '<STR_LIT>' ) or <EOL> data . startswith ( '<STR_LIT>' ) ) : <EOL> data = list ( map ( str . splitlines , data . split ( '<STR_LIT>' ) ) ) <EOL> del data [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] <EOL> url = data [ <NUM_LIT:0> ] [ <NUM_LIT:3> ] <EOL> revs = [ int ( d [ <NUM_LIT:9> ] ) for d in data if len ( d ) > <NUM_LIT:9> and d [ <NUM_LIT:9> ] ] + [ <NUM_LIT:0> ] <EOL> elif data . startswith ( '<STR_LIT>' ) : <EOL> match = _svn_xml_url_re . search ( data ) <EOL> if not match : <EOL> raise ValueError ( '<STR_LIT>' % data ) <EOL> url = match . group ( <NUM_LIT:1> ) <EOL> revs = [ int ( m . group ( <NUM_LIT:1> ) ) for m in _svn_rev_re . finditer ( data ) ] + [ <NUM_LIT:0> ] <EOL> else : <EOL> try : <EOL> xml = self . run_command ( <EOL> [ '<STR_LIT:info>' , '<STR_LIT>' , location ] , <EOL> show_stdout = False , <EOL> ) <EOL> url = _svn_info_xml_url_re . search ( xml ) . group ( <NUM_LIT:1> ) <EOL> revs = [ <EOL> int ( m . group ( <NUM_LIT:1> ) ) for m in _svn_info_xml_rev_re . finditer ( xml ) <EOL> ] <EOL> except InstallationError : <EOL> url , revs = None , [ ] <EOL> if revs : <EOL> rev = max ( revs ) <EOL> else : <EOL> rev = <NUM_LIT:0> <EOL> return url , rev <EOL> def get_tag_revs ( self , svn_tag_url ) : <EOL> stdout = self . run_command ( [ '<STR_LIT>' , '<STR_LIT>' , svn_tag_url ] , show_stdout = False ) <EOL> results = [ ] <EOL> for line in stdout . splitlines ( ) : <EOL> parts = line . split ( ) <EOL> rev = int ( parts [ <NUM_LIT:0> ] ) <EOL> tag = parts [ - <NUM_LIT:1> ] . strip ( '<STR_LIT:/>' ) <EOL> results . append ( ( tag , rev ) ) <EOL> return results <EOL> def find_tag_match ( self , rev , tag_revs ) : <EOL> best_match_rev = None <EOL> best_tag = None <EOL> for tag , tag_rev in tag_revs : <EOL> if ( tag_rev > rev and <EOL> ( best_match_rev is None or best_match_rev > tag_rev ) ) : <EOL> best_match_rev = tag_rev <EOL> best_tag = tag <EOL> return best_tag <EOL> def get_src_requirement ( self , dist , location , find_tags = False ) : <EOL> repo = self . get_url ( location ) <EOL> if repo is None : <EOL> return None <EOL> parts = repo . split ( '<STR_LIT:/>' ) <EOL> egg_project_name = dist . egg_name ( ) . split ( '<STR_LIT:->' , <NUM_LIT:1> ) [ <NUM_LIT:0> ] <EOL> rev = self . get_revision ( location ) <EOL> if parts [ - <NUM_LIT:2> ] in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> full_egg_name = '<STR_LIT>' % ( egg_project_name , parts [ - <NUM_LIT:1> ] ) <EOL> elif parts [ - <NUM_LIT:2> ] in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> full_egg_name = '<STR_LIT>' % ( dist . egg_name ( ) , parts [ - <NUM_LIT:1> ] , rev ) <EOL> elif parts [ - <NUM_LIT:1> ] == '<STR_LIT>' : <EOL> full_egg_name = '<STR_LIT>' % ( dist . egg_name ( ) , rev ) <EOL> if find_tags : <EOL> tag_url = '<STR_LIT:/>' . join ( parts [ : - <NUM_LIT:1> ] ) + '<STR_LIT>' <EOL> tag_revs = self . get_tag_revs ( tag_url ) <EOL> match = self . find_tag_match ( rev , tag_revs ) <EOL> if match : <EOL> logger . info ( <EOL> '<STR_LIT>' , <EOL> match , <EOL> ) <EOL> repo = '<STR_LIT>' % ( tag_url , match ) <EOL> full_egg_name = '<STR_LIT>' % ( egg_project_name , match ) <EOL> else : <EOL> logger . warning ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT:%s>' , <EOL> repo , <EOL> ) <EOL> full_egg_name = '<STR_LIT>' % ( egg_project_name , rev ) <EOL> return '<STR_LIT>' % ( repo , rev , full_egg_name ) <EOL> def get_rev_options ( url , rev ) : <EOL> if rev : <EOL> rev_options = [ '<STR_LIT>' , rev ] <EOL> else : <EOL> rev_options = [ ] <EOL> r = urllib_parse . urlsplit ( url ) <EOL> if hasattr ( r , '<STR_LIT:username>' ) : <EOL> username , password = r . username , r . password <EOL> else : <EOL> netloc = r [ <NUM_LIT:1> ] <EOL> if '<STR_LIT:@>' in netloc : <EOL> auth = netloc . split ( '<STR_LIT:@>' ) [ <NUM_LIT:0> ] <EOL> if '<STR_LIT::>' in auth : <EOL> username , password = auth . split ( '<STR_LIT::>' , <NUM_LIT:1> ) <EOL> else : <EOL> username , password = auth , None <EOL> else : <EOL> username , password = None , None <EOL> if username : <EOL> rev_options += [ '<STR_LIT>' , username ] <EOL> if password : <EOL> rev_options += [ '<STR_LIT>' , password ] <EOL> return rev_options <EOL> vcs . register ( Subversion ) </s>
