def normalize_domain(domain):
 assert isinstance(domain, (list, tuple)), "Domains to normalize must have a 'domain' form: a list or tuple of domain components"
 if (not domain):
  return TRUE_DOMAIN
 result = []
 expected = 1
 op_arity = {NOT_OPERATOR: 1, AND_OPERATOR: 2, OR_OPERATOR: 2}
 for token in domain:
  if (expected == 0):
   result[0:0] = [AND_OPERATOR]
   expected = 1
  result.append(token)
  if isinstance(token, (list, tuple)):
   expected -= 1
  else:
   expected += (op_arity.get(token, 0) - 1)
 assert (expected == 0), ('This domain is syntactically not correct: %s' % domain)
 return result

def normalize_domain ( domain ) : assert isinstance ( domain , ( list , tuple ) ) , "Domains to normalize must have a 'domain' form: a list or tuple of domain components" if ( not domain ) : return TRUE_DOMAIN result = [ ] expected = 1 op_arity = { NOT_OPERATOR : 1 , AND_OPERATOR : 2 , OR_OPERATOR : 2 } for token in domain : if ( expected == 0 ) : result [ 0 : 0 ] = [ AND_OPERATOR ] expected = 1 result . append ( token ) if isinstance ( token , ( list , tuple ) ) : expected -= 1 else : expected += ( op_arity . get ( token , 0 ) - 1 ) assert ( expected == 0 ) , ( 'This domain is syntactically not correct: %s' % domain ) return result
returns a normalized version of domain_expr .