async def add(self, entry, attributes): try: req = { 'entry': entry.encode(), 'attributes': encode_attributes(attributes) } br = {'addRequest': AddRequest(req)} msg = {'protocolOp': protocolOp(br)} msg_id = await self.send_message(msg) results = await self.recv_message(msg_id) if isinstance(results[0], Exception): return False, results[0] for message in results: msg_type = message['protocolOp'].name message = message.native if msg_type == 'addResponse': if message['protocolOp']['resultCode'] != 'success': return False, Exception( 'Failed to add DN! LDAP error! Reason: %s Diag: %s' % (message['protocolOp']['resultCode'], message['protocolOp']['diagnosticMessage'])) return True, None except Exception as e: return False, e
async def add(self, entry, attributes): """ Performs the add operation. :param entry: The DN of the object to be added :type entry: str :param attributes: Attributes to be used in the operation :type attributes: dict :return: A tuple of (True, None) on success or (False, Exception) on error. :rtype: (:class:`bool`, :class:`Exception`) """ try: req = { 'entry' : entry.encode(), 'attributes' : encode_attributes(attributes) } br = { 'addRequest' : AddRequest(req)} msg = { 'protocolOp' : protocolOp(br)} msg_id = await self.send_message(msg) results = await self.recv_message(msg_id) if isinstance(results[0], Exception): return False, results[0] for message in results: msg_type = message['protocolOp'].name message = message.native if msg_type == 'addResponse': if message['protocolOp']['resultCode'] != 'success': return False, LDAPAddException( entry, message['protocolOp']['resultCode'], message['protocolOp']['diagnosticMessage'] ) return True, None except Exception as e: return False, e