Parse a Unix permission string and return integer value.
333526
def parse_unix_perm(text):
    ''''''
    # Based on ftp-ls.c symperms
    if len(text) != 9:
        return 0

    perms = 0

    for triad_index in range(3):
        string_index = triad_index * 3
        perms <<= 3

        if text[string_index] == 'r':
            perms |= 1 << 2

        if text[string_index + 1] == 'w':
            perms |= 1 << 1

        if text[string_index + 2] in 'xs':
            perms |= 1

    return perms
54040
def parse_permissions(perms):
    
    if isinstance(perms, six.string_types):
        perms = perms.split(',')
    perms = [perm.strip().lower() for perm in perms]
    if 'all' in perms:
        return ALL_PERMISSIONS
    return validate_permissions(perms)
416871
def find_permission(
        permissions, permission_type, object_id=None, namespace=None):
    ''''''
    if object_id is not None:
        return permissions.filter(
            type=permission_type, object_id=object_id, namespace=namespace)
    return permissions.filter(type=permission_type)
1218713
def parseLsPermissionText(permission_text):
    

    from six.moves import range

    match = re.search("[-drwx]+", permission_text)
    if match is None:
        raise ValueError(
            "invalid permission character: " + permission_text)

    if len(permission_text) != 10:
        raise ValueError(
            "invalid permission text length: " + permission_text)

    permission_text = permission_text[1:]

    return int(
        "0" + "".join([
            str(parsePermission3Char(permission_text[i:i + 3]))
            for i in range(0, 9, 3)
        ]),
        base=8)
998420
def _process_permission(perm):
    """"""
    # XXX: Optimize: rebuild only permissions, not whole document
    codename = perm.permission.codename
    if not codename.startswith('view') and not codename.startswith('owner'):
        return

    index_builder.build(perm.content_object)
1228534
def parse(cls, detail_string):
        """"""
        split = detail_string.split(':')
        if len(split) != 4:
            raise Exception('invalid credentials')  # TODO: other exception

        ltpk = binascii.unhexlify(split[0])
        ltsk = binascii.unhexlify(split[1])
        atv_id = binascii.unhexlify(split[2])
        client_id = binascii.unhexlify(split[3])
        return Credentials(ltpk, ltsk, atv_id, client_id)
190674
def check_permission_safety(path):
    
    f_stats = os.stat(path)
    return (f_stats.st_mode & (stat.S_IRWXG | stat.S_IRWXO)) == 0 and f_stats.st_uid == os.getuid()
823384
def parse_int(int_str):
    """"""
    int_str = int_str.replace(',', '')

    factor = __get_factor(int_str)
    if factor != 1:
        int_str = int_str[:-1]

    try:
        return int(int_str.replace(',', '')) * factor
    except ValueError:
        return None
51341
public static FsPermission valueOf(String unixSymbolicPermission) {
    if (unixSymbolicPermission == null) {
      return null;
    }
    else if (unixSymbolicPermission.length() != 10) {
      throw new IllegalArgumentException("length != 10(unixSymbolicPermission="
          + unixSymbolicPermission + ")");
    }
    int n = 0;
    for(int i = 1; i < unixSymbolicPermission.length(); i++) {
      n = n << 1;
      char c = unixSymbolicPermission.charAt(i);
      n += (c == '-' || c == 'T' || c == 'S') ? 0: 1;
    }
    return new FsPermission((short)n);
  }
1150581
async def verify_permissions(self, user_id, *permissions):
        

        prefix = f"{self._prefix_perm}/{user_id}/"

        perm_names = [str(p) for p in permissions]
        
        checkings = [KV.get.txn(prefix + p) for p in perm_names]
        success, responses = await self._client.txn(compare=[], success=checkings)
        if not success:
            errmsg = f"无法读取用户({user_id})的权限信息"
            raise Unprocessable(errmsg)

        for i, item  in enumerate(responses):
            if item[0] is not None:
                return permissions[0]
                
        return None
1132001
def parse_unix(self, lines):
        ''''''
        # This method uses some Filezilla parsing algorithms

        for line in lines:
            original_line = line
            fields = line.split(' ')
            after_perm_index = 0

            # Search for the permissions field by checking the file type
            for field in fields:
                after_perm_index += len(field)
                if not field:
                    continue

                # If the filesystem goes corrupt, it may show ? instead
                # but I don't really care in that situation.
                if field[0] in 'bcdlps-':
                    if field[0] == 'd':
                        file_type = 'dir'
                    elif field[0] == '-':
                        file_type = 'file'
                    elif field[0] == 'l':
                        file_type = 'symlink'
                    else:
                        file_type = 'other'

                    perms = parse_unix_perm(field[1:])

                    break
            else:
                raise ListingError('Failed to parse file type.')

            line = line[after_perm_index:]

            # We look for the position of the date and use the integer
            # before it as the file size.
            # We look for the position of the time and use the text
            # after it as the filename

            while line:
                try:
                    datetime_obj, start_index, end_index = self.parse_datetime(line)
                except ValueError:
                    line = line[4:]
                else:
                    break
            else:
                raise ListingError(
                    'Could parse a date from {}'.format(repr(original_line)))

            file_size = int(line[:start_index].rstrip().rpartition(' ')[-1])

            filename = line[end_index:].strip()

            if file_type == 'symlink':
                filename, sep, symlink_dest = filename.partition(' -> ')
            else:
                symlink_dest = None

            yield FileEntry(filename, file_type, file_size, datetime_obj,
                            symlink_dest, perm=perms)
718210
def parse_membership(header_string, membership):  # pragma: no cover
        """"""
        print(header_string, "\n{}".format('=' * len(header_string)))
        for key, values in membership.items():
            if values is None:
                continue
            print('- ', key)
            for value in values:
                print("\t- {}".format(value))
230803
def parse_authority(cls, authority):
        ''''''
        userinfo, sep, host = authority.partition('@')

        if not sep:
            return '', userinfo
        else:
            return userinfo, host
169981
def run(self, value, errors, request):
        """"""
        thing = super(AccessibleDBThing, self).run(value, errors, request)
        if errors:
            return None
        if not thing.can_access(request.user):
            message = 'Insufficient permissions for {0}'.format(self.param)
            raise HTTPForbidden(message)
        return thing
838301
def str2rsi(key):
    
    rlzi, sid, imt = key.split('/')
    return int(rlzi[4:]), int(sid[4:]), imt
1113735
def getPermissionBit(self, t, m):
        '''
        
        '''
        try:
            if isinstance(m, string_types):
                return self.rights[t][m]['BITS']
            else:
                return m
        except KeyError:
            raise CommandExecutionError((
                'No right "{0}".  It should be one of the following:  {1}')
                .format(m, ', '.join(self.rights[t])))
948936
def _str_sid(self):
    ''
    sub_auths = "-".join([str(sub) for sub in self.sub_authorities])
    return f'S-{self.revision_number}-{self.authority}-{sub_auths}'