Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
fd664e8
[python-ldap] Remove compatibility wrappers for Py2/Py3
Alphix Jan 26, 2024
24ba7dc
[python-ldap] Make __version__ imports more consistent
Alphix Jan 26, 2024
521edad
[python-ldap] Type fixes for Lib/ldap/__init__.py
Alphix Jan 26, 2024
e978e18
[python-ldap] Type fixes for Lib/ldap/asyncsearch.py
Alphix Jan 26, 2024
60858e7
[python-ldap] Type fixes for Lib/ldap/cidict.py
Alphix Jan 26, 2024
7e7b508
[python-ldap] Type fixes for Lib/ldap/constants.py
Alphix Jan 26, 2024
c61ec81
[python-ldap] Type fixes for Lib/ldap/controls/psearch.py
Alphix Jan 26, 2024
052005e
[python-ldap] Type fixes for Lib/ldap/controls/psearch.py
Alphix Jan 26, 2024
77526a6
[python-ldap] Type fixes for Lib/ldap/controls/simple.py
Alphix Jan 26, 2024
56c6e9a
[python-ldap] Type fixes for Lib/ldap/controls/sss.py
Alphix Jan 26, 2024
4ca3ad6
[python-ldap] Type fixes for Lib/ldap/extop/__init__.py
Alphix Jan 26, 2024
b1222c9
[python-ldap] Type fixes for Lib/ldap/modlist.py
Alphix Jan 26, 2024
b5822c9
[python-ldap] Type fixes for Lib/ldap/resiter.py
Alphix Jan 26, 2024
d0ee8e7
[python-ldap] Type fixes for Lib/ldap/sasl.py
Alphix Jan 26, 2024
7aa6386
[python-ldap] Type fixes for Lib/ldap/syncrepl.py
Alphix Jan 27, 2024
4e903ff
[python-ldap] Type fixes for Lib/ldapurl.py
Alphix Jan 27, 2024
5234a44
[python-ldap] Type fixes for Lib/slaptest/*
Alphix Jan 27, 2024
536e8e4
[python-ldap] Type fixes for Lib/ldif.py
Alphix Jan 27, 2024
dee3ac2
[python-ldap] Type fixes for Lib/ldap/ldapobject.py
Alphix Jan 27, 2024
13eee1b
[python-ldap] Type fixes for Lib/ldap/schema/subentry.py
Alphix Jan 27, 2024
7fa9d15
[python-ldap] Type fixes for Lib/ldap/schema/models.py
Alphix Jan 27, 2024
23646cb
[python-ldap] Type fixes for Lib/ldap/controls/openldap.py
Alphix Jan 27, 2024
6a5ed0c
[python-ldap] Type fixes for Lib/ldap/controls/pagedresults.py
Alphix Jan 27, 2024
bf70305
[python-ldap] Type fixes for Lib/ldap/extop/__init__.py
Alphix Jan 27, 2024
90e1248
[python-ldap] Improve documentation in Lib/ldap/dn.py
Alphix Jan 27, 2024
ed5f796
[python-ldap] Correct KNOWN_RESPONSE_CONTROLS registration in Lib/lda…
Alphix Jan 27, 2024
84a1c18
[python-ldap] Add type annotations
Alphix Jan 27, 2024
ea6b625
[python-ldap] Integrate typing into the build/CI system
Alphix Jan 27, 2024
d7699f8
[python-ldap] Move _ldap to ldap._ldap
Alphix Jan 30, 2024
2726abc
[python-ldap] Add stubtest to typing CI
Alphix Jan 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Doc/fake_ldap_module_for_documentation.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
"""
A module that mocks `_ldap` for the purposes of generating documentation
A module that mocks `ldap._ldap` for the purposes of generating documentation

This module provides placeholders for the contents of `_ldap`, making it
possible to generate documentation even _ldap is not compiled.
This module provides placeholders for the contents of `ldap._ldap`, making it
possible to generate documentation even if ldap._ldap is not compiled.
It should also make the documentation independent of which features are
available in the system OpenLDAP library.

The overly long module name will show up in AttributeError messages,
hinting that this is not the actual _ldap.
hinting that this is not the actual ldap._ldap.

See https://www.python-ldap.org/ for details.
"""

import sys

# Cause `import _ldap` to import this module instead of the actual `_ldap`.
sys.modules['_ldap'] = sys.modules[__name__]
# Cause `import ldap._ldap` to import this module instead of the actual module.
sys.modules['ldap._ldap'] = sys.modules[__name__]

from constants import CONSTANTS
from pkginfo import __version__
Expand Down
38 changes: 24 additions & 14 deletions Lib/ldap/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,19 @@
import os
import sys

from typing import Any, Type, Optional, Union


if __debug__:
# Tracing is only supported in debugging mode
import atexit
import traceback
_trace_level = int(os.environ.get("PYTHON_LDAP_TRACE_LEVEL", 0))
_trace_file = os.environ.get("PYTHON_LDAP_TRACE_FILE")
if _trace_file is None:
_trace_file_path = os.environ.get("PYTHON_LDAP_TRACE_FILE")
if _trace_file_path is None:
_trace_file = sys.stderr
else:
_trace_file = open(_trace_file, 'a')
_trace_file = open(_trace_file_path, 'a')
atexit.register(_trace_file.close)
_trace_stack_limit = None
else:
Expand All @@ -31,10 +34,10 @@
_trace_file = sys.stderr
_trace_stack_limit = None

import _ldap
import ldap._ldap as _ldap
assert _ldap.__version__==__version__, \
ImportError(f'ldap {__version__} and _ldap {_ldap.__version__} version mismatch!')
from _ldap import *
from ldap._ldap import *
# call into libldap to initialize it right now
LIBLDAP_API_INFO = _ldap.get_option(_ldap.OPT_API_INFO)

Expand All @@ -45,18 +48,21 @@

class DummyLock:
"""Define dummy class with methods compatible to threading.Lock"""
def __init__(self):
pass
def acquire(self):
def __init__(self) -> None:
pass
def release(self):

def acquire(self) -> bool:
return True

def release(self) -> None:
pass

try:
# Check if Python installation was build with thread support
# FIXME: This can be simplified, from Python 3.7 this module is mandatory
import threading
except ImportError:
LDAPLockBaseClass = DummyLock
LDAPLockBaseClass: Union[Type[DummyLock], Type[threading.Lock]] = DummyLock
else:
LDAPLockBaseClass = threading.Lock

Expand All @@ -69,7 +75,11 @@ class LDAPLock:
"""
_min_trace_level = 3

def __init__(self,lock_class=None,desc=''):
def __init__(
self,
lock_class: Optional[Type[Any]] = None,
desc: str = ''
) -> None:
"""
lock_class
Class compatible to threading.Lock
Expand All @@ -79,19 +89,19 @@ def __init__(self,lock_class=None,desc=''):
self._desc = desc
self._lock = (lock_class or LDAPLockBaseClass)()

def acquire(self):
def acquire(self) -> bool:
if __debug__:
global _trace_level
if _trace_level>=self._min_trace_level:
_trace_file.write('***{}.acquire() {} {}\n'.format(self.__class__.__name__,repr(self),self._desc))
return self._lock.acquire()

def release(self):
def release(self) -> None:
if __debug__:
global _trace_level
if _trace_level>=self._min_trace_level:
_trace_file.write('***{}.release() {} {}\n'.format(self.__class__.__name__,repr(self),self._desc))
return self._lock.release()
self._lock.release()


# Create module-wide lock for serializing all calls into underlying LDAP lib
Expand Down
Loading