return [ func(x) for x in value ]
else:
return func(value)
-
+
+def escape_ldap_filter(value):
+ value = str(value)
+ return value.replace('\\', '\\5c') \
+ .replace('*', '\\2a') \
+ .replace('(', '\\28') \
+ .replace(')', '\\29') \
+ .replace('\0', '\\00')
+
class LdapConnection(object):
def __init__(self, server, bind_dn, bind_password):
self.connection = ldap.initialize(server)
from django.db.models import fields, SubfieldBase
+from ldapdb import escape_ldap_filter
+
class CharField(fields.CharField):
def __init__(self, *args, **kwargs):
kwargs['max_length'] = 200
super(CharField, self).__init__(*args, **kwargs)
+ def get_prep_lookup(self, lookup_type, value):
+ return escape_ldap_filter(value)
+
class ImageField(fields.Field):
pass
import ldapdb
-def escape_ldap_filter(value):
- value = str(value)
- return value.replace('\\', '\\5c') \
- .replace('*', '\\2a') \
- .replace('(', '\\28') \
- .replace(')', '\\29') \
- .replace('\0', '\\00')
+from ldapdb import escape_ldap_filter
class Constraint(BaseConstraint):
"""
if isinstance(item, WhereNode):
bits.append(item.as_sql())
continue
- (table, column, type), x, y, values = item
- equal_bits = [ "(%s=%s)" % (column, value) for value in values ]
- if len(equal_bits) == 1:
- clause = equal_bits[0]
+ constraint, x, y, values = item
+ if hasattr(constraint, "col"):
+ # django 1.2
+ clause = "(%s=%s)" % (constraint.col, values)
else:
- clause = '(|%s)' % ''.join(equal_bits)
+ # django 1.1
+ (table, column, type) = constraint
+ equal_bits = [ "(%s=%s)" % (column, value) for value in values ]
+ if len(equal_bits) == 1:
+ clause = equal_bits[0]
+ else:
+ clause = '(|%s)' % ''.join(equal_bits)
if self.negated:
bits.append('(!%s)' % clause)
else:
from django.test import TestCase
from django.db.models.sql.where import Constraint, AND, OR
+from ldapdb.models.query import escape_ldap_filter
from ldapdb.models.fields import CharField, IntegerField
-from ldapdb.models.query import WhereNode, escape_ldap_filter
+from ldapdb.models.query import WhereNode
class WhereTestCase(TestCase):
def test_escape(self):