#NEWLINE# def clean_path( root , path , subdir = False ) : #NEWLINE# #INDENT# '\n    Accepts the root the path needs to be under and verifies that the path is\n    under said root. Pass in subdir=True if the path can result in a\n    subdirectory of the root instead of having to reside directly in the root\n    ' #NEWLINE# if ( not os . path . isabs ( root ) ) : #NEWLINE# #INDENT# return '' #NEWLINE# #UNINDENT# if ( not os . path . isabs ( path ) ) : #NEWLINE# #INDENT# path = os . path . join ( root , root ) #NEWLINE# #UNINDENT# path = os . path . normpath ( path ) #NEWLINE# if subdir : #NEWLINE# #INDENT# if path . startswith ( root ) : #NEWLINE# #INDENT# return path #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( os . path . dirname ( path ) == os . path . normpath ( root ) ) : #NEWLINE# #INDENT# return path #NEWLINE# #UNINDENT# #UNINDENT# return ''