From 5fcccd5c52415dc4a72a65890b6463dbc436b210 Mon Sep 17 00:00:00 2001 From: stroeder Date: Thu, 28 Jul 2011 08:57:12 +0000 Subject: [PATCH] Class attributes in doc strings --- Lib/ldap/controls/readentry.py | 90 ++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 Lib/ldap/controls/readentry.py diff --git a/Lib/ldap/controls/readentry.py b/Lib/ldap/controls/readentry.py new file mode 100644 index 0000000..19ba9d5 --- /dev/null +++ b/Lib/ldap/controls/readentry.py @@ -0,0 +1,90 @@ +#!/usr/bin/env python +""" +ldap.controls.readentry - classes for the Read Entry controls +(see RFC 4527) + +See http://www.python-ldap.org/ for project details. + +$Id: readentry.py,v 1.4 2011/07/28 08:57:12 stroeder Exp $ +""" + +import ldap + +from pyasn1.codec.ber import encoder,decoder +from ldap.controls import LDAPControl,KNOWN_RESPONSE_CONTROLS + +from pyasn1_modules.rfc2251 import AttributeDescriptionList,SearchResultEntry + + +class ReadEntryControl(LDAPControl): + """ + Base class for read entry control described in RFC 4527 + + attrList + list of attribute type names requested + + Class attributes with values extracted from the response control: + + dn + string holding the distinguished name of the LDAP entry + entry + dictionary holding the LDAP entry + """ + + def __init__(self,criticality=False,attrList=None): + self.criticality,self.attrList,self.entry = criticality,attrList or [],None + + def encodeControlValue(self): + attributeSelection = AttributeDescriptionList() + for i in range(len(self.attrList)): + attributeSelection.setComponentByPosition(i,self.attrList[i]) + return encoder.encode(attributeSelection) + + def decodeControlValue(self,encodedControlValue): + decodedEntry,_ = decoder.decode(encodedControlValue,asn1Spec=SearchResultEntry()) + self.dn = str(decodedEntry[0]) + self.entry = {} + for attr in decodedEntry[1]: + self.entry[str(attr[0])] = [ str(attr_value) for attr_value in attr[1] ] + + +class PreReadControl(ReadEntryControl): + """ + Class for pre-read control described in RFC 4527 + + attrList + list of attribute type names requested + + Class attributes with values extracted from the response control: + + dn + string holding the distinguished name of the LDAP entry + before the operation was done by the server + entry + dictionary holding the LDAP entry + before the operation was done by the server + """ + controlType = ldap.CONTROL_PRE_READ + +KNOWN_RESPONSE_CONTROLS[PreReadControl.controlType] = PreReadControl + + +class PostReadControl(ReadEntryControl): + """ + Class for post-read control described in RFC 4527 + + attrList + list of attribute type names requested + + Class attributes with values extracted from the response control: + + dn + string holding the distinguished name of the LDAP entry + after the operation was done by the server + entry + dictionary holding the LDAP entry + after the operation was done by the server + """ + controlType = ldap.CONTROL_POST_READ + +KNOWN_RESPONSE_CONTROLS[PostReadControl.controlType] = PostReadControl