Skip to content

Commit

Permalink
Revert "use xpyth-parser for parsing xpath (#91)"
Browse files Browse the repository at this point in the history
This reverts commit e4531f4.
  • Loading branch information
bbonf committed Dec 13, 2023
1 parent e4531f4 commit 6298a66
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 21 deletions.
3 changes: 1 addition & 2 deletions backend/requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ alpino-query>=2.1.10
celery[redis]>=5.2.0
mwe-query>=0.0.4
urllib3<=2.0.0
psycopg2
xpyth-parser
psycopg2
11 changes: 2 additions & 9 deletions backend/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,7 @@ idna==3.4
iniconfig==2.0.0
# via pytest
isodate==0.6.1
# via
# rdflib
# xpyth-parser
# via rdflib
jinja2==3.1.2
# via spacy
kombu==5.3.1
Expand All @@ -116,7 +114,6 @@ lxml==4.9.3
# folia
# sastadev
# tei-reader
# xpyth-parser
markupsafe==2.1.3
# via jinja2
murmurhash==1.0.9
Expand Down Expand Up @@ -158,9 +155,7 @@ pydantic==2.1.1
pydantic-core==2.4.0
# via pydantic
pyparsing==3.1.1
# via
# rdflib
# xpyth-parser
# via rdflib
pytest==7.4.0
# via
# -r requirements.in
Expand Down Expand Up @@ -263,8 +258,6 @@ wcwidth==0.2.6
# via prompt-toolkit
xlsxwriter==3.1.2
# via sastadev
xpyth-parser==0.0.10
# via -r requirements.in

# The following packages are considered to be unsafe in a requirements file:
# setuptools
15 changes: 5 additions & 10 deletions backend/search/basex_search.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
"""Auxiliary functions to facilitate searching in BaseX."""

import lxml.etree
import logging
import string
from io import StringIO
from typing import List
from xpyth_parser.parse import Parser

from .types import BaseXMatch, Result

log = logging.getLogger()

ALLOWED_DBNAME_CHARS = string.ascii_letters + string.digits + \
'!#$%&\'()+-=@[]^_`{}~.'
Expand All @@ -18,14 +16,11 @@
def check_xpath(xpath: str) -> bool:
"""Return True if a string is (only) a valid XPath, otherwise False."""
try:
# for some reason ".." isn't being properly parsed. since it's an abbreviation for
# parent::node(), we can replace it ahead of time
Parser(xpath.replace('..', 'parent::node()'), no_resolve=True)
lxml.etree.XPath(xpath)
except lxml.etree.XPathError:
return False
else:
return True
except:
log.exception('XPath parse exception')

return False


def check_db_name(db_name: str) -> bool:
Expand Down

0 comments on commit 6298a66

Please sign in to comment.