Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit 53a5cb1

Browse files
Merge pull request #3 from tomkralidis/add-logging
replace prints with logging
2 parents a0d49f3 + 6a1cc35 commit 53a5cb1

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

pycql/integrations/sqlalchemy/parser.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
1+
2+
import logging
3+
import re
4+
15
from ...parser import parse as _plain_parse
26
from ...util import parse_duration
37
from dateparser import parse as parse_datetime
48
from sqlalchemy import func
5-
import re
9+
10+
LOGGER = logging.getLogger(__name__)
611

712

813
def parse_geometry(geom):
9-
print("PARSE GEOM", geom)
14+
LOGGER.debug(f"PARSE GEOM: {geom}")
1015
search = re.search(r"SRID=(\d+);", geom)
1116

1217
sridtxt = "" if search else "SRID=4326;"
13-
print(f"{sridtxt}{geom}")
18+
LOGGER.debug(f"{sridtxt}{geom}")
1419

1520
return func.ST_GeomFromEWKT(f"{sridtxt}{geom}")
1621

1722

1823
def parse_bbox(box, srid: int=4326):
19-
print("PARSE BBOX", type(box), box)
24+
LOGGER.debug("PARSE BBOX: {type(box)}, {box}")
2025
minx, miny, maxx, maxy = box
2126
return func.ST_GeomFromEWKT(
2227
f"SRID={srid};POLYGON(("

pycql/lexer.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,15 @@
2525
# THE SOFTWARE.
2626
# ------------------------------------------------------------------------------
2727

28+
import logging
2829

2930
from ply import lex
3031
from ply.lex import TOKEN
3132

3233
from . import values
3334

35+
LOGGER = logging.getLogger(__name__)
36+
3437

3538
class CQLLexer(object):
3639
def __init__(self, geometry_factory=values.Geometry, bbox_factory=values.BBox,
@@ -217,4 +220,4 @@ def t_newline(self, t):
217220
t_ignore = ' \t'
218221

219222
def t_error(self, t):
220-
print("ERROR", t)
223+
LOGGER.debug(t)

pycql/parser.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,16 @@
2525
# THE SOFTWARE.
2626
# ------------------------------------------------------------------------------
2727

28+
import logging
29+
2830
from ply import yacc
2931

3032
from .lexer import CQLLexer
3133
from . import ast
3234
from . import values
3335

36+
LOGGER = logging.getLogger(__name__)
37+
3438

3539
class CQLParser(object):
3640
def __init__(self, geometry_factory=values.Geometry, bbox_factory=values.BBox,
@@ -260,18 +264,18 @@ def p_empty(self, p):
260264

261265
def p_error(self, p):
262266
if p:
263-
print(dir(p))
264-
print("Syntax error at token", p.type, p.value, p.lexpos, p.lineno)
267+
LOGGER.debug(dir(p))
268+
LOGGER.debug(f"Syntax error at token {p.type}, {p.value}, {p.lexpos}, {p.lineno}")
265269

266-
print(self.__query.split('\n'))
270+
LOGGER.debug(self.__query.split('\n'))
267271
line = self.__query.split('\n')[p.lineno - 1]
268-
print(line)
269-
print((' ' * p.lexpos) + '^')
272+
LOGGER.debug(line)
273+
LOGGER.debug((' ' * p.lexpos) + '^')
270274

271275
# Just discard the token and tell the parser it's okay.
272276
#p.parser.errok()
273277
else:
274-
print("Syntax error at EOF")
278+
LOGGER.debug("Syntax error at EOF")
275279

276280

277281
def parse(cql, geometry_factory=values.Geometry, bbox_factory=values.BBox,

0 commit comments

Comments
 (0)