summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2013-12-07 12:28:15 -0500
committerJason R. Coombs <jaraco@jaraco.com>2013-12-07 12:28:15 -0500
commit074fa0ecbe18b9908a29e6a22bfe99b924b3ab98 (patch)
tree6c2d0c9424f89c9c5101ca2c53fc5047b06064fc
parentdb03ee55726794834b414a574ece29efc9bb930e (diff)
downloadpython-setuptools-bitbucket-074fa0ecbe18b9908a29e6a22bfe99b924b3ab98.tar.gz
Add support for exempting a path based on a regular expression.
-rwxr-xr-xsetuptools/sandbox.py14
1 files changed, 12 insertions, 2 deletions
diff --git a/setuptools/sandbox.py b/setuptools/sandbox.py
index 50fb02a3..26960846 100755
--- a/setuptools/sandbox.py
+++ b/setuptools/sandbox.py
@@ -3,6 +3,8 @@ import sys
import tempfile
import operator
import functools
+import itertools
+import re
import pkg_resources
@@ -197,6 +199,9 @@ class DirectorySandbox(AbstractSandbox):
"utime", "lchown", "chroot", "mkfifo", "mknod", "tempnam",
])
+ _exception_patterns = []
+ "allow writing to paths that match the pattern"
+
def __init__(self, sandbox, exceptions=_EXCEPTIONS):
self._sandbox = os.path.normcase(os.path.realpath(sandbox))
self._prefix = os.path.join(self._sandbox,'')
@@ -237,11 +242,16 @@ class DirectorySandbox(AbstractSandbox):
self._active = active
def _exempted(self, filepath):
- exception_matches = (
+ start_matches = (
filepath.startswith(exception)
for exception in self._exceptions
)
- return any(exception_matches)
+ pattern_matches = (
+ re.match(pattern, filepath)
+ for pattern in self._exception_patterns
+ )
+ candidates = itertools.chain(start_matches, pattern_matches)
+ return any(candidates)
def _remap_input(self, operation, path, *args, **kw):
"""Called for path inputs"""