Update pyson with trytond one

This commit is contained in:
Cédric Krier committed 2011-08-21 11:22:23 +02:00
1 parent 8a60934688
commit ea60a8bdf3
1 file changed
+60 -2
+60 -2
View File
@@ -18,6 +18,64 @@ class PYSON(object):
def eval(dct, context):
raise NotImplementedError
def __invert__(self):
if self.types()!= set([bool]):
return Not(Bool(self))
else:
return Not(self)
def __and__(self, other):
if (isinstance(self, And)
and not isinstance(self, Or)):
self._statements.append(other)
return self
if (isinstance(other, PYSON)
and other.types() != set([bool])):
other = Bool(other)
if self.types() != set([bool]):
return And(Bool(self), other)
else:
return And(self, other)
def __or__(self, other):
if isinstance(self, Or):
self._statements.append(other)
return self
if (isinstance(other, PYSON)
and other.types() != set([bool])):
other = Bool(other)
if self.types() != set([bool]):
return Or(Bool(self), other)
else:
return Or(self, other)
def __eq__(self, other):
return Equal(self, other)
def __ne__(self, other):
return Not(Equal(self, other))
def __gt__(self, other):
return Greater(self, other)
def __ge__(self, other):
return Greater(self, other, True)
def __lt__(self, other):
return Less(self, other)
def __le__(self, other):
return Less(self, other, True)
def get(self, k, d=''):
return Get(self, k, d)
def in_(self, obj):
return In(self, obj)
def contains(self, k):
return In(k, self)
class PYSONEncoder(json.JSONEncoder):
@@ -129,7 +187,7 @@ class And(PYSON):
assert isinstance(statement, bool), \
'statement must be boolean'
assert len(statements) >= 2, 'must have at least 2 statements'
self._statements = statements
self._statements = list(statements)
def pyson(self):
return {
@@ -403,7 +461,7 @@ class Date(PYSON):
date = date.replace(year=year)
if dct['dM']:
month = date.month + dct['dM']
year = date.year + month / 12
year = date.year + month // 12
month = month % 12
date = date.replace(year=year, month=month)
if dct['dd']: