Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | Static Private Attributes
tempfile.TemporaryDirectory Class Reference
Inheritance diagram for tempfile.TemporaryDirectory:
Inheritance graph
[legend]
Collaboration diagram for tempfile.TemporaryDirectory:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def __repr__
def __enter__
def cleanup
def __exit__
def __del__

Public Attributes

 name
_PyObject_HEAD_EXTRA Py_ssize_t ob_refcnt
struct _typeobjectob_type

Private Member Functions

def _rmtree

Private Attributes

 _closed

Static Private Attributes

tuple _listdir = staticmethod(_os.listdir)
tuple _path_join = staticmethod(_os.path.join)
tuple _isdir = staticmethod(_os.path.isdir)
tuple _islink = staticmethod(_os.path.islink)
tuple _remove = staticmethod(_os.remove)
tuple _rmdir = staticmethod(_os.rmdir)
 _os_error = _os.error
 _warn = _warnings.warn

Detailed Description

Create and return a temporary directory.  This has the same
behavior as mkdtemp but can be used as a context manager.  For
example:

    with TemporaryDirectory() as tmpdir:
        ...

Upon exiting the context, the directory and everthing contained
in it are removed.

Definition at line 609 of file tempfile.py.


Constructor & Destructor Documentation

def tempfile.TemporaryDirectory.__init__ (   self,
  suffix = "",
  prefix = template,
  dir = None 
)

Definition at line 621 of file tempfile.py.

00621 
00622     def __init__(self, suffix="", prefix=template, dir=None):
00623         self._closed = False
00624         self.name = None # Handle mkdtemp throwing an exception
00625         self.name = mkdtemp(suffix, prefix, dir)

Here is the caller graph for this function:

Definition at line 653 of file tempfile.py.

00653 
00654     def __del__(self):
00655         # Issue a ResourceWarning if implicit cleanup needed
00656         self.cleanup(_warn=True)

Here is the call graph for this function:


Member Function Documentation

Definition at line 629 of file tempfile.py.

00629 
00630     def __enter__(self):
00631         return self.name

def tempfile.TemporaryDirectory.__exit__ (   self,
  exc,
  value,
  tb 
)

Definition at line 650 of file tempfile.py.

00650 
00651     def __exit__(self, exc, value, tb):
00652         self.cleanup()

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 626 of file tempfile.py.

00626 
00627     def __repr__(self):
00628         return "<{} {!r}>".format(self.__class__.__name__, self.name)

def tempfile.TemporaryDirectory._rmtree (   self,
  path 
) [private]

Definition at line 670 of file tempfile.py.

00670 
00671     def _rmtree(self, path):
00672         # Essentially a stripped down version of shutil.rmtree.  We can't
00673         # use globals because they may be None'ed out at shutdown.
00674         for name in self._listdir(path):
00675             fullname = self._path_join(path, name)
00676             try:
00677                 isdir = self._isdir(fullname) and not self._islink(fullname)
00678             except self._os_error:
00679                 isdir = False
00680             if isdir:
00681                 self._rmtree(fullname)
00682             else:
00683                 try:
00684                     self._remove(fullname)
00685                 except self._os_error:
00686                     pass
00687         try:
00688             self._rmdir(path)
00689         except self._os_error:
00690             pass

Here is the call graph for this function:

Here is the caller graph for this function:

def tempfile.TemporaryDirectory.cleanup (   self,
  _warn = False 
)

Definition at line 632 of file tempfile.py.

00632 
00633     def cleanup(self, _warn=False):
00634         if self.name and not self._closed:
00635             try:
00636                 self._rmtree(self.name)
00637             except (TypeError, AttributeError) as ex:
00638                 # Issue #10188: Emit a warning on stderr
00639                 # if the directory could not be cleaned
00640                 # up due to missing globals
00641                 if "None" not in str(ex):
00642                     raise
00643                 print("ERROR: {!r} while cleaning up {!r}".format(ex, self,),
00644                       file=_sys.stderr)
00645                 return
00646             self._closed = True
00647             if _warn:
00648                 self._warn("Implicitly cleaning up {!r}".format(self),
00649                            ResourceWarning)

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 622 of file tempfile.py.

Definition at line 663 of file tempfile.py.

tuple tempfile.TemporaryDirectory._islink = staticmethod(_os.path.islink) [static, private]

Definition at line 664 of file tempfile.py.

tuple tempfile.TemporaryDirectory._listdir = staticmethod(_os.listdir) [static, private]

Definition at line 661 of file tempfile.py.

Definition at line 667 of file tempfile.py.

Definition at line 662 of file tempfile.py.

tuple tempfile.TemporaryDirectory._remove = staticmethod(_os.remove) [static, private]

Definition at line 665 of file tempfile.py.

Definition at line 666 of file tempfile.py.

tempfile.TemporaryDirectory._warn = _warnings.warn [static, private]

Definition at line 668 of file tempfile.py.

Definition at line 623 of file tempfile.py.

Definition at line 107 of file object.h.

struct _typeobject* _object::ob_type [inherited]

Definition at line 108 of file object.h.


The documentation for this class was generated from the following file: