We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
path module overriden by path variable
On

https://github.com/rootpy/rootpy/blob/master/rootpy/io/file.py#L43

the module path is overriden by the variable path.

Locally, pyflakes also  warns me about it:

```
rootpy/rootpy/io $ pyflakes file.py
file.py:255: redefinition of unused 'path' from line 13
file.py:306: redefinition of unused 'path' from line 13
```

Is this something we like to have fixed?


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `rootpy/io/file.py`
Content:
```
1 # Copyright 2012 the rootpy developers
2 # distributed under the terms of the GNU General Public License
3 """
4 This module enhances IO-related ROOT functionality
5 """
6 import ROOT
7 
8 from ..core import Object
9 from ..decorators import snake_case_methods
10 from ..context import preserve_current_directory
11 from .. import asrootpy, QROOT
12 from . import utils, DoesNotExist
13 from ..util import path
14 
15 import tempfile
16 import os
17 import warnings
18 
19 
20 __all__ = [
21     'Directory',
22     'File',
23     'TemporaryFile',
24     'root_open',
25     'open', # deprecated
26 ]
27 
28 
29 VALIDPATH = '^(?P<file>.+.root)(?:[/](?P<path>.+))?$'
30 GLOBALS = {}
31 
32 
33 def wrap_path_handling(f):
34 
35     def get(self, name, rootpy=True, **kwargs):
36 
37         _name = os.path.normpath(name)
38         if _name == '.':
39             return self
40         if _name == '..':
41             return self._parent
42         try:
43             dirpath, _, path = _name.partition(os.path.sep)
44             if path:
45                 if dirpath == '..':
46                     return self._parent.Get(path, rootpy=rootpy, **kwargs)
47                 else:
48                     _dir = f(self, dirpath)
49                     if not isinstance(_dir, _DirectoryBase):
50                         raise DoesNotExist
51                     _dir._parent = self
52                     _dir._path = os.path.join(self._path, dirpath)
53                     thing = _dir.Get(path, rootpy=rootpy, **kwargs)
54             else:
55                 thing = f(self, _name, rootpy=rootpy, **kwargs)
56                 if isinstance(thing, _DirectoryBase):
57                     thing._parent = self
58             if isinstance(thing, _DirectoryBase):
59                 if isinstance(self, File):
60                     thing._path = os.path.normpath(
61                             (':' + os.path.sep).join([self._path, _name]))
62                 else:
63                     thing._path = os.path.normpath(
64                             os.path.join(self._path, _name))
65             return thing
66         except DoesNotExist:
67             raise DoesNotExist("requested path '%s' does not exist in %s" %
68                     (name, self._path))
69     return get
70 
71 
72 class _DirectoryBase(Object):
73 
74     def walk(self, top=None, class_pattern=None):
75         """
76         Calls :func:`rootpy.io.utils.walk`.
77         """
78         return utils.walk(self, top, class_pattern=class_pattern)
79 
80     def __getattr__(self, attr):
81         """
82         Natural naming support. Now you can get an object from a
83         File/Directory with::
84 
85             myfile.somedir.otherdir.histname
86         """
87         # Be careful! If ``__getattr__`` ends up being called again here,
88         # this can end up in an "infinite" recursion and stack overflow.
89 
90         # Directly call ROOT's Get() here since ``attr`` must anyway be a valid
91         # identifier (not a path including subdirectories).
92         thing = super(_DirectoryBase, self).Get(attr)
93         if not thing:
94             raise AttributeError("{0} has no attribute '{1}'".format(self, attr))
95         thing = asrootpy(thing)
96         if isinstance(thing, Directory):
97             thing._path = os.path.join(self._path, thing.GetName())
98             thing._parent = self
99         return thing
100 
101     def __setattr__(self, attr, value):
102 
103         if ('_inited' not in self.__dict__ or
104             attr in self.__dict__ or
105             not isinstance(value, ROOT.TObject)):
106             return super(_DirectoryBase, self).__setattr__(attr, value)
107 
108         self.__setitem__(attr, value)
109 
110     def __getitem__(self, name):
111 
112         return self.Get(name)
113 
114     def __setitem__(self, name, thing):
115         """
116         Allow writing objects in a file with ``myfile['thing'] = myobject``
117         """
118         with preserve_current_directory():
119             self.cd()
120             thing.Write(name)
121 
122     def __iter__(self):
123 
124         return self.walk()
125 
126     def keys(self):
127 
128         return self.GetListOfKeys()
129 
130     def unique_keys(self):
131 
132         keys = {}
133         for key in self.keys():
134             keys[key.GetName()] = key
135         return keys.values()
136 
137     @wrap_path_handling
138     def Get(self, name, rootpy=True, **kwargs):
139         """
140         Return the requested object cast as its corresponding subclass in
141         rootpy if one exists and ``rootpy=True``, otherwise return the
142         unadulterated TObject.
143         """
144         thing = super(_DirectoryBase, self).Get(name)
145         if not thing:
146             raise DoesNotExist
147         if rootpy:
148             return asrootpy(thing, **kwargs)
149         return thing
150 
151     @wrap_path_handling
152     def GetDirectory(self, name, rootpy=True, **kwargs):
153 
154         rdir = super(_DirectoryBase, self).GetDirectory(name)
155         if not rdir:
156             raise DoesNotExist
157         if rootpy:
158             return asrootpy(rdir, **kwargs)
159         return rdir
160 
161 
162 @snake_case_methods
163 class Directory(_DirectoryBase, QROOT.TDirectoryFile):
164     """
165     Inherits from TDirectory
166     """
167     def __init__(self, name, title, *args, **kwargs):
168 
169         super(Directory, self).__init__(name, title, *args, **kwargs)
170         self._post_init()
171 
172     def _post_init(self):
173 
174         self._path = self.GetName()
175         self._parent = ROOT.gDirectory.func()
176         self._inited = True
177 
178     def __str__(self):
179 
180         return "%s('%s')" % (self.__class__.__name__, self._path)
181 
182     def __repr__(self):
183 
184         return self.__str__()
185 
186 
187 @snake_case_methods
188 class File(_DirectoryBase, QROOT.TFile):
189     """
190     Wrapper for TFile that adds various convenience functions.
191 
192     >>> from rootpy.test import filename
193     >>> f = File(filename, 'read')
194 
195     """
196     def __init__(self, name, *args, **kwargs):
197 
198         # trigger finalSetup
199         ROOT.kTRUE
200         super(File, self).__init__(name, *args, **kwargs)
201         self._path = self.GetName()
202         self._parent = self
203         self._inited = True
204 
205     def __enter__(self):
206 
207         return self
208 
209     def __exit__(self, type, value, traceback):
210 
211         self.Close()
212         return False
213 
214     def __str__(self):
215 
216         return "%s('%s')" % (self.__class__.__name__, self._path)
217 
218     def __repr__(self):
219 
220         return self.__str__()
221 
222 
223 @snake_case_methods
224 class TemporaryFile(File, QROOT.TFile):
225     """
226     A temporary ROOT file that is automatically deleted when closed.
227     Uses Python's :func:`tempfile.mkstemp` to obtain a temporary file
228     in the most secure manner possible.
229 
230     Keyword arguments are passed directly to :func:`tempfile.mkstemp`
231     """
232     def __init__(self, suffix='.root', **kwargs):
233 
234         self.__fd, self.__tmp_path = tempfile.mkstemp(suffix=suffix, **kwargs)
235         super(TemporaryFile, self).__init__(self.__tmp_path, 'recreate')
236 
237     def Close(self):
238 
239         super(TemporaryFile, self).Close()
240         os.close(self.__fd)
241         os.remove(self.__tmp_path)
242 
243     def __exit__(self, type, value, traceback):
244 
245         self.Close()
246         return False
247 
248 
249 def root_open(filename, mode=""):
250 
251     filename = path.expand(filename)
252     root_file = ROOT.TFile.Open(filename, mode)
253     # fix evil segfault after attempt to open bad file in 5.30
254     # this fix is not needed in 5.32
255     # GetListOfClosedObjects() does not appear until 5.30
256     if ROOT.gROOT.GetVersionInt() >= 53000:
257         GLOBALS['CLOSEDOBJECTS'] = ROOT.gROOT.GetListOfClosedObjects()
258     if not root_file:
259         raise IOError("Could not open file: '%s'" % filename)
260     root_file.__class__ = File
261     root_file._path = filename
262     root_file._parent = root_file
263     root_file._inited = True
264     return root_file
265 
266 
267 def open(filename, mode=""):
268 
269     warnings.warn("Use root_open instead; open is deprecated.",
270                   DeprecationWarning)
271     return root_open(filename, mode)
272
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/rootpy/io/file.py b/rootpy/io/file.py
--- a/rootpy/io/file.py
+++ b/rootpy/io/file.py
@@ -10,7 +10,7 @@
 from ..context import preserve_current_directory
 from .. import asrootpy, QROOT
 from . import utils, DoesNotExist
-from ..util import path
+from ..util.path import expand as expand_path
 
 import tempfile
 import os
@@ -248,7 +248,7 @@
 
 def root_open(filename, mode=""):
 
-    filename = path.expand(filename)
+    filename = expand_path(filename)
     root_file = ROOT.TFile.Open(filename, mode)
     # fix evil segfault after attempt to open bad file in 5.30
     # this fix is not needed in 5.32

{"golden_diff": "diff --git a/rootpy/io/file.py b/rootpy/io/file.py\n--- a/rootpy/io/file.py\n+++ b/rootpy/io/file.py\n@@ -10,7 +10,7 @@\n from ..context import preserve_current_directory\n from .. import asrootpy, QROOT\n from . import utils, DoesNotExist\n-from ..util import path\n+from ..util.path import expand as expand_path\n \n import tempfile\n import os\n@@ -248,7 +248,7 @@\n \n def root_open(filename, mode=\"\"):\n \n-    filename = path.expand(filename)\n+    filename = expand_path(filename)\n     root_file = ROOT.TFile.Open(filename, mode)\n     # fix evil segfault after attempt to open bad file in 5.30\n     # this fix is not needed in 5.32\n", "issue": "path module overriden by path variable\nOn\n\nhttps://github.com/rootpy/rootpy/blob/master/rootpy/io/file.py#L43\n\nthe module path is overriden by the variable path.\n\nLocally, pyflakes also  warns me about it:\n\n```\nrootpy/rootpy/io $ pyflakes file.py\nfile.py:255: redefinition of unused 'path' from line 13\nfile.py:306: redefinition of unused 'path' from line 13\n```\n\nIs this something we like to have fixed?\n\n", "before_files": [{"content": "# Copyright 2012 the rootpy developers\n# distributed under the terms of the GNU General Public License\n\"\"\"\nThis module enhances IO-related ROOT functionality\n\"\"\"\nimport ROOT\n\nfrom ..core import Object\nfrom ..decorators import snake_case_methods\nfrom ..context import preserve_current_directory\nfrom .. import asrootpy, QROOT\nfrom . import utils, DoesNotExist\nfrom ..util import path\n\nimport tempfile\nimport os\nimport warnings\n\n\n__all__ = [\n    'Directory',\n    'File',\n    'TemporaryFile',\n    'root_open',\n    'open', # deprecated\n]\n\n\nVALIDPATH = '^(?P<file>.+.root)(?:[/](?P<path>.+))?$'\nGLOBALS = {}\n\n\ndef wrap_path_handling(f):\n\n    def get(self, name, rootpy=True, **kwargs):\n\n        _name = os.path.normpath(name)\n        if _name == '.':\n            return self\n        if _name == '..':\n            return self._parent\n        try:\n            dirpath, _, path = _name.partition(os.path.sep)\n            if path:\n                if dirpath == '..':\n                    return self._parent.Get(path, rootpy=rootpy, **kwargs)\n                else:\n                    _dir = f(self, dirpath)\n                    if not isinstance(_dir, _DirectoryBase):\n                        raise DoesNotExist\n                    _dir._parent = self\n                    _dir._path = os.path.join(self._path, dirpath)\n                    thing = _dir.Get(path, rootpy=rootpy, **kwargs)\n            else:\n                thing = f(self, _name, rootpy=rootpy, **kwargs)\n                if isinstance(thing, _DirectoryBase):\n                    thing._parent = self\n            if isinstance(thing, _DirectoryBase):\n                if isinstance(self, File):\n                    thing._path = os.path.normpath(\n                            (':' + os.path.sep).join([self._path, _name]))\n                else:\n                    thing._path = os.path.normpath(\n                            os.path.join(self._path, _name))\n            return thing\n        except DoesNotExist:\n            raise DoesNotExist(\"requested path '%s' does not exist in %s\" %\n                    (name, self._path))\n    return get\n\n\nclass _DirectoryBase(Object):\n\n    def walk(self, top=None, class_pattern=None):\n        \"\"\"\n        Calls :func:`rootpy.io.utils.walk`.\n        \"\"\"\n        return utils.walk(self, top, class_pattern=class_pattern)\n\n    def __getattr__(self, attr):\n        \"\"\"\n        Natural naming support. Now you can get an object from a\n        File/Directory with::\n\n            myfile.somedir.otherdir.histname\n        \"\"\"\n        # Be careful! If ``__getattr__`` ends up being called again here,\n        # this can end up in an \"infinite\" recursion and stack overflow.\n\n        # Directly call ROOT's Get() here since ``attr`` must anyway be a valid\n        # identifier (not a path including subdirectories).\n        thing = super(_DirectoryBase, self).Get(attr)\n        if not thing:\n            raise AttributeError(\"{0} has no attribute '{1}'\".format(self, attr))\n        thing = asrootpy(thing)\n        if isinstance(thing, Directory):\n            thing._path = os.path.join(self._path, thing.GetName())\n            thing._parent = self\n        return thing\n\n    def __setattr__(self, attr, value):\n\n        if ('_inited' not in self.__dict__ or\n            attr in self.__dict__ or\n            not isinstance(value, ROOT.TObject)):\n            return super(_DirectoryBase, self).__setattr__(attr, value)\n\n        self.__setitem__(attr, value)\n\n    def __getitem__(self, name):\n\n        return self.Get(name)\n\n    def __setitem__(self, name, thing):\n        \"\"\"\n        Allow writing objects in a file with ``myfile['thing'] = myobject``\n        \"\"\"\n        with preserve_current_directory():\n            self.cd()\n            thing.Write(name)\n\n    def __iter__(self):\n\n        return self.walk()\n\n    def keys(self):\n\n        return self.GetListOfKeys()\n\n    def unique_keys(self):\n\n        keys = {}\n        for key in self.keys():\n            keys[key.GetName()] = key\n        return keys.values()\n\n    @wrap_path_handling\n    def Get(self, name, rootpy=True, **kwargs):\n        \"\"\"\n        Return the requested object cast as its corresponding subclass in\n        rootpy if one exists and ``rootpy=True``, otherwise return the\n        unadulterated TObject.\n        \"\"\"\n        thing = super(_DirectoryBase, self).Get(name)\n        if not thing:\n            raise DoesNotExist\n        if rootpy:\n            return asrootpy(thing, **kwargs)\n        return thing\n\n    @wrap_path_handling\n    def GetDirectory(self, name, rootpy=True, **kwargs):\n\n        rdir = super(_DirectoryBase, self).GetDirectory(name)\n        if not rdir:\n            raise DoesNotExist\n        if rootpy:\n            return asrootpy(rdir, **kwargs)\n        return rdir\n\n\n@snake_case_methods\nclass Directory(_DirectoryBase, QROOT.TDirectoryFile):\n    \"\"\"\n    Inherits from TDirectory\n    \"\"\"\n    def __init__(self, name, title, *args, **kwargs):\n\n        super(Directory, self).__init__(name, title, *args, **kwargs)\n        self._post_init()\n\n    def _post_init(self):\n\n        self._path = self.GetName()\n        self._parent = ROOT.gDirectory.func()\n        self._inited = True\n\n    def __str__(self):\n\n        return \"%s('%s')\" % (self.__class__.__name__, self._path)\n\n    def __repr__(self):\n\n        return self.__str__()\n\n\n@snake_case_methods\nclass File(_DirectoryBase, QROOT.TFile):\n    \"\"\"\n    Wrapper for TFile that adds various convenience functions.\n\n    >>> from rootpy.test import filename\n    >>> f = File(filename, 'read')\n\n    \"\"\"\n    def __init__(self, name, *args, **kwargs):\n\n        # trigger finalSetup\n        ROOT.kTRUE\n        super(File, self).__init__(name, *args, **kwargs)\n        self._path = self.GetName()\n        self._parent = self\n        self._inited = True\n\n    def __enter__(self):\n\n        return self\n\n    def __exit__(self, type, value, traceback):\n\n        self.Close()\n        return False\n\n    def __str__(self):\n\n        return \"%s('%s')\" % (self.__class__.__name__, self._path)\n\n    def __repr__(self):\n\n        return self.__str__()\n\n\n@snake_case_methods\nclass TemporaryFile(File, QROOT.TFile):\n    \"\"\"\n    A temporary ROOT file that is automatically deleted when closed.\n    Uses Python's :func:`tempfile.mkstemp` to obtain a temporary file\n    in the most secure manner possible.\n\n    Keyword arguments are passed directly to :func:`tempfile.mkstemp`\n    \"\"\"\n    def __init__(self, suffix='.root', **kwargs):\n\n        self.__fd, self.__tmp_path = tempfile.mkstemp(suffix=suffix, **kwargs)\n        super(TemporaryFile, self).__init__(self.__tmp_path, 'recreate')\n\n    def Close(self):\n\n        super(TemporaryFile, self).Close()\n        os.close(self.__fd)\n        os.remove(self.__tmp_path)\n\n    def __exit__(self, type, value, traceback):\n\n        self.Close()\n        return False\n\n\ndef root_open(filename, mode=\"\"):\n\n    filename = path.expand(filename)\n    root_file = ROOT.TFile.Open(filename, mode)\n    # fix evil segfault after attempt to open bad file in 5.30\n    # this fix is not needed in 5.32\n    # GetListOfClosedObjects() does not appear until 5.30\n    if ROOT.gROOT.GetVersionInt() >= 53000:\n        GLOBALS['CLOSEDOBJECTS'] = ROOT.gROOT.GetListOfClosedObjects()\n    if not root_file:\n        raise IOError(\"Could not open file: '%s'\" % filename)\n    root_file.__class__ = File\n    root_file._path = filename\n    root_file._parent = root_file\n    root_file._inited = True\n    return root_file\n\n\ndef open(filename, mode=\"\"):\n\n    warnings.warn(\"Use root_open instead; open is deprecated.\",\n                  DeprecationWarning)\n    return root_open(filename, mode)\n", "path": "rootpy/io/file.py"}], "after_files": [{"content": "# Copyright 2012 the rootpy developers\n# distributed under the terms of the GNU General Public License\n\"\"\"\nThis module enhances IO-related ROOT functionality\n\"\"\"\nimport ROOT\n\nfrom ..core import Object\nfrom ..decorators import snake_case_methods\nfrom ..context import preserve_current_directory\nfrom .. import asrootpy, QROOT\nfrom . import utils, DoesNotExist\nfrom ..util.path import expand as expand_path\n\nimport tempfile\nimport os\nimport warnings\n\n\n__all__ = [\n    'Directory',\n    'File',\n    'TemporaryFile',\n    'root_open',\n    'open', # deprecated\n]\n\n\nVALIDPATH = '^(?P<file>.+.root)(?:[/](?P<path>.+))?$'\nGLOBALS = {}\n\n\ndef wrap_path_handling(f):\n\n    def get(self, name, rootpy=True, **kwargs):\n\n        _name = os.path.normpath(name)\n        if _name == '.':\n            return self\n        if _name == '..':\n            return self._parent\n        try:\n            dirpath, _, path = _name.partition(os.path.sep)\n            if path:\n                if dirpath == '..':\n                    return self._parent.Get(path, rootpy=rootpy, **kwargs)\n                else:\n                    _dir = f(self, dirpath)\n                    if not isinstance(_dir, _DirectoryBase):\n                        raise DoesNotExist\n                    _dir._parent = self\n                    _dir._path = os.path.join(self._path, dirpath)\n                    thing = _dir.Get(path, rootpy=rootpy, **kwargs)\n            else:\n                thing = f(self, _name, rootpy=rootpy, **kwargs)\n                if isinstance(thing, _DirectoryBase):\n                    thing._parent = self\n            if isinstance(thing, _DirectoryBase):\n                if isinstance(self, File):\n                    thing._path = os.path.normpath(\n                            (':' + os.path.sep).join([self._path, _name]))\n                else:\n                    thing._path = os.path.normpath(\n                            os.path.join(self._path, _name))\n            return thing\n        except DoesNotExist:\n            raise DoesNotExist(\"requested path '%s' does not exist in %s\" %\n                    (name, self._path))\n    return get\n\n\nclass _DirectoryBase(Object):\n\n    def walk(self, top=None, class_pattern=None):\n        \"\"\"\n        Calls :func:`rootpy.io.utils.walk`.\n        \"\"\"\n        return utils.walk(self, top, class_pattern=class_pattern)\n\n    def __getattr__(self, attr):\n        \"\"\"\n        Natural naming support. Now you can get an object from a\n        File/Directory with::\n\n            myfile.somedir.otherdir.histname\n        \"\"\"\n        # Be careful! If ``__getattr__`` ends up being called again here,\n        # this can end up in an \"infinite\" recursion and stack overflow.\n\n        # Directly call ROOT's Get() here since ``attr`` must anyway be a valid\n        # identifier (not a path including subdirectories).\n        thing = super(_DirectoryBase, self).Get(attr)\n        if not thing:\n            raise AttributeError(\"{0} has no attribute '{1}'\".format(self, attr))\n        thing = asrootpy(thing)\n        if isinstance(thing, Directory):\n            thing._path = os.path.join(self._path, thing.GetName())\n            thing._parent = self\n        return thing\n\n    def __setattr__(self, attr, value):\n\n        if ('_inited' not in self.__dict__ or\n            attr in self.__dict__ or\n            not isinstance(value, ROOT.TObject)):\n            return super(_DirectoryBase, self).__setattr__(attr, value)\n\n        self.__setitem__(attr, value)\n\n    def __getitem__(self, name):\n\n        return self.Get(name)\n\n    def __setitem__(self, name, thing):\n        \"\"\"\n        Allow writing objects in a file with ``myfile['thing'] = myobject``\n        \"\"\"\n        with preserve_current_directory():\n            self.cd()\n            thing.Write(name)\n\n    def __iter__(self):\n\n        return self.walk()\n\n    def keys(self):\n\n        return self.GetListOfKeys()\n\n    def unique_keys(self):\n\n        keys = {}\n        for key in self.keys():\n            keys[key.GetName()] = key\n        return keys.values()\n\n    @wrap_path_handling\n    def Get(self, name, rootpy=True, **kwargs):\n        \"\"\"\n        Return the requested object cast as its corresponding subclass in\n        rootpy if one exists and ``rootpy=True``, otherwise return the\n        unadulterated TObject.\n        \"\"\"\n        thing = super(_DirectoryBase, self).Get(name)\n        if not thing:\n            raise DoesNotExist\n        if rootpy:\n            return asrootpy(thing, **kwargs)\n        return thing\n\n    @wrap_path_handling\n    def GetDirectory(self, name, rootpy=True, **kwargs):\n\n        rdir = super(_DirectoryBase, self).GetDirectory(name)\n        if not rdir:\n            raise DoesNotExist\n        if rootpy:\n            return asrootpy(rdir, **kwargs)\n        return rdir\n\n\n@snake_case_methods\nclass Directory(_DirectoryBase, QROOT.TDirectoryFile):\n    \"\"\"\n    Inherits from TDirectory\n    \"\"\"\n    def __init__(self, name, title, *args, **kwargs):\n\n        super(Directory, self).__init__(name, title, *args, **kwargs)\n        self._post_init()\n\n    def _post_init(self):\n\n        self._path = self.GetName()\n        self._parent = ROOT.gDirectory.func()\n        self._inited = True\n\n    def __str__(self):\n\n        return \"%s('%s')\" % (self.__class__.__name__, self._path)\n\n    def __repr__(self):\n\n        return self.__str__()\n\n\n@snake_case_methods\nclass File(_DirectoryBase, QROOT.TFile):\n    \"\"\"\n    Wrapper for TFile that adds various convenience functions.\n\n    >>> from rootpy.test import filename\n    >>> f = File(filename, 'read')\n\n    \"\"\"\n    def __init__(self, name, *args, **kwargs):\n\n        # trigger finalSetup\n        ROOT.kTRUE\n        super(File, self).__init__(name, *args, **kwargs)\n        self._path = self.GetName()\n        self._parent = self\n        self._inited = True\n\n    def __enter__(self):\n\n        return self\n\n    def __exit__(self, type, value, traceback):\n\n        self.Close()\n        return False\n\n    def __str__(self):\n\n        return \"%s('%s')\" % (self.__class__.__name__, self._path)\n\n    def __repr__(self):\n\n        return self.__str__()\n\n\n@snake_case_methods\nclass TemporaryFile(File, QROOT.TFile):\n    \"\"\"\n    A temporary ROOT file that is automatically deleted when closed.\n    Uses Python's :func:`tempfile.mkstemp` to obtain a temporary file\n    in the most secure manner possible.\n\n    Keyword arguments are passed directly to :func:`tempfile.mkstemp`\n    \"\"\"\n    def __init__(self, suffix='.root', **kwargs):\n\n        self.__fd, self.__tmp_path = tempfile.mkstemp(suffix=suffix, **kwargs)\n        super(TemporaryFile, self).__init__(self.__tmp_path, 'recreate')\n\n    def Close(self):\n\n        super(TemporaryFile, self).Close()\n        os.close(self.__fd)\n        os.remove(self.__tmp_path)\n\n    def __exit__(self, type, value, traceback):\n\n        self.Close()\n        return False\n\n\ndef root_open(filename, mode=\"\"):\n\n    filename = expand_path(filename)\n    root_file = ROOT.TFile.Open(filename, mode)\n    # fix evil segfault after attempt to open bad file in 5.30\n    # this fix is not needed in 5.32\n    # GetListOfClosedObjects() does not appear until 5.30\n    if ROOT.gROOT.GetVersionInt() >= 53000:\n        GLOBALS['CLOSEDOBJECTS'] = ROOT.gROOT.GetListOfClosedObjects()\n    if not root_file:\n        raise IOError(\"Could not open file: '%s'\" % filename)\n    root_file.__class__ = File\n    root_file._path = filename\n    root_file._parent = root_file\n    root_file._inited = True\n    return root_file\n\n\ndef open(filename, mode=\"\"):\n\n    warnings.warn(\"Use root_open instead; open is deprecated.\",\n                  DeprecationWarning)\n    return root_open(filename, mode)\n", "path": "rootpy/io/file.py"}]}