diff --git a/tryton/pyson.py b/tryton/pyson.py index 5eaa0edadc..a79067a80c 100644 --- a/tryton/pyson.py +++ b/tryton/pyson.py @@ -95,6 +95,14 @@ class PYSON(object): def contains(self, k): return In(k, self) + def __repr__(self): + klass = self.__class__.__name__ + return '%s(%s)' % (klass, ', '.join(map(repr, self.__repr_params__))) + + @property + def __repr_params__(self): + return NotImplementedError + class PYSONEncoder(json.JSONEncoder): @@ -132,6 +140,10 @@ class Eval(PYSON): self._value = value self._default = default + @property + def __repr_params__(self): + return self._value, self._default + def pyson(self): return { '__class__': 'Eval', @@ -161,6 +173,10 @@ class Not(PYSON): assert isinstance(value, bool), 'value must be boolean' self._value = value + @property + def __repr_params__(self): + return (self._value,) + def pyson(self): return { '__class__': 'Not', @@ -181,6 +197,10 @@ class Bool(PYSON): super(Bool, self).__init__() self._value = value + @property + def __repr_params__(self): + return (self._value,) + def pyson(self): return { '__class__': 'Bool', @@ -209,6 +229,10 @@ class And(PYSON): assert len(statements) >= 2, 'must have at least 2 statements' self._statements = list(statements) + @property + def __repr_params__(self): + return tuple(self._statements) + def pyson(self): return { '__class__': 'And', @@ -251,6 +275,10 @@ class Equal(PYSON): self._statement1 = statement1 self._statement2 = statement2 + @property + def __repr_params__(self): + return (self._statement1, self._statement2) + def pyson(self): return { '__class__': 'Equal', @@ -285,6 +313,10 @@ class Greater(PYSON): self._statement2 = statement2 self._equal = equal + @property + def __repr_params__(self): + return (self._statement1, self._statement2, self._equal) + def pyson(self): return { '__class__': 'Greater', @@ -352,6 +384,10 @@ class If(PYSON): self._then_statement = then_statement self._else_statement = else_statement + @property + def __repr_params__(self): + return (self._condition, self._then_statement, self._else_statement) + def pyson(self): return { '__class__': 'If', @@ -391,6 +427,10 @@ class Get(PYSON): self._key = key self._default = default + @property + def __repr_params__(self): + return (self._obj, self._key, self._default) + def pyson(self): return { '__class__': 'Get', @@ -433,6 +473,10 @@ class In(PYSON): self._key = key self._obj = obj + @property + def __repr_params__(self): + return (self._key, self._obj) + def pyson(self): return { '__class__': 'In', @@ -467,6 +511,11 @@ class Date(PYSON): self._delta_months = delta_months self._delta_days = delta_days + @property + def __repr_params__(self): + return (self._year, self._month, self._day, + self._delta_years, self._delta_months, self._delta_days) + def pyson(self): return { '__class__': 'Date', @@ -520,6 +569,15 @@ class DateTime(Date): self._delta_seconds = delta_seconds self._delta_microseconds = delta_microseconds + @property + def __repr_params__(self): + date_params = super(DateTime, self).__repr_params__ + return (date_params[:3] + + (self._hour, self._minute, self._second, self._microsecond) + + date_params[3:] + + (self._delta_hours, self._delta_minutes, self._delta_seconds, + self._delta_microseconds)) + def pyson(self): res = super(DateTime, self).pyson() res['__class__'] = 'DateTime' @@ -568,6 +626,10 @@ class Len(PYSON): 'value must be a dict or list or a string' self._value = value + @property + def __repr_params__(self): + return (self._value,) + def pyson(self): return { '__class__': 'Len',