def __init__(self, stringValue=None, attributeType=None, value=None): if stringValue is None: assert attributeType is not None assert value is not None self.attributeType = to_unicode(attributeType) self.value = to_unicode(value) else: assert attributeType is None assert value is None stringValue = to_unicode(stringValue) if u'=' not in stringValue: raise InvalidRelativeDistinguishedName(stringValue) self.attributeType, self.value = stringValue.split(u'=', 1)
def __init__(self, stringValue=None, attributeType=None, value=None): if stringValue is None: assert attributeType is not None assert value is not None self.attributeType = to_unicode(attributeType) self.value = to_unicode(value) else: assert attributeType is None assert value is None stringValue = to_unicode(stringValue) if "=" not in stringValue: raise InvalidRelativeDistinguishedName(stringValue) self.attributeType, self.value = stringValue.split("=", 1)
def __init__(self, magic=None, stringValue=None, listOfRDNs=None): assert magic is not None or stringValue is not None or listOfRDNs is not None if magic is not None: assert stringValue is None assert listOfRDNs is None if isinstance(magic, DistinguishedName): listOfRDNs = magic.split() elif isinstance(magic, (bytes, str)): # This might need to be expended if we want to support # different encodings. stringValue = magic else: listOfRDNs = magic if stringValue is None: assert listOfRDNs is not None for x in listOfRDNs: assert isinstance(x, RelativeDistinguishedName) self.listOfRDNs = tuple(listOfRDNs) else: assert listOfRDNs is None self.listOfRDNs = tuple( [ RelativeDistinguishedName(stringValue=x) for x in _splitOnNotEscaped(to_unicode(stringValue), ",") ] )
def __init__(self, magic=None, stringValue=None, attributeTypesAndValues=None): if magic is not None: assert stringValue is None assert attributeTypesAndValues is None if isinstance(magic, RelativeDistinguishedName): attributeTypesAndValues = magic.split() elif isinstance(magic, (six.binary_type, six.text_type)): stringValue = magic else: attributeTypesAndValues = magic if stringValue is None: assert attributeTypesAndValues is not None assert not isinstance(attributeTypesAndValues, (six.binary_type, six.text_type)) self.attributeTypesAndValues = tuple(attributeTypesAndValues) else: assert attributeTypesAndValues is None self.attributeTypesAndValues = tuple([ LDAPAttributeTypeAndValue(stringValue=unescape(x)) for x in _splitOnNotEscaped(to_unicode(stringValue), u'+') ])
def _get(path, dn): path = to_unicode(path) dn = distinguishedname.DistinguishedName(dn) l = list(dn.split()) assert len(l) >= 1 l.reverse() parser = StoreParsedLDIF() entry = os.path.join(path, *[u'%s.dir' % rdn.getText() for rdn in l[:-1]]) entry = os.path.join(entry, u'%s.ldif' % l[-1].getText()) f = open(entry, 'rb') while 1: data = f.read(8192) if not data: break parser.dataReceived(data) parser.connectionLost(failure.Failure(error.ConnectionDone())) assert parser.done entries = parser.seen if len(entries) == 0: raise LDIFTreeEntryContainsNoEntries() elif len(entries) > 1: raise LDIFTreeEntryContainsMultipleEntries(entries) else: return entries[0]
def _put(path, entry): path = to_unicode(path) l = list(entry.dn.split()) assert len(l) >= 1 l.reverse() entryRDN = l.pop() if l: grandParent = os.path.join(path, *[u'%s.dir' % rdn.getText() for rdn in l[:-1]]) parentEntry = os.path.join(grandParent, u'%s.ldif' % l[-1].getText()) parentDir = os.path.join(grandParent, u'%s.dir' % l[-1].getText()) if not os.path.exists(parentDir): if not os.path.exists(parentEntry): raise LDIFTreeNoSuchObject(entry.dn.up()) try: os.mkdir(parentDir) except OSError as e: if e.errno == errno.EEXIST: # we lost a race to create the directory, safe to ignore pass else: raise else: parentDir = path return _putEntry(os.path.join(parentDir, u'%s' % entryRDN.getText()), entry)
def __init__(self, path, dn=None, *a, **kw): if dn is None: dn = u'' entry.BaseLDAPEntry.__init__(self, dn, *a, **kw) self.path = to_unicode(path) if self.dn != '': self._load()
def __init__(self, magic=None, stringValue=None, listOfRDNs=None): assert (magic is not None or stringValue is not None or listOfRDNs is not None) if magic is not None: assert stringValue is None assert listOfRDNs is None if isinstance(magic, DistinguishedName): listOfRDNs = magic.split() elif isinstance(magic, (six.binary_type, six.text_type)): # This might need to be expended if we want to support # different encodings. stringValue = magic else: listOfRDNs = magic if stringValue is None: assert listOfRDNs is not None for x in listOfRDNs: assert isinstance(x, RelativeDistinguishedName) self.listOfRDNs = tuple(listOfRDNs) else: assert listOfRDNs is None self.listOfRDNs = tuple([RelativeDistinguishedName(stringValue=x) for x in _splitOnNotEscaped(to_unicode(stringValue), u',')])
def _put(path, entry): path = to_unicode(path) l = list(entry.dn.split()) assert len(l) >= 1 l.reverse() entryRDN = l.pop() if l: grandParent = os.path.join( path, *[u'%s.dir' % rdn.getText() for rdn in l[:-1]]) parentEntry = os.path.join(grandParent, u'%s.ldif' % l[-1].getText()) parentDir = os.path.join(grandParent, u'%s.dir' % l[-1].getText()) if not os.path.exists(parentDir): if not os.path.exists(parentEntry): raise LDIFTreeNoSuchObject(entry.dn.up()) try: os.mkdir(parentDir) except OSError as e: if e.errno == errno.EEXIST: # we lost a race to create the directory, safe to ignore pass else: raise else: parentDir = path return _putEntry(os.path.join(parentDir, u'%s' % entryRDN.getText()), entry)
def __repr__(self): keys = sorted((key for key in self), key=to_bytes) a = [] for key in keys: a.append('%s: %s' % (repr(key), repr(list(self[key])))) attributes = ', '.join(a) dn = self.dn.toWire() if six.PY2 else to_unicode(self.dn.toWire()) return '%s(%s, {%s})' % (self.__class__.__name__, repr(dn), attributes)
def __repr__(self): dn = to_bytes(self.dn) return (self.__class__.__name__ + '(' + 'dn=%r' % (dn if six.PY2 else to_unicode(dn)) + ', ' + 'modifications=%r' % self.modifications + ')')
def parseFilter(s): """ Converting source string to pureldap.LDAPFilter Source string is converted to unicode as pyparsing cannot parse bytes objects with the rules declared in this module. """ s = to_unicode(s) try: x = toplevel.parseString(s) except ParseException as e: raise InvalidLDAPFilter(e.msg, e.loc, e.line) assert len(x) == 1 return x[0]
def parseFilter(s): """ Converting source string to pureldap.LDAPFilter Source string is converted to unicode for Python 3 as pyparsing cannot parse Python 3 byte strings with the rules declared in this module. """ s = to_unicode(s) if not six.PY2 else s try: x = toplevel.parseString(s) except ParseException as e: raise InvalidLDAPFilter(e.msg, e.loc, e.line) assert len(x) == 1 return x[0]
def __init__(self, magic=None, stringValue=None, attributeTypesAndValues=None): if magic is not None: assert stringValue is None assert attributeTypesAndValues is None if isinstance(magic, RelativeDistinguishedName): attributeTypesAndValues = magic.split() elif isinstance(magic, (six.binary_type, six.text_type)): stringValue = magic else: attributeTypesAndValues = magic if stringValue is None: assert attributeTypesAndValues is not None assert not isinstance(attributeTypesAndValues, (six.binary_type, six.text_type)) self.attributeTypesAndValues = tuple(attributeTypesAndValues) else: assert attributeTypesAndValues is None self.attributeTypesAndValues = tuple([LDAPAttributeTypeAndValue(stringValue=unescape(x)) for x in _splitOnNotEscaped(to_unicode(stringValue), u'+')])
def __repr__(self): dn = to_bytes(self.dn) return (self.__class__.__name__ + '(' + '%r' % (dn if six.PY2 else to_unicode(dn)) + ')')