#NEWLINE# def urljoin( base , url , allow_fragments = True ) : #NEWLINE# #INDENT# if ( not base ) : #NEWLINE# #INDENT# return url #NEWLINE# #UNINDENT# if ( not url ) : #NEWLINE# #INDENT# return base #NEWLINE# #UNINDENT# ( bscheme , bnetloc , bpath , bparams , bquery , bfragment ) = urlparse ( base , '' , allow_fragments ) #NEWLINE# ( scheme , netloc , path , params , query , fragment ) = urlparse ( url , bscheme , allow_fragments ) #NEWLINE# if ( ( scheme != bscheme ) or ( scheme not in uses_relative ) ) : #NEWLINE# #INDENT# return url #NEWLINE# #UNINDENT# if ( scheme in uses_netloc ) : #NEWLINE# #INDENT# if netloc : #NEWLINE# #INDENT# return urlunparse ( ( scheme , netloc , path , params , query , fragment ) ) #NEWLINE# #UNINDENT# netloc = bnetloc #NEWLINE# #UNINDENT# if ( path [ : 1 ] == '/' ) : #NEWLINE# #INDENT# return urlunparse ( ( scheme , netloc , path , params , query , fragment ) ) #NEWLINE# #UNINDENT# if ( not ( path or params or query ) ) : #NEWLINE# #INDENT# return urlunparse ( ( scheme , netloc , bpath , bparams , bquery , fragment ) ) #NEWLINE# #UNINDENT# segments = ( bpath . split ( '/' ) [ : ( - 1 ) ] + path . split ( '/' ) ) #NEWLINE# if ( segments [ ( - 1 ) ] == '.' ) : #NEWLINE# #INDENT# segments [ ( - 1 ) ] = '' #NEWLINE# #UNINDENT# while ( '.' in segments ) : #NEWLINE# #INDENT# segments . remove ( '.' ) #NEWLINE# #UNINDENT# while True : #NEWLINE# #INDENT# ( n , i , old_s ) = ( ( len ( segments ) - 1 ) , 1 , tuple ( segments ) ) #NEWLINE# while ( i < n ) : #NEWLINE# #INDENT# if ( ( segments [ i ] == '..' ) and ( segments [ ( i - 1 ) ] not in ( '' , '..' ) ) ) : #NEWLINE# #INDENT# del segments [ ( i - 1 ) : ( i + 1 ) ] #NEWLINE# break #NEWLINE# #UNINDENT# i = ( i + 1 ) #NEWLINE# #UNINDENT# if ( old_s == tuple ( segments ) ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# #UNINDENT# if ( segments == [ '' , '..' ] ) : #NEWLINE# #INDENT# segments [ ( - 1 ) ] = '' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( len ( segments ) >= 2 ) and ( segments [ ( - 1 ) ] == '..' ) ) : #NEWLINE# #INDENT# segments = ( segments [ 0 : ( - 2 ) ] + [ '' ] ) #NEWLINE# #UNINDENT# #UNINDENT# return urlunparse ( ( scheme , netloc , '/' . join ( segments ) , params , query , fragment ) )