Python 3 support: use set operators to filter string contents

This commit is contained in:
Kamil Cholewiński 2015-04-10 12:15:58 +02:00
parent 758899440a
commit de4ae07a4f
1 changed files with 3 additions and 2 deletions

View File

@ -80,6 +80,7 @@ class FilePerms(object):
# TODO: consider more than the lower 9 bits
class _FilePermProperty(object):
_perm_chars = 'rwx'
_perm_set = frozenset('rwx')
_perm_val = {'r': 4, 'w': 2, 'x': 1} # for sorting
def __init__(self, attribute, offset):
@ -96,8 +97,8 @@ class FilePerms(object):
if cur == value:
return
try:
invalid_chars = str(value).translate(None, self._perm_chars)
except (TypeError, UnicodeEncodeError):
invalid_chars = set(str(value)) - self._perm_set
except TypeError:
raise TypeError('expected string, not %r' % value)
if invalid_chars:
raise ValueError('got invalid chars %r in permission'