'Convert a Unix permission string (rw-r--r--) into a mode (0644)'

def _permstr_to_octal(self, modestr, umask):

    revstr = modestr[::(-1)]
    mode = 0
    for j in range(0, 3):
        for i in range(0, 3):
            if (revstr[(i + (3 * j))] in ['r', 'w', 'x', 's', 't']):
                mode += (2 ** (i + (3 * j)))
    return (mode & (~ umask))
