# Path: ldaptor/protocols/ldap/ldapconnector.py
# class LDAPConnector(SRVConnector):
# class LDAPClientCreator(protocol.ClientCreator):
#     def __init__(self, reactor, dn, factory,
#                  overrides=None, bindAddress=None):
#     def __getstate__(self):
#     def _findOverRide(self, dn, overrides):
#     def _isQueryNeeded(self):
#     def connect(self):
#     def pickServer(self):
#     def connect(self, dn, overrides=None, bindAddress=None):
#     def connectAnonymously(self, dn, overrides=None):
#         def _bind(proto):
# 
# Path: ldaptor/protocols/ldap/distinguishedname.py
# def escape(s):
# def unescape(s):
# def _splitOnNotEscaped(s, separator):
#     def __init__(self, rdn):
#     def __str__(self):
#     def __init__(self, stringValue=None, attributeType=None, value=None):
#     def __str__(self):
#     def __repr__(self):
#     def __hash__(self):
#     def __eq__(self, other):
#     def __ne__(self, other):
#     def __lt__(self, other):
#     def __gt__(self, other):
#     def __le__(self, other):
#     def __ge__(self, other):
#     def __init__(self, magic=None, stringValue=None, attributeTypesAndValues=None):
#     def split(self):
#     def __str__(self):
#     def __repr__(self):
#     def __hash__(self):
#     def __eq__(self, other):
#     def __ne__(self, other):
#     def __lt__(self, other):
#     def __gt__(self, other):
#     def __le__(self, other):
#     def __ge__(self, other):
#     def count(self):
#     def __init__(self, magic=None, stringValue=None, listOfRDNs=None):
#     def split(self):
#     def up(self):
#     def __str__(self):
#     def __repr__(self):
#     def __hash__(self):
#     def __eq__(self, other):
#     def __ne__(self, other):
#     def __cmp__(self, other):
#     def getDomainName(self):
#     def contains(self, other):
# class InvalidRelativeDistinguishedName(Exception):
# class LDAPAttributeTypeAndValue:
# class RelativeDistinguishedName:
# class DistinguishedName:


from twisted.trial import unittest
from twisted.internet import reactor, protocol, address
from ldaptor.protocols.ldap import ldapconnector, distinguishedname

class FakeProto(protocol.Protocol):
    pass

class TestCallableOverride(unittest.TestCase):
    """
    Callable values in serviceLocationOverride get to override the
    whole connecting process.
    """

    def testSimple(self):
        dn = distinguishedname.DistinguishedName('dc=example,dc=com')
        c = ldapconnector.LDAPClientCreator(reactor, FakeProto)
        def _doConnect(factory):
            factory.doStart()
            factory.startedConnecting(c)
            proto = factory.buildProtocol(address.IPv4Address('TCP', 'localhost', '1'))
        d = c.connect(dn, overrides={ dn: _doConnect, })
        def cb(r):
            self.failUnless(isinstance(r, FakeProto))
        d.addCallback(cb)
        return d

    def testFindOverride_plainString(self):
        """Plain strings work as override keys."""

# Path: ldaptor/protocols/ldap/ldapconnector.py
# class LDAPConnector(SRVConnector):
# class LDAPClientCreator(protocol.ClientCreator):
#     def __init__(self, reactor, dn, factory,
#                  overrides=None, bindAddress=None):
#     def __getstate__(self):
#     def _findOverRide(self, dn, overrides):
#     def _isQueryNeeded(self):
#     def connect(self):
#     def pickServer(self):
#     def connect(self, dn, overrides=None, bindAddress=None):
#     def connectAnonymously(self, dn, overrides=None):
#         def _bind(proto):
# 
# Path: ldaptor/protocols/ldap/distinguishedname.py
# def escape(s):
# def unescape(s):
# def _splitOnNotEscaped(s, separator):
#     def __init__(self, rdn):
#     def __str__(self):
#     def __init__(self, stringValue=None, attributeType=None, value=None):
#     def __str__(self):
#     def __repr__(self):
#     def __hash__(self):
#     def __eq__(self, other):
#     def __ne__(self, other):
#     def __lt__(self, other):
#     def __gt__(self, other):
#     def __le__(self, other):
#     def __ge__(self, other):
#     def __init__(self, magic=None, stringValue=None, attributeTypesAndValues=None):
#     def split(self):
#     def __str__(self):
#     def __repr__(self):
#     def __hash__(self):
#     def __eq__(self, other):
#     def __ne__(self, other):
#     def __lt__(self, other):
#     def __gt__(self, other):
#     def __le__(self, other):
#     def __ge__(self, other):
#     def count(self):
#     def __init__(self, magic=None, stringValue=None, listOfRDNs=None):
#     def split(self):
#     def up(self):
#     def __str__(self):
#     def __repr__(self):
#     def __hash__(self):
#     def __eq__(self, other):
#     def __ne__(self, other):
#     def __cmp__(self, other):
#     def getDomainName(self):
#     def contains(self, other):
# class InvalidRelativeDistinguishedName(Exception):
# class LDAPAttributeTypeAndValue:
# class RelativeDistinguishedName:
# class DistinguishedName:


# Path: ldaptor/test/test_connector.py
from twisted.trial import unittest
from twisted.internet import reactor, protocol, address
from ldaptor.protocols.ldap import ldapconnector, distinguishedname


class FakeProto(protocol.Protocol):
    pass

class TestCallableOverride(unittest.TestCase):
    """
    Callable values in serviceLocationOverride get to override the
    whole connecting process.
    """

    def testSimple(self):
        dn = distinguishedname.DistinguishedName('dc=example,dc=com')
        c = ldapconnector.LDAPClientCreator(reactor, FakeProto)
        def _doConnect(factory):
            factory.doStart()
            factory.startedConnecting(c)
            proto = factory.buildProtocol(address.IPv4Address('TCP', 'localhost', '1'))
        d = c.connect(dn, overrides={ dn: _doConnect, })
        def cb(r):
            self.failUnless(isinstance(r, FakeProto))
        d.addCallback(cb)
        return d

    def testFindOverride_plainString(self):
        """Plain strings work as override keys."""

        c=ldapconnector.LDAPConnector(reactor=None,