def parse(self, text):
        """The parser entry point.

        Parse the provided text to check for its validity.

        On success, the parsing tree is available into the result
        attribute. It is a list of sievecommands.Command objects (see
        the module documentation for specific information).

        On error, an string containing the explicit reason is
        available into the error attribute.

        :param text: a string containing the data to parse
        :return: True on success (no error detected), False otherwise
        """
        if isinstance(text, text_type):
            text = text.encode("utf-8")

        self.__reset_parser()
        try:
            for ttype, tvalue in self.lexer.scan(text):
                if ttype == "hash_comment":
                    self.hash_comments += [tvalue.strip()]
                    continue
                if ttype == "bracket_comment":
                    continue
                if self.__expected is not None:
                    if ttype not in self.__expected:
                        if self.lexer.pos < len(text):
                            msg = (
                                "%s found while %s expected near '%s'"
                                % (ttype, "|".join(self.__expected),
                                   text[self.lexer.pos])
                            )
                        else:
                            msg = (
                                "%s found while %s expected at end of file"
                                  % (ttype, "|".join(self.__expected))
                            )
                        raise ParseError(msg)
                    self.__expected = None

                if not self.__command(ttype, tvalue):
                    msg = (
                        "unexpected token '%s' found near '%s'"
                        % (tvalue.decode(), text.decode()[self.lexer.pos])
                    )
                    raise ParseError(msg)
            if self.__opened_blocks:
                self.__set_expected("right_cbracket")
            if self.__expected is not None:
                raise ParseError("end of script reached while %s expected" %
                                 "|".join(self.__expected))

        except (ParseError, CommandError) as e:
            self.error = "line %d: %s" % (self.lexer.curlineno(), str(e))
            return False
        return True
def parse ( self , text ) : if isinstance ( text , text_type ) : text = text . encode ( "utf-8" ) self . __reset_parser ( ) try : for ttype , tvalue in self . lexer . scan ( text ) : if ttype == "hash_comment" : self . hash_comments += [ tvalue . strip ( ) ] continue if ttype == "bracket_comment" : continue if self . __expected is not None : if ttype not in self . __expected : if self . lexer . pos < len ( text ) : msg = ( "%s found while %s expected near '%s'" % ( ttype , "|" . join ( self . __expected ) , text [ self . lexer . pos ] ) ) else : msg = ( "%s found while %s expected at end of file" % ( ttype , "|" . join ( self . __expected ) ) ) raise ParseError ( msg ) self . __expected = None if not self . __command ( ttype , tvalue ) : msg = ( "unexpected token '%s' found near '%s'" % ( tvalue . decode ( ) , text . decode ( ) [ self . lexer . pos ] ) ) raise ParseError ( msg ) if self . __opened_blocks : self . __set_expected ( "right_cbracket" ) if self . __expected is not None : raise ParseError ( "end of script reached while %s expected" % "|" . join ( self . __expected ) ) except ( ParseError , CommandError ) as e : self . error = "line %d: %s" % ( self . lexer . curlineno ( ) , str ( e ) ) return False return True
The parser entry point.

        Parse the provided text to check for its validity.

        On success, the parsing tree is available into the result
        attribute. It is a list of sievecommands.Command objects (see
        the module documentation for specific information).

        On error, an string containing the explicit reason is
        available into the error attribute.

        :param text: a string containing the data to parse
        :return: True on success (no error detected), False otherwise