Skip to content

Commit fa1f5e4

Browse files
author
stroeder
committed
a bit of PEP-8 for ldap.__init__
1 parent c4388b5 commit fa1f5e4

File tree

1 file changed

+86
-64
lines changed

1 file changed

+86
-64
lines changed

Lib/ldap/__init__.py

Lines changed: 86 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -6,95 +6,117 @@
66

77
# This is also the overall release version number
88

9-
from pkginfo import __version__, __author__, __license__
10-
119
import sys
1210

13-
if __debug__:
14-
# Tracing is only supported in debugging mode
15-
import traceback
16-
_trace_level = 0
17-
_trace_file = sys.stderr
18-
_trace_stack_limit = None
11+
from ldap.pkginfo import __version__, __author__, __license__
1912

20-
from ldap.pkginfo import __version__
13+
if __debug__:
14+
# Tracing is only supported in debugging mode
15+
import traceback
16+
_trace_level = 0
17+
_trace_file = sys.stderr
18+
_trace_stack_limit = None
2119

2220
import _ldap
23-
assert _ldap.__version__==__version__, \
24-
ImportError('ldap %s and _ldap %s version mismatch!' % (__version__,_ldap.__version__))
21+
assert _ldap.__version__ == __version__, ImportError(
22+
'ldap %s and _ldap %s version mismatch!' % (__version__, _ldap.__version__)
23+
)
2524
from _ldap import *
2625
# call into libldap to initialize it right now
26+
from functions import open, initialize, init, get_option, set_option
27+
from functions import escape_str, strf_secs, strp_secs
28+
from ldapobject import NO_UNIQUE_ENTRY
29+
from ldap.dn import explode_dn, explode_rdn
30+
31+
2732
LIBLDAP_API_INFO = _ldap.get_option(_ldap.OPT_API_INFO)
2833

2934
OPT_NAMES_DICT = {}
30-
for k,v in vars(_ldap).items():
31-
if k.startswith('OPT_'):
32-
OPT_NAMES_DICT[v]=k
35+
for key, val in vars(_ldap).items():
36+
if key.startswith('OPT_'):
37+
OPT_NAMES_DICT[val] = key
38+
3339

3440
class DummyLock:
35-
"""Define dummy class with methods compatible to threading.Lock"""
36-
def __init__(self):
37-
pass
38-
def acquire(self):
39-
pass
40-
def release(self):
41-
pass
41+
"""
42+
Define dummy class with methods compatible to threading.Lock
43+
"""
44+
45+
def __init__(self):
46+
pass
47+
48+
def acquire(self):
49+
"""
50+
dummy
51+
"""
52+
pass
53+
54+
def release(self):
55+
"""
56+
dummy
57+
"""
58+
pass
59+
4260

4361
try:
44-
# Check if Python installation was build with thread support
45-
import thread
62+
# Check if Python installation was build with thread support
63+
import thread
4664
except ImportError:
47-
LDAPLockBaseClass = DummyLock
65+
LDAPLockBaseClass = DummyLock
4866
else:
49-
import threading
50-
LDAPLockBaseClass = threading.Lock
67+
import threading
68+
LDAPLockBaseClass = threading.Lock
5169

5270

53-
class LDAPLock:
54-
"""
55-
Mainly a wrapper class to log all locking events.
56-
Note that this cumbersome approach with _lock attribute was taken
57-
since threading.Lock is not suitable for sub-classing.
58-
"""
59-
_min_trace_level = 3
60-
61-
def __init__(self,lock_class=None,desc=''):
71+
class LDAPLock(object):
6272
"""
63-
lock_class
64-
Class compatible to threading.Lock
65-
desc
66-
Description shown in debug log messages
73+
Mainly a wrapper class to log all locking events.
74+
Note that this cumbersome approach with _lock attribute was taken
75+
since threading.Lock is not suitable for sub-classing.
6776
"""
68-
self._desc = desc
69-
self._lock = (lock_class or LDAPLockBaseClass)()
70-
71-
def acquire(self):
72-
if __debug__:
73-
global _trace_level
74-
if _trace_level>=self._min_trace_level:
75-
_trace_file.write('***%s.acquire() %s %s\n' % (self.__class__.__name__,repr(self),self._desc))
76-
return self._lock.acquire()
77-
78-
def release(self):
79-
if __debug__:
80-
global _trace_level
81-
if _trace_level>=self._min_trace_level:
82-
_trace_file.write('***%s.release() %s %s\n' % (self.__class__.__name__,repr(self),self._desc))
83-
return self._lock.release()
77+
_min_trace_level = 3
78+
79+
def __init__(self, lock_class=None, desc='', trace_level=None):
80+
"""
81+
lock_class
82+
Class compatible to threading.Lock
83+
desc
84+
Description shown in debug log messages
85+
"""
86+
self._desc = desc
87+
self._lock = (lock_class or LDAPLockBaseClass)()
88+
if trace_level is not None:
89+
self._min_trace_level = trace_level
90+
91+
def acquire(self):
92+
"""
93+
acquire lock and log
94+
"""
95+
if __debug__:
96+
global _trace_level
97+
if _trace_level >= self._min_trace_level:
98+
_trace_file.write('***%s.acquire() %r %s\n' % (
99+
self.__class__.__name__, self, self._desc
100+
))
101+
return self._lock.acquire()
102+
103+
def release(self):
104+
"""
105+
release lock and log
106+
"""
107+
if __debug__:
108+
global _trace_level
109+
if _trace_level >= self._min_trace_level:
110+
_trace_file.write('***%s.release() %r %s\n' % (
111+
self.__class__.__name__, self, self._desc
112+
))
113+
return self._lock.release()
84114

85115

86116
# Create module-wide lock for serializing all calls into underlying LDAP lib
87117
_ldap_module_lock = LDAPLock(desc='Module wide')
88118

89-
from functions import open,initialize,init,get_option,set_option,escape_str,strf_secs,strp_secs
90-
91-
from ldapobject import NO_UNIQUE_ENTRY
92-
93-
from ldap.dn import explode_dn,explode_rdn,str2dn,dn2str
94-
del str2dn
95-
del dn2str
96-
97119
# More constants
98120

99121
# For compability of 2.3 and 2.4 OpenLDAP API
100-
OPT_DIAGNOSTIC_MESSAGE = OPT_ERROR_STRING
122+
OPT_DIAGNOSTIC_MESSAGE = _ldap.OPT_ERROR_STRING

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy