# Path: ldaptor/protocols/ldap/ldifprotocol.py
# class LDIFParseError(Exception):
# class LDIFLineWithoutSemicolonError(LDIFParseError):
# class LDIFEntryStartsWithNonDNError(LDIFParseError):
# class LDIFEntryStartsWithSpaceError(LDIFParseError):
# class LDIFVersionNotANumberError(LDIFParseError):
# class LDIFUnsupportedVersionError(LDIFParseError):
# class LDIFTruncatedError(LDIFParseError):
# class LDIF(object, basic.LineReceiver):
#     def __str__(self):
#     def logicalLineReceived(self, line):
#     def lineReceived(self, line):
#     def parseValue(self, val):
#     def _parseLine(self, line):
#     def state_HEADER(self, line):
#     def state_WAIT_FOR_DN(self, line):
#     def state_IN_ENTRY(self, line):
#     def gotEntry(self, obj):
#     def connectionLost(self, reason=protocol.connectionDone):
# HEADER = 'HEADER'
# WAIT_FOR_DN = 'WAIT_FOR_DN'
# IN_ENTRY = 'IN_ENTRY'
# 
# 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 ldaptor.protocols.ldap import ldifprotocol, distinguishedname
import sets
cn:foo
avalue:a
aValUe:b

""")

        self.failUnlessEqual(len(proto.listOfCompleted), 1)

        o = proto.listOfCompleted.pop(0)
        self.failUnlessEqual(str(o.dn), 'cn=foo,dc=example,dc=com')
        self.failUnlessEqual(o['objectClass'], ['a', 'b'])
        self.failUnlessEqual(o['CN'], ['foo'])
        self.failUnlessEqual(o['aValue'], ['a', 'b'])

        self.failUnlessEqual(proto.listOfCompleted, [])

    def testTruncatedFailure(self):
        proto = LDIFDriver()
        proto.dataReceived("""\
version: 1
dn: cn=foo,dc=example,dc=com
objectClass: a
objectClass: b
aValue: a
aValue: b
bValue: c
""")

        self.failUnlessEqual(len(proto.listOfCompleted), 0)


# Path: ldaptor/protocols/ldap/ldifprotocol.py
# class LDIFParseError(Exception):
# class LDIFLineWithoutSemicolonError(LDIFParseError):
# class LDIFEntryStartsWithNonDNError(LDIFParseError):
# class LDIFEntryStartsWithSpaceError(LDIFParseError):
# class LDIFVersionNotANumberError(LDIFParseError):
# class LDIFUnsupportedVersionError(LDIFParseError):
# class LDIFTruncatedError(LDIFParseError):
# class LDIF(object, basic.LineReceiver):
#     def __str__(self):
#     def logicalLineReceived(self, line):
#     def lineReceived(self, line):
#     def parseValue(self, val):
#     def _parseLine(self, line):
#     def state_HEADER(self, line):
#     def state_WAIT_FOR_DN(self, line):
#     def state_IN_ENTRY(self, line):
#     def gotEntry(self, obj):
#     def connectionLost(self, reason=protocol.connectionDone):
# HEADER = 'HEADER'
# WAIT_FOR_DN = 'WAIT_FOR_DN'
# IN_ENTRY = 'IN_ENTRY'
# 
# 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_ldifprotocol.py
from twisted.trial import unittest
from ldaptor.protocols.ldap import ldifprotocol, distinguishedname
import sets

cn:foo
avalue:a
aValUe:b

""")

        self.failUnlessEqual(len(proto.listOfCompleted), 1)

        o = proto.listOfCompleted.pop(0)
        self.failUnlessEqual(str(o.dn), 'cn=foo,dc=example,dc=com')
        self.failUnlessEqual(o['objectClass'], ['a', 'b'])
        self.failUnlessEqual(o['CN'], ['foo'])
        self.failUnlessEqual(o['aValue'], ['a', 'b'])

        self.failUnlessEqual(proto.listOfCompleted, [])

    def testTruncatedFailure(self):
        proto = LDIFDriver()
        proto.dataReceived("""\
version: 1
dn: cn=foo,dc=example,dc=com
objectClass: a
objectClass: b
aValue: a
aValue: b
bValue: c
""")

        self.failUnlessEqual(len(proto.listOfCompleted), 0)


        self.assertRaises(ldifprotocol.LDIFTruncatedError,