Skip to content

Commit ccf9cff

Browse files
committed
style: clean up code
1 parent 6660a7c commit ccf9cff

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

jsonpath/__init__.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Author : zhangxianbing1
33
Date : 2020-12-27 09:22:14
44
LastEditors : zhangxianbing1
5-
LastEditTime : 2020-12-30 17:16:18
5+
LastEditTime : 2020-12-30 17:28:02
66
Description : JSONPath
77
"""
88
__version__ = "1.0.0"
@@ -13,7 +13,7 @@
1313
import os
1414
import re
1515
import sys
16-
from typing import Any, Dict, Iterable, Union
16+
from typing import Any, Dict, Iterable
1717
from collections import defaultdict
1818

1919
RESULT_TYPE = {
@@ -33,8 +33,11 @@
3333
REP_DOT = re.compile(r"(?<!\.)\.(?!\.)")
3434
REP_FILTER = re.compile(r"\[(\??\(.*?\))\]")
3535
REP_SORT = re.compile(r"\[[\\|/](.*?),\]")
36-
_DEBUG = os.getenv("PYTHONDEBUG")
36+
3737
LOG = logging.getLogger(__name__)
38+
LOG.setLevel(logging.DEBUG)
39+
40+
# pylint: disable=invalid-name,missing-function-docstring,missing-class-docstring
3841

3942

4043
def concat(x, y, con=SEP):
@@ -46,16 +49,16 @@ class ExprSyntaxError(Exception):
4649

4750

4851
class JSONPath:
49-
5052
# annotations
5153
result: Iterable
5254
result_type: str
5355
caller_globals: Dict[str, Any]
5456
subx = defaultdict(list)
5557
ops: list
5658
oplen: int
59+
debug: int
5760

58-
def __init__(self, expr: str, *, result_type="VALUE"):
61+
def __init__(self, expr: str, *, result_type="VALUE", debug=0):
5962

6063
if result_type not in RESULT_TYPE:
6164
raise ValueError(f"result_type must be one of {tuple(RESULT_TYPE.keys())}")
@@ -67,25 +70,21 @@ def __init__(self, expr: str, *, result_type="VALUE"):
6770
self.ops = expr.split(SEP)
6871
self.oplen = len(self.ops)
6972

73+
self.debug = debug
74+
7075
def _parse_expr(self, expr):
71-
print(f"before expr: {expr}")
76+
LOG.debug("before expr: %s", expr)
7277

7378
expr = REP_PICKUP_QUOTE.sub(self._f_pickup_quote, expr)
74-
# print(expr)
7579
expr = REP_PICKUP_BRACKET.sub(self._f_pickup_bracket, expr)
76-
# print(expr)
7780
expr = REP_DOUBLEDOTS.sub(f"{SEP}..{SEP}", expr)
78-
# print(expr)
7981
expr = REP_DOT.sub(SEP, expr)
80-
# print(expr)
8182
expr = REP_PUTBACK_BRACKET.sub(self._f_putback_bracket, expr)
82-
# print(expr)
8383
expr = REP_PUTBACK_QUOTE.sub(self._f_putback_quote, expr)
84-
# print(expr)
8584
if expr.startswith("$;"):
8685
expr = expr[2:]
8786

88-
print(f"after expr: {expr}")
87+
LOG.debug("before expr: %s", expr)
8988
return expr
9089

9190
def _f_pickup_quote(self, m):

0 commit comments

Comments
 (0)