Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8335773

Browse files
committed
matplotlib: _is_writable_dir tests with os.access and TemporaryFile.
This fails either if the OS tells us it isn't writable, or if a file cannot be created there.
1 parent 81639a1 commit 8335773

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

lib/matplotlib/__init__.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,24 @@ def _is_writable_dir(p):
217217
p + '' # test is string like
218218
except TypeError:
219219
return False
220-
return os.access(p, os.W_OK) and os.path.isdir(p)
220+
221+
# Test whether the operating system thinks it's a writable directory.
222+
# Note that this check is necessary on Google App Engine, because the
223+
# subsequent check will succeed even though p may not be writable.
224+
if not os.access(p, os.W_OK) or not os.path.isdir(p):
225+
return False
226+
227+
# Also test that it is actually possible to write to a file here.
228+
try:
229+
t = tempfile.TemporaryFile(dir=p)
230+
try:
231+
t.write(ascii('1'))
232+
finally:
233+
t.close()
234+
except OSError:
235+
return False
236+
237+
return True
221238

222239
class Verbose:
223240
"""

0 commit comments

Comments
 (0)