Allow mode='x' even for Python < 3.3

The built-in open() function isn't used anymore.
The function os.path.isfile() is used to check if a file exists already.
For mode 'w+', an existing file is first opened in write-only mode to
make sure it is truncated. Afterwards it is re-opened in read/write
mode.