'Validates that a parsed rule entry is valid for fschecker.
Args:
expression: A rule expression.
Raises:
DefinitionError: If the filter definition could not be validated.
Returns:
True if the expression validated OK.'

def Validate(self, expression):

    parsed = self._Load(expression)
    if (not parsed):
        raise DefinitionError('Empty    StatFilter    expression.')
    bad_keys = (set(parsed) - self._KEYS)
    if bad_keys:
        raise DefinitionError(('Invalid    parameters:    %s' % ','.join(bad_keys)))
    if (self.cfg.mask and (not self.cfg.mode)):
        raise DefinitionError('mode    can    only    be    set    when    mask    is    also    defined.')
    if self.cfg.mask:
        if (len(self.cfg.mask) > 1):
            raise DefinitionError('Too    many    mask    values    defined.')
        if (not self._PERM_RE.match(self.cfg.mask[0])):
            raise DefinitionError(('mask=%s    is    not    octal,    e.g.    0600' % self.cfg.mask))
    if self.cfg.mode:
        if (len(self.cfg.mode) > 1):
            raise DefinitionError('Too    many    mode    values    defined.')
        if (not self._PERM_RE.match(self.cfg.mode[0])):
            raise DefinitionError(('mode=%s    is    not    octal,    e.g.    0600' % self.cfg.mode))
    if self.cfg.gid:
        for gid in self.cfg.gid:
            matched = self._UID_GID_RE.match(gid)
            if (not matched):
                raise DefinitionError(('gid:    %s    is    not    an    integer    preceded    by    !,    >,    <    or    =.' % gid))
    if self.cfg.uid:
        for uid in self.cfg.uid:
            matched = self._UID_GID_RE.match(uid)
            if (not matched):
                raise DefinitionError(('uid:    %s    is    not    an    integer    preceded    by    !,    >,    <    or    =.' % uid))
    if self.cfg.file_re:
        if (len(self.cfg.file_re) > 1):
            raise DefinitionError(('Too    many    regexes    defined:    %s' % self.cfg.file_re))
        try:
            self.file_re = re.compile(self.cfg.file_re[0])
        except (re.error, TypeError) as e:
            raise DefinitionError(('Invalid    file    regex:    %s' % e))
    if self.cfg.path_re:
        if (len(self.cfg.path_re) > 1):
            raise DefinitionError(('Too    many    regexes    defined:    %s' % self.cfg.path_re))
        try:
            self.path_re = re.compile(self.cfg.path_re[0])
        except (re.error, TypeError) as e:
            raise DefinitionError(('Invalid    path    regex:    %s' % e))
    if self.cfg.file_type:
        if (len(self.cfg.file_type) > 1):
            raise DefinitionError(('Too    many    file    types    defined:    %s' % self.cfg.file_type))
        file_type = self.cfg.file_type[0].upper()
        if (file_type not in self._TYPES):
            raise DefinitionError(('Unsupported    file    type    %s' % file_type))
    self._Initialize()
    if (not self.matchers):
        raise DefinitionError(('StatFilter    has    no    actions:    %s' % expression))
    return True
