code: def apply_mode_spec(spec, mode):
      
      for clause in mitogen.core.to_text(spec).split(','):
          match = CHMOD_CLAUSE_PAT.match(clause)
          who, op, perms = match.groups()
          for ch in who or 'a':
              mask = CHMOD_MASKS[ch]
              bits = CHMOD_BITS[ch]
              cur_perm_bits = mode & mask
              new_perm_bits = reduce(operator.or_, (bits[p] for p in perms), 0)
              mode &= ~mask
              if op == '=':
                  mode |= new_perm_bits
              elif op == '+':
                  mode |= new_perm_bits | cur_perm_bits
              else:
                  mode |= cur_perm_bits & ~new_perm_bits
      return mode
docs: Given a symbolic file mode change specification in the style of chmod(1)
      `spec`, apply changes in the specification to the numeric file mode `mode`.