16 |
# write to the Free Software Foundation, Inc., 59 Temple Place |
# write to the Free Software Foundation, Inc., 59 Temple Place |
17 |
# - Suite 330, Boston, MA 02111-1307, USA. |
# - Suite 330, Boston, MA 02111-1307, USA. |
18 |
# |
# |
19 |
# Copyright 2000-2002 Free Software Foundation |
# Copyright 2000-2003 Free Software Foundation |
20 |
# |
# |
21 |
# FILE: |
# FILE: |
22 |
# GConditions.py |
# GConditions.py |
148 |
class GCnull(GConditionElement): |
class GCnull(GConditionElement): |
149 |
def __init__(self, parent=None): |
def __init__(self, parent=None): |
150 |
GConditionElement.__init__(self, parent, 'GCnull') |
GConditionElement.__init__(self, parent, 'GCnull') |
151 |
|
|
152 |
class GCnotnull(GConditionElement): |
class GCnotnull(GConditionElement): |
153 |
def __init__(self, parent=None): |
def __init__(self, parent=None): |
154 |
GConditionElement.__init__(self, parent, 'GCnotnull') |
GConditionElement.__init__(self, parent, 'GCnotnull') |
155 |
|
|
156 |
|
|
157 |
|
|
158 |
# build an impossible condition GCondition={0=1} |
# build an impossible condition GCondition={0=1} |
159 |
GCimpossible=GCondition() |
GCimpossible=GCondition() |
261 |
'BaseClass': GCnotbetween, |
'BaseClass': GCnotbetween, |
262 |
'ParentTags': ('condition','and','or','not','negate') }, |
'ParentTags': ('condition','and','or','not','negate') }, |
263 |
'null': { |
'null': { |
264 |
'BaseClass': GCnull, |
'BaseClass': GCnull, |
265 |
'ParentTags': ('FIXME') }, |
'ParentTags': ('condition','and','or','not') }, |
266 |
'notnull': { |
'notnull': { |
267 |
'BaseClass': GCnotnull, |
'BaseClass': GCnotnull, |
268 |
'ParentTags': ('FIXME') }, |
'ParentTags': ('condition','and','or','not') }, |
269 |
} |
} |
270 |
|
|
271 |
for alteration in updates.keys(): |
for alteration in updates.keys(): |
398 |
|
|
399 |
def buildPrefixFromTree(conditionTree): |
def buildPrefixFromTree(conditionTree): |
400 |
if type(conditionTree) != types.InstanceType: |
if type(conditionTree) != types.InstanceType: |
401 |
raise ConditionError, "No valid condition tree" |
tmsg = _("No valid condition tree") |
402 |
else: |
raise ConditionError, tmsg |
403 |
|
else: |
404 |
otype = string.lower(conditionTree._type[2:]) |
otype = string.lower(conditionTree._type[2:]) |
405 |
|
|
406 |
# |
# |
414 |
|
|
415 |
elif otype == 'param': |
elif otype == 'param': |
416 |
return [('param', conditionTree.getValue())] |
return [('param', conditionTree.getValue())] |
417 |
|
|
418 |
# |
# |
419 |
# if its an conditional object, then process it's children |
# if its an conditional object, then process it's children |
420 |
# |
# |
421 |
elif conditionElements.has_key(otype): |
elif conditionElements.has_key(otype): |
422 |
result=[] |
result=[] |
423 |
|
|
424 |
# first add operator to the list |
# first add operator to the list |
425 |
result.append((otype,'')); # ,None)); |
result.append((otype,'')); # ,None)); |
426 |
|
|
427 |
|
|
428 |
# change operations with more than there minimal element no into |
# change operations with more than there minimal element no into |
429 |
# multiple operations with minimal elements |
# multiple operations with minimal elements |
434 |
conditionElements[otype][0]): |
conditionElements[otype][0]): |
435 |
paramcount=paramcount-1 |
paramcount=paramcount-1 |
436 |
result.append((otype,'')); |
result.append((otype,'')); |
437 |
|
|
438 |
|
|
439 |
# then add children |
# then add children |
440 |
for i in range(0, len(conditionTree._children)): |
for i in range(0, len(conditionTree._children)): |
445 |
# check for integrity of condition |
# check for integrity of condition |
446 |
# |
# |
447 |
if len(conditionTree._children) < conditionElements[otype][0]: |
if len(conditionTree._children) < conditionElements[otype][0]: |
448 |
raise GConditions.ConditionError, \ |
tmsg = _('Condition element "%s" expects at least %s arguments; found %s') % \ |
449 |
_('Condition element "%s" expects at least %s arguments; found %s') % \ |
(otype, conditionElements[otype][0], len(conditionTree._children)) |
450 |
(otype, conditionElements[otype][0], len(conditionTree._children)) |
raise GConditions.ConditionError, tmsg |
451 |
|
|
452 |
if len(conditionTree._children) > conditionElements[otype][1]: |
if len(conditionTree._children) > conditionElements[otype][1]: |
453 |
raise GConditions.ConditionError, \ |
tmsg = _('Condition element "%s" expects at most %s arguments; found %s') % \ |
454 |
_('Condition element "%s" expects at most %s arguments; found %s') % \ |
(otype, conditionElements[otype][1], len(conditionTree._children)) |
455 |
(otype, conditionElements[otype][1], len(conditionTree._children)) |
raise GConditions.ConditionError, tmsg |
456 |
|
|
457 |
|
|
458 |
# return combination |
# return combination |
459 |
return result; |
return result; |
460 |
|
|
461 |
else: |
else: |
462 |
raise GConditions.ConditionNotSupported, \ |
tmsg = _('Condition clause "%s" is not supported '+ |
|
_('Condition clause "%s" is not supported '+ |
|
463 |
'by the condition to prefix table conversion.') % otype |
'by the condition to prefix table conversion.') % otype |
464 |
|
raise GConditions.ConditionNotSupported, tmsg |
465 |
|
|