Python pyparsing.ParseBaseException() Examples

The following are 5 code examples of pyparsing.ParseBaseException(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module pyparsing , or try the search function .
Example #1
Source File: pathspec.py    From bob with GNU General Public License v3.0 6 votes vote down vote up
def __query(self, path):
        # replace aliases
        path = self.__substAlias(path)

        while path.endswith('/'): path = path[:-1]
        if path:
            try:
                path = self.__pathGrammer.parseString(path, True)
            except pyparsing.ParseBaseException as e:
                raise BobError("Invalid syntax: " + str(e),
                               help=markLocation(e.line, e.col))
            assert len(path) == 1
            assert isinstance(path[0], LocationPath)
            #print(path[0])
            return path[0].evalForward(self.__getGraphRoot())
        else:
            root = self.__getGraphRoot()
            return (set([root]), set([root])) 
Example #2
Source File: stringparser.py    From bob with GNU General Public License v3.0 5 votes vote down vote up
def parseExpression(self, expression):
        try:
            ret = self.__ifgrammer.parseString(expression, True)
        except pyparsing.ParseBaseException as e:
            raise ParseError("Invalid syntax: " + str(e))
        return ret[0] 
Example #3
Source File: ldap3mock.py    From privacyidea with GNU Affero General Public License v3.0 5 votes vote down vote up
def search(self, search_base=None, search_scope=None,
               search_filter=None, attributes=None, paged_size=5,
               size_limit=0, paged_cookie=None):
        s_filter = list()
        candidates = list()
        self.response = list()
        self.result = dict()

        try:
            if isinstance(search_filter, bytes):
                # We need to convert to unicode otherwise pyparsing will not
                # find the u"รถ"
                search_filter = to_unicode(search_filter)
            expr = Connection._parse_filter()
            s_filter = expr.parseString(search_filter).asList()[0]
        except pyparsing.ParseBaseException as exx:
            # Just for debugging purposes
            s = "{!s}".format(exx)

        for item in s_filter:
            if item[0] in self.operation:
                candidates = self.operation.get(item[0])(search_base,
                                                         s_filter)
        self.response = Connection._deDuplicate(candidates)

        return True 
Example #4
Source File: test_config_parser.py    From pyhocon with Apache License 2.0 5 votes vote down vote up
def test_fail_parse_forbidden_characters(self, forbidden_char):
        with pytest.raises(ParseBaseException):
            ConfigFactory.parse_string('a: hey man{}'.format(forbidden_char)) 
Example #5
Source File: model.py    From trains with Apache License 2.0 5 votes vote down vote up
def _text_to_config_dict(text):
        if not isinstance(text, six.string_types):
            raise ValueError("Model configuration parsing only supports string")
        try:
            return ConfigFactory.parse_string(text).as_plain_ordered_dict()
        except pyparsing.ParseBaseException as ex:
            pos = "at char {}, line:{}, col:{}".format(ex.loc, ex.lineno, ex.column)
            six.raise_from(ValueError("Could not parse configuration text ({}):\n{}".format(pos, text)), None)
        except Exception:
            six.raise_from(ValueError("Could not parse configuration text:\n{}".format(text)), None)