|
5 | 5 | from __future__ import print_function |
6 | 6 |
|
7 | 7 | from collections import defaultdict |
8 | | -from functools import wraps |
9 | 8 |
|
10 | 9 | import pyparsing |
11 | 10 | from pyparsing import Literal, Suppress, pyparsing_common, opAssoc, Word |
12 | 11 |
|
13 | 12 | from .expression import Expression, Variable, Constant, ExpressionComponent |
14 | 13 | from .identifiers import order_of_operations |
15 | | -from .logging import logger |
| 14 | +from .logging import logger, add_logging |
16 | 15 |
|
17 | 16 |
|
18 | 17 | __all__ = [ |
|
24 | 23 | ] |
25 | 24 |
|
26 | 25 |
|
27 | | -def add_logging(func): |
28 | | - @wraps(func) |
29 | | - def new_func(*args, **kwargs): |
30 | | - try: |
31 | | - func_name = func.__qualname__ |
32 | | - except AttributeError: |
33 | | - # Python 2 doesn't have __qualname__ |
34 | | - func_name = func.__name__ |
35 | | - logger.debug('Calling '+func_name+' with '+repr(args)+' and '+repr(kwargs)) |
36 | | - result = func(*args, **kwargs) |
37 | | - logger.debug(' - Got result '+repr(result)) |
38 | | - return result |
39 | | - return new_func |
40 | | - |
41 | | - |
42 | 26 | class PConstant(object): |
43 | 27 | def __init__(self, id, value): |
44 | 28 | """Represents a constant |
@@ -81,6 +65,7 @@ def get_parser(self, EXPRESSION): |
81 | 65 | # TODO Detect constants? |
82 | 66 | return None |
83 | 67 |
|
| 68 | + @add_logging |
84 | 69 | def to_string(self): |
85 | 70 | return str(self.value) |
86 | 71 |
|
@@ -146,6 +131,7 @@ def _parse_action(self, string, location, result): |
146 | 131 | # TODO Replace with logging decorator |
147 | 132 | return self(*result) |
148 | 133 |
|
| 134 | + @add_logging(ignore_args=[2, 3]) |
149 | 135 | def to_string(self, expression, config, constants): |
150 | 136 | args = [] |
151 | 137 | for arg in expression.args: |
@@ -225,6 +211,7 @@ def _parse_action(self, string, location, result): |
225 | 211 | assert len(result) >= 2 or self._rhs_only, result |
226 | 212 | return self(*result) |
227 | 213 |
|
| 214 | + @add_logging(ignore_args=[2, 3]) |
228 | 215 | def to_string(self, expression, config, constants): |
229 | 216 | args = [] |
230 | 217 | for arg in expression.args: |
|
0 commit comments