def cmp(field, value, comparison='=', escape=(lambda v: _escape(v)), table=''):
 if table:
  field = abs(table, field)
 if (isinstance(value, basestring) and (value.startswith(('*', '%')) or value.endswith(('*', '%')))):
  if (comparison in ('=', 'i=', '==', LIKE)):
   return ('%s like %s' % (field, escape(value.replace('*', '%'))))
  if (comparison in ('!=', '<>')):
   return ('%s not like %s' % (field, escape(value.replace('*', '%'))))
 if isinstance(value, basestring):
  if (comparison == 'i='):
   return ('%s like %s' % (field, escape(value)))
 if isinstance(value, (list, tuple)):
  if find((lambda v: (isinstance(v, basestring) and (v.startswith('*') or v.endswith('*')))), value):
   return ('(%s)' % any(*[(field, v) for v in value]).sql(escape=escape))
  if (comparison in ('=', '==', IN)):
   return ('%s in (%s)' % (field, ','.join((escape(v) for v in value))))
  if (comparison in ('!=', '<>')):
   return ('%s not in (%s)' % (field, ','.join((escape(v) for v in value))))
  if (comparison in (':', BETWEEN)):
   return ('%s between %s and %s' % (field, escape(value[0]), escape(value[1])))
 if isinstance(value, type(None)):
  if (comparison in ('=', '==')):
   return ('%s is null' % field)
  if (comparison in ('!=', '<>')):
   return ('%s is not null' % field)
 if isinstance(value, Query):
  if (comparison in ('=', '==', IN)):
   return ('%s in %s' % (field, escape(value)))
  if (comparison in ('!=', '<>')):
   return ('%s not in %s' % (field, escape(value)))
 return ('%s%s%s' % (field, comparison, escape(value)))

def cmp ( field , value , comparison = '=' , escape = ( lambda v : _escape ( v ) ) , table = '' ) : if table : field = abs ( table , field ) if ( isinstance ( value , basestring ) and ( value . startswith ( ( '*' , '%' ) ) or value . endswith ( ( '*' , '%' ) ) ) ) : if ( comparison in ( '=' , 'i=' , '==' , LIKE ) ) : return ( '%s like %s' % ( field , escape ( value . replace ( '*' , '%' ) ) ) ) if ( comparison in ( '!=' , '<>' ) ) : return ( '%s not like %s' % ( field , escape ( value . replace ( '*' , '%' ) ) ) ) if isinstance ( value , basestring ) : if ( comparison == 'i=' ) : return ( '%s like %s' % ( field , escape ( value ) ) ) if isinstance ( value , ( list , tuple ) ) : if find ( ( lambda v : ( isinstance ( v , basestring ) and ( v . startswith ( '*' ) or v . endswith ( '*' ) ) ) ) , value ) : return ( '(%s)' % any ( * [ ( field , v ) for v in value ] ) . sql ( escape = escape ) ) if ( comparison in ( '=' , '==' , IN ) ) : return ( '%s in (%s)' % ( field , ',' . join ( ( escape ( v ) for v in value ) ) ) ) if ( comparison in ( '!=' , '<>' ) ) : return ( '%s not in (%s)' % ( field , ',' . join ( ( escape ( v ) for v in value ) ) ) ) if ( comparison in ( ':' , BETWEEN ) ) : return ( '%s between %s and %s' % ( field , escape ( value [ 0 ] ) , escape ( value [ 1 ] ) ) ) if isinstance ( value , type ( None ) ) : if ( comparison in ( '=' , '==' ) ) : return ( '%s is null' % field ) if ( comparison in ( '!=' , '<>' ) ) : return ( '%s is not null' % field ) if isinstance ( value , Query ) : if ( comparison in ( '=' , '==' , IN ) ) : return ( '%s in %s' % ( field , escape ( value ) ) ) if ( comparison in ( '!=' , '<>' ) ) : return ( '%s not in %s' % ( field , escape ( value ) ) ) return ( '%s%s%s' % ( field , comparison , escape ( value ) ) )
compare two files .