#NEWLINE# def fopen( * args , **kwargs ) : #NEWLINE# #INDENT# '\n    Wrapper around open() built-in to set CLOEXEC on the fd.\n\n    This flag specifies that the file descriptor should be closed when an exec\n    function is invoked;\n    When a file descriptor is allocated (as with open or dup), this bit is\n    initially cleared on the new file descriptor, meaning that descriptor will\n    survive into the new program after exec.\n\n    NB! We still have small race condition between open and fcntl.\n\n    ' #NEWLINE# if ( ( six . PY2 and is_windows ( ) and ( 'binary' not in kwargs ) ) or kwargs . pop ( 'binary' , False ) ) : #NEWLINE# #INDENT# if ( len ( args ) > 1 ) : #NEWLINE# #INDENT# args = list ( args ) #NEWLINE# if ( 'b' not in args [ 1 ] ) : #NEWLINE# #INDENT# args [ 1 ] += 'b' #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if kwargs . get ( 'mode' , None ) : #NEWLINE# #INDENT# if ( 'b' not in kwargs [ 'mode' ] ) : #NEWLINE# #INDENT# kwargs [ 'mode' ] += 'b' #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# kwargs [ 'mode' ] = 'rb' #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( six . PY3 and ( 'encoding' not in kwargs ) ) : #NEWLINE# #INDENT# binary = False #NEWLINE# if ( len ( old_flags ) > 1 ) : #NEWLINE# #INDENT# args = list ( args ) #NEWLINE# if ( 'b' in args [ 1 ] ) : #NEWLINE# #INDENT# binary = True #NEWLINE# #UNINDENT# #UNINDENT# if kwargs . get ( 'mode' , None ) : #NEWLINE# #INDENT# if ( 'b' in kwargs [ 'mode' ] ) : #NEWLINE# #INDENT# binary = True #NEWLINE# #UNINDENT# #UNINDENT# if ( not binary ) : #NEWLINE# #INDENT# kwargs [ 'encoding' ] = 'utf-8' #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# fhandle = open ( * args , ** kwargs ) #NEWLINE# if is_fcntl_available ( ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# FD_CLOEXEC = fcntl . FD_CLOEXEC #NEWLINE# #UNINDENT# except AttributeError : #NEWLINE# #INDENT# FD_CLOEXEC = 1 #NEWLINE# #UNINDENT# old_flags = fcntl . fcntl ( fhandle . fileno ( ) , fcntl . F_GETFD ) #NEWLINE# fcntl . fcntl ( fhandle . fileno ( ) , fcntl . F_SETFD , ( old_flags | FD_CLOEXEC ) ) #NEWLINE# #UNINDENT# return fhandle