<s> import os <EOL> from os . path import join , normcase , normpath , abspath , isabs , sep <EOL> from google . appengine . _internal . django . utils . encoding import force_unicode <EOL> if os . name == '<STR_LIT>' : <EOL> abspathu = abspath <EOL> else : <EOL> def abspathu ( path ) : <EOL> """<STR_LIT>""" <EOL> if not isabs ( path ) : <EOL> path = join ( os . getcwdu ( ) , path ) <EOL> return normpath ( path ) <EOL> def safe_join ( base , * paths ) : <EOL> """<STR_LIT>""" <EOL> base = force_unicode ( base ) <EOL> paths = [ force_unicode ( p ) for p in paths ] <EOL> final_path = normcase ( abspathu ( join ( base , * paths ) ) ) <EOL> base_path = normcase ( abspathu ( base ) ) <EOL> base_path_len = len ( base_path ) <EOL> if not final_path . startswith ( base_path ) or final_path [ base_path_len : base_path_len + <NUM_LIT:1> ] not in ( '<STR_LIT>' , sep ) : <EOL> raise ValueError ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> return final_path </s>
