#NEWLINE# def get_file_content( url , comes_from = None , session = None ) : #NEWLINE# #INDENT# 'Gets the content of a file; it may be a filename, file: URL, or\n    http: URL.  Returns (location, content).  Content is unicode.' #NEWLINE# if ( session is None ) : #NEWLINE# #INDENT# session = PipSession ( ) #NEWLINE# #UNINDENT# match = _scheme_re . search ( url ) #NEWLINE# if match : #NEWLINE# #INDENT# scheme = match . group ( 1 ) . lower ( ) #NEWLINE# if ( ( scheme == 'file' ) and comes_from and comes_from . startswith ( 'http' ) ) : #NEWLINE# #INDENT# raise InstallationError ( ( 'Requirements file %s references URL %s, which is local' % ( comes_from , url ) ) ) #NEWLINE# #UNINDENT# if ( scheme == 'file' ) : #NEWLINE# #INDENT# path = url . split ( ':' , 1 ) [ 1 ] #NEWLINE# path = path . replace ( '\\' , '/' ) #NEWLINE# match = _url_slash_drive_re . match ( path ) #NEWLINE# if match : #NEWLINE# #INDENT# path = ( ( match . group ( 1 ) + ':' ) + path . split ( '|' , 1 ) [ 1 ] ) #NEWLINE# #UNINDENT# path = urllib . unquote ( path ) #NEWLINE# if path . startswith ( '/' ) : #NEWLINE# #INDENT# path = ( '/' + path . lstrip ( '/' ) ) #NEWLINE# #UNINDENT# url = path #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# resp = session . get ( url ) #NEWLINE# resp . raise_for_status ( ) #NEWLINE# if six . PY3 : #NEWLINE# #INDENT# return ( resp . url , resp . text ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return ( resp . url , resp . content ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# try : #NEWLINE# #INDENT# f = open ( url ) #NEWLINE# content = f . read ( ) #NEWLINE# #UNINDENT# except IOError : #NEWLINE# #INDENT# e = sys . exc_info ( ) [ 1 ] #NEWLINE# raise InstallationError ( ( 'Could not open requirements file: %s' % str ( e ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# f . close ( ) #NEWLINE# #UNINDENT# return ( url , content )