Commit ef565f9d authored by Jason R. Coombs's avatar Jason R. Coombs

Add support for exempting a path based on a regular expression.

--HG--
extra : histedit_source : 2f1f4146ec1d5196cb65602302185a12060cfa17
parent 3915375e
...@@ -3,6 +3,8 @@ import sys ...@@ -3,6 +3,8 @@ import sys
import tempfile import tempfile
import operator import operator
import functools import functools
import itertools
import re
import pkg_resources import pkg_resources
...@@ -197,6 +199,9 @@ class DirectorySandbox(AbstractSandbox): ...@@ -197,6 +199,9 @@ class DirectorySandbox(AbstractSandbox):
"utime", "lchown", "chroot", "mkfifo", "mknod", "tempnam", "utime", "lchown", "chroot", "mkfifo", "mknod", "tempnam",
]) ])
_exception_patterns = []
"allow writing to paths that match the pattern"
def __init__(self, sandbox, exceptions=_EXCEPTIONS): def __init__(self, sandbox, exceptions=_EXCEPTIONS):
self._sandbox = os.path.normcase(os.path.realpath(sandbox)) self._sandbox = os.path.normcase(os.path.realpath(sandbox))
self._prefix = os.path.join(self._sandbox,'') self._prefix = os.path.join(self._sandbox,'')
...@@ -237,11 +242,16 @@ class DirectorySandbox(AbstractSandbox): ...@@ -237,11 +242,16 @@ class DirectorySandbox(AbstractSandbox):
self._active = active self._active = active
def _exempted(self, filepath): def _exempted(self, filepath):
exception_matches = ( start_matches = (
filepath.startswith(exception) filepath.startswith(exception)
for exception in self._exceptions 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): def _remap_input(self, operation, path, *args, **kw):
"""Called for path inputs""" """Called for path inputs"""
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment