new openfile method, it's suitable for running test with StringIO