MCPcopy Index your code
hub / github.com/aws/aws-cli / temporary_file

Function temporary_file

awscli/testutils.py:154–173  ·  view source on GitHub ↗

This is a cross platform temporary file creation. tempfile.NamedTemporary file on windows creates a secure temp file that can't be read by other processes and can't be opened a second time. For tests, we generally *want* them to be read multiple times. The test fixture writes the t

(mode)

Source from the content-addressed store, hash-verified

152
153@contextlib.contextmanager
154def temporary_file(mode):
155 """This is a cross platform temporary file creation.
156
157 tempfile.NamedTemporary file on windows creates a secure temp file
158 that can't be read by other processes and can't be opened a second time.
159
160 For tests, we generally *want* them to be read multiple times.
161 The test fixture writes the temp file contents, the test reads the
162 temp file.
163
164 """
165 temporary_directory = tempfile.mkdtemp()
166 basename = 'tmpfile-%s' % str(random_chars(8))
167 full_filename = os.path.join(temporary_directory, basename)
168 open(full_filename, 'w').close()
169 try:
170 with open(full_filename, mode) as f:
171 yield f
172 finally:
173 shutil.rmtree(temporary_directory)
174
175
176def create_bucket(session, name=None, region=None):

Calls 3

random_charsFunction · 0.70
closeMethod · 0.45
rmtreeMethod · 0.45

Tested by

no test coverage detected