#NEWLINE# def test_writable_dir( path ) : #NEWLINE# #INDENT# 'Check if a directory is writable.\n\n    Uses os.access() on POSIX, tries creating files on Windows.\n    ' #NEWLINE# if ( os . name == 'posix' ) : #NEWLINE# #INDENT# return os . access ( path , os . W_OK ) #NEWLINE# #UNINDENT# basename = 'accesstest_deleteme_fishfingers_custard_' #NEWLINE# alphabet = 'abcdefghijklmnopqrstuvwxyz0123456789' #NEWLINE# for i in range ( 10 ) : #NEWLINE# #INDENT# name = ( basename + '' . join ( ( random . choice ( alphabet ) for _ in range ( 6 ) ) ) ) #NEWLINE# file = os . path . join ( path , name ) #NEWLINE# try : #NEWLINE# #INDENT# with open ( file , mode = 'xb' ) : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# #UNINDENT# except FileExistsError : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# except PermissionError : #NEWLINE# #INDENT# return False #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# os . unlink ( file ) #NEWLINE# return True #NEWLINE# #UNINDENT# #UNINDENT# msg = 'Unexpected condition testing for writable directory {!r}. Please open an issue on flit to debug why this occurred.' #NEWLINE# raise EnvironmentError ( msg . format ( path ) )