From 6d72715629a9b4d4be666139dd5e9c9126ea8bfa Mon Sep 17 00:00:00 2001 From: James Robinson Date: Sat, 24 Feb 2024 00:57:06 +0000 Subject: [PATCH] :alien: Add patched version of LDAPString to workaround TypeError on LDAP filtering in the upstream library --- apricot/__init__.py | 1 + apricot/patches/__init__.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 apricot/patches/__init__.py diff --git a/apricot/__init__.py b/apricot/__init__.py index 201e2e7..0a47852 100644 --- a/apricot/__init__.py +++ b/apricot/__init__.py @@ -1,5 +1,6 @@ from .__about__ import __version__, __version_info__ from .apricot_server import ApricotServer +from .patches import LDAPString # noqa: F401 __all__ = [ "__version__", diff --git a/apricot/patches/__init__.py b/apricot/patches/__init__.py new file mode 100644 index 0000000..1150918 --- /dev/null +++ b/apricot/patches/__init__.py @@ -0,0 +1,15 @@ +"""Patch LDAPString to avoid TypeError when parsing LDAP filter strings""" + +from ldaptor.protocols.pureldap import LDAPString + +old_init = LDAPString.__init__ + + +def patched_init(self, *k, **kw): + """Patch LDAPString init to store its value as 'str' not 'bytes'""" + old_init(self, *k, **kw) + if isinstance(self.value, bytes): + self.value = self.value.decode() + + +LDAPString.__init__ = patched_init