#NEWLINE# def safe_join( base , * paths ) : #NEWLINE# #INDENT# '\n    Joins one or more path components to the base path component intelligently.\n    Returns a normalized, absolute version of the final path.\n\n    The final path must be located inside of the base path component (otherwise\n    a ValueError is raised).\n    ' #NEWLINE# base = force_unicode ( base ) #NEWLINE# paths = [ force_unicode ( p ) for p in paths ] #NEWLINE# final_path = abspathu ( join ( base , * paths ) ) #NEWLINE# base_path = abspathu ( base ) #NEWLINE# base_path_len = len ( base_path ) #NEWLINE# if ( ( not normcase ( final_path ) . startswith ( normcase ( base_path ) ) ) or ( final_path [ base_path_len : ( base_path_len + 1 ) ] not in ( '' , sep ) ) ) : #NEWLINE# #INDENT# raise ValueError ( ( 'The joined path (%s) is located outside of the base path component (%s)' % ( final_path , base_path ) ) ) #NEWLINE# #UNINDENT# return final_path