From e8eb3eeb9cd48a0be785fa53d7d1e2a91a3b5935 Mon Sep 17 00:00:00 2001 From: stroeder Date: Sun, 19 Nov 2017 00:10:42 +0000 Subject: [PATCH] a bit of PEP-8 for ldap.sasl --- Lib/ldap/sasl.py | 71 +++++++++++++++++++++++++++--------------------- 1 file changed, 40 insertions(+), 31 deletions(-) diff --git a/Lib/ldap/sasl.py b/Lib/ldap/sasl.py index 77d8ee2..d67153d 100644 --- a/Lib/ldap/sasl.py +++ b/Lib/ldap/sasl.py @@ -15,18 +15,19 @@ from ldap import __version__ if __debug__: - # Tracing is only supported in debugging mode - import traceback - from ldap import _trace_level,_trace_file,_trace_stack_limit + # Tracing is only supported in debugging mode + from ldap import _trace_level, _trace_file + # These are the SASL callback id's , as defined in sasl.h -CB_USER = 0x4001 -CB_AUTHNAME = 0x4002 -CB_LANGUAGE = 0x4003 -CB_PASS = 0x4004 -CB_ECHOPROMPT = 0x4005 -CB_NOECHOPROMPT= 0x4006 -CB_GETREALM = 0x4008 +CB_USER = 0x4001 +CB_AUTHNAME = 0x4002 +CB_LANGUAGE = 0x4003 +CB_PASS = 0x4004 +CB_ECHOPROMPT = 0x4005 +CB_NOECHOPROMPT = 0x4006 +CB_GETREALM = 0x4008 + class sasl: """This class handles SASL interactions for authentication. @@ -35,7 +36,7 @@ class sasl: specific SASL authentication mechanisms, this method can be overridden""" - def __init__(self,cb_value_dict,mech): + def __init__(self, cb_value_dict, mech): """ The (generic) base class takes a cb_value_dictionary of question-answer pairs. Questions are specified by the respective SASL callback id's. The mech argument is a string that specifies @@ -43,7 +44,7 @@ def __init__(self,cb_value_dict,mech): self.cb_value_dict = cb_value_dict or {} self.mech = mech - def callback(self,cb_id,challenge,prompt,defresult): + def callback(self, cb_id, challenge, prompt, defresult): """ The callback method will be called by the sasl_bind_s() method several times. Each time it will provide the id, which tells us what kind of information is requested (the CB_ ... @@ -61,46 +62,54 @@ def callback(self,cb_id,challenge,prompt,defresult): # The following print command might be useful for debugging # new sasl mechanisms. So it is left here - cb_result = self.cb_value_dict.get(cb_id,defresult) or '' + cb_result = self.cb_value_dict.get(cb_id, defresult) or '' if __debug__: - if _trace_level>=1: - _trace_file.write("*** id=%d, challenge=%s, prompt=%s, defresult=%s\n-> %s\n" % ( - cb_id, challenge, prompt, repr(defresult), repr(self.cb_value_dict.get(cb_result)) - )) + if _trace_level >= 1: + _trace_file.write("*** id=%d, challenge=%s, prompt=%s, defresult=%s\n-> %s\n" % ( + cb_id, + challenge, + prompt, + repr(defresult), + repr(self.cb_value_dict.get(cb_result)) + )) return cb_result class cram_md5(sasl): """This class handles SASL CRAM-MD5 authentication.""" - def __init__(self,authc_id, password, authz_id=""): - auth_dict = {CB_AUTHNAME:authc_id, CB_PASS:password, - CB_USER:authz_id} - sasl.__init__(self,auth_dict,"CRAM-MD5") + def __init__(self, authc_id, password, authz_id=""): + auth_dict = { + CB_AUTHNAME: authc_id, + CB_PASS: password, + CB_USER: authz_id, + } + sasl.__init__(self, auth_dict, "CRAM-MD5") class digest_md5(sasl): """This class handles SASL DIGEST-MD5 authentication.""" - def __init__(self,authc_id, password, authz_id=""): - auth_dict = {CB_AUTHNAME:authc_id, CB_PASS:password, - CB_USER:authz_id} - sasl.__init__(self,auth_dict,"DIGEST-MD5") + def __init__(self, authc_id, password, authz_id=""): + auth_dict = { + CB_AUTHNAME: authc_id, + CB_PASS: password, + CB_USER: authz_id, + } + sasl.__init__(self, auth_dict, "DIGEST-MD5") class gssapi(sasl): """This class handles SASL GSSAPI (i.e. Kerberos V) authentication.""" - def __init__(self,authz_id=""): - sasl.__init__(self, {CB_USER:authz_id},"GSSAPI") + def __init__(self, authz_id=""): + sasl.__init__(self, {CB_USER: authz_id}, "GSSAPI") class external(sasl): """This class handles SASL EXTERNAL authentication (i.e. X.509 client certificate)""" - def __init__(self,authz_id=""): - sasl.__init__(self, {CB_USER:authz_id},"EXTERNAL") - - + def __init__(self, authz_id=""): + sasl.__init__(self, {CB_USER: authz_id}, "EXTERNAL")