)]}'
{"tooz/drivers/file.py":[{"author":{"_account_id":1297,"name":"Joshua Harlow","email":"jxharlow@godaddy.com","username":"harlowja"},"change_message_id":"3c43f79bc08538be2fcae5219f70ee5bd255d43c","unresolved":false,"context_lines":[{"line_number":270,"context_line":"        }"},{"line_number":271,"context_line":"        details[u\u0027encoded\u0027] \u003d details[u\"group_id\"] !\u003d group_id"},{"line_number":272,"context_line":"        details_blob \u003d utils.dumps(details)"},{"line_number":273,"context_line":"        fd, name \u003d tempfile.mkstemp(\"tooz\", dir\u003dself._tmpdir)"},{"line_number":274,"context_line":"        with os.fdopen(fd, \"wb\") as fh:"},{"line_number":275,"context_line":"            fh.write(details_blob)"},{"line_number":276,"context_line":"        os.rename(name, path)"}],"source_content_type":"text/x-python","patch_set":2,"id":"bacf61ea_fdb356e7","line":273,"updated":"2016-07-29 00:00:05.000000000","message":"The following should handle write failing better (and not leaving a tempfile around if fdopen or rename borks).\n\n    import contextlib\n    import os\n\n    import tempfile\n\n\n    class MoveableTemporaryFile(object):\n        def __init__(self, *args, **kwargs):\n            self.path \u003d None\n            self.descriptor \u003d -1\n            self.destroy \u003d True\n            self._args \u003d args\n            self._kwargs \u003d kwargs\n\n        def __enter__(self):\n            self.descriptor, self.path \u003d tempfile.mkstemp(*self._args,\n                                                          **self._kwargs)\n            return self\n\n        @contextlib.contextmanager\n        def open(self, mode):\n            with os.fdopen(self.descriptor, mode) as fh:\n                yield fh\n\n        def move(self, to_path):\n            os.rename(self.path, to_path)\n            self.destroy \u003d False\n            self.path \u003d to_path\n\n        def __exit__(self, exception_type, exception_value, traceback):\n            if self.destroy and self.path is not None:\n                os.unlink(self.path)","commit_id":"ded3cbcaf40326925a88a074f91789500410b9ab"}]}
