diff --git a/ansible_mitogen/helpers.py b/ansible_mitogen/helpers.py index a4ba59f6..b1dcfe8f 100644 --- a/ansible_mitogen/helpers.py +++ b/ansible_mitogen/helpers.py @@ -190,9 +190,6 @@ CHMOD_BITS = { } } -def or_(it): - return reduce(operator.or_, it, 0) - def apply_mode_spec(spec, mode): for clause in spec.split(','): @@ -202,7 +199,7 @@ def apply_mode_spec(spec, mode): mask = CHMOD_MASKS[ch] bits = CHMOD_BITS[ch] cur_perm_bits = mode & mask - new_perm_bits = or_(bits[p] for p in perms) + new_perm_bits = reduce(operator.or_, (bits[p] for p in perms), 0) mode &= ~mask if op == '=': mode |= new_perm_bits diff --git a/tests/ansible_helpers_test.py b/tests/ansible_helpers_test.py new file mode 100644 index 00000000..b582466a --- /dev/null +++ b/tests/ansible_helpers_test.py @@ -0,0 +1,20 @@ + +import unittest2 + +import ansible_mitogen.helpers +import testlib + + +class ApplyModeSpecTest(unittest2.TestCase): + func = staticmethod(ansible_mitogen.apply_mode_spec) + + def test_simple(self): + spec = 'u+rwx,go=x' + self.assertEquals(0711, self.func(spec, 0)) + + spec = 'g-rw' + self.assertEquals(0717, self.func(spec, 0777)) + + +if __name__ == '__main__': + unittest2.main()