1 | # override tempfile methods for debugging |
---|
2 | |
---|
3 | import tempfile, traceback |
---|
4 | |
---|
5 | import logging |
---|
6 | log = logging.getLogger( __name__ ) |
---|
7 | |
---|
8 | class TempFile( object ): |
---|
9 | def __init__( self ): |
---|
10 | tempfile._NamedTemporaryFile = tempfile.NamedTemporaryFile |
---|
11 | tempfile._mkstemp = tempfile.mkstemp |
---|
12 | tempfile.NamedTemporaryFile = self.NamedTemporaryFile |
---|
13 | tempfile.mkstemp = self.mkstemp |
---|
14 | def NamedTemporaryFile( self, *args, **kwargs ): |
---|
15 | f = tempfile._NamedTemporaryFile( *args, **kwargs ) |
---|
16 | try: |
---|
17 | log.debug( ( "Opened tempfile %s with NamedTemporaryFile:\n" % f.name ) + "".join( traceback.format_stack() ) ) |
---|
18 | except AttributeError: |
---|
19 | pass |
---|
20 | return f |
---|
21 | def mkstemp( self, *args, **kwargs ): |
---|
22 | f = tempfile._mkstemp( *args, **kwargs ) |
---|
23 | try: |
---|
24 | log.debug( ( "Opened tempfile %s with mkstemp:\n" % f[1] ) + "".join( traceback.format_stack() ) ) |
---|
25 | except TypeError: |
---|
26 | pass |
---|
27 | return f |
---|