From 9ff0d6290735dd6249534bb9adeddb6505a665df Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 3 Feb 2025 22:47:53 +0000 Subject: [PATCH 1/2] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/asottile/pyupgrade: v2.26.0 → v3.19.1](https://github.com/asottile/pyupgrade/compare/v2.26.0...v3.19.1) - [github.com/psf/black: 21.9b0 → 25.1.0](https://github.com/psf/black/compare/21.9b0...25.1.0) - [github.com/PyCQA/flake8: 3.9.2 → 7.1.1](https://github.com/PyCQA/flake8/compare/3.9.2...7.1.1) - [github.com/pre-commit/pygrep-hooks: v1.9.0 → v1.10.0](https://github.com/pre-commit/pygrep-hooks/compare/v1.9.0...v1.10.0) - [github.com/pre-commit/pre-commit-hooks: v4.0.1 → v5.0.0](https://github.com/pre-commit/pre-commit-hooks/compare/v4.0.1...v5.0.0) - [github.com/pre-commit/mirrors-prettier: v2.4.1 → v4.0.0-alpha.8](https://github.com/pre-commit/mirrors-prettier/compare/v2.4.1...v4.0.0-alpha.8) - https://github.com/myint/autoflake → https://github.com/PyCQA/autoflake - [github.com/PyCQA/autoflake: v1.4 → v2.3.1](https://github.com/PyCQA/autoflake/compare/v1.4...v2.3.1) - [github.com/mgedmin/check-manifest: 0.46 → 0.50](https://github.com/mgedmin/check-manifest/compare/0.46...0.50) --- .pre-commit-config.yaml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index af767812..aa3ec931 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,29 +3,29 @@ ci: repos: - repo: https://github.com/asottile/pyupgrade - rev: v2.26.0 + rev: v3.19.1 hooks: - id: pyupgrade args: ["--py36-plus"] - repo: https://github.com/psf/black - rev: 21.9b0 + rev: 25.1.0 hooks: - id: black args: ["--target-version", "py36"] - repo: https://github.com/PyCQA/flake8 - rev: 3.9.2 + rev: 7.1.1 hooks: - id: flake8 - repo: https://github.com/pre-commit/pygrep-hooks - rev: v1.9.0 + rev: v1.10.0 hooks: - id: python-check-blanket-noqa - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.0.1 + rev: v5.0.0 hooks: - id: check-merge-conflict - id: check-toml @@ -33,13 +33,13 @@ repos: - id: mixed-line-ending - repo: https://github.com/pre-commit/mirrors-prettier - rev: v2.4.1 + rev: v4.0.0-alpha.8 hooks: - id: prettier args: [--prose-wrap=always, --print-width=88] - - repo: https://github.com/myint/autoflake - rev: v1.4 + - repo: https://github.com/PyCQA/autoflake + rev: v2.3.1 hooks: - id: autoflake args: @@ -50,6 +50,6 @@ repos: - --remove-unused-variables - repo: https://github.com/mgedmin/check-manifest - rev: "0.46" + rev: "0.50" hooks: - id: check-manifest From a721d825fdeb99cf3b1a3ecf9db76b033cb2ba62 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 3 Feb 2025 22:49:32 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- SECURITY.md | 9 ++++++--- docs/source/examples/ldaptor_basic.py | 6 +++--- ldaptor/__init__.py | 1 + ldaptor/_encoder.py | 2 +- ldaptor/_scripts/ldap2dhcpconf.py | 2 +- ldaptor/dns.py | 4 ++-- ldaptor/ldiftree.py | 1 + ldaptor/protocols/ldap/ldapsyntax.py | 1 + ldaptor/protocols/ldap/merger.py | 8 ++++---- ldaptor/protocols/ldap/proxybase.py | 1 + ldaptor/test/test_attributeset.py | 1 + ldaptor/test/test_autofill_samba.py | 1 + ldaptor/test/test_encoder.py | 2 +- ldaptor/test/test_examples.py | 1 + ldaptor/test/test_inmemory.py | 1 + ldaptor/test/test_ldapclient.py | 1 + ldaptor/test/test_ldaperrors.py | 2 +- ldaptor/test/test_ldif.py | 6 +++--- ldaptor/test/test_match.py | 1 + ldaptor/test/test_proxybase.py | 1 + ldaptor/test/test_pureber.py | 5 +++-- ldaptor/test/test_pureldap.py | 9 +++++---- ldaptor/test/test_server.py | 1 + ldaptor/test/test_usage.py | 1 + ldaptor/usage.py | 1 + 25 files changed, 44 insertions(+), 25 deletions(-) diff --git a/SECURITY.md b/SECURITY.md index 95172e2c..6020438d 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -1,7 +1,10 @@ # Security Policy -twisted/ldaptor project uses the same security policy as [twisted/twisted](https://github.com/twisted/twisted). +twisted/ldaptor project uses the same security policy as +[twisted/twisted](https://github.com/twisted/twisted). -For more details please check the [Twisted security process](https://github.com/twisted/twisted?tab=security-ov-file#readme) +For more details please check the +[Twisted security process](https://github.com/twisted/twisted?tab=security-ov-file#readme) -You can send a security report via [GitHub Security Advisories](https://github.com/twisted/ldaptor/security/advisories/new) +You can send a security report via +[GitHub Security Advisories](https://github.com/twisted/ldaptor/security/advisories/new) diff --git a/docs/source/examples/ldaptor_basic.py b/docs/source/examples/ldaptor_basic.py index d4e6d52e..464dbe45 100644 --- a/docs/source/examples/ldaptor_basic.py +++ b/docs/source/examples/ldaptor_basic.py @@ -1,9 +1,9 @@ #! /usr/bin/env python """ - Testing a simple ldaptor ldap server - Base on an example by Gaston TJEBBES aka "tonthon": - http://tonthon.blogspot.com/2011/02/ldaptor-ldap-with-twisted-server-side.html +Testing a simple ldaptor ldap server +Base on an example by Gaston TJEBBES aka "tonthon": +http://tonthon.blogspot.com/2011/02/ldaptor-ldap-with-twisted-server-side.html """ import tempfile, sys diff --git a/ldaptor/__init__.py b/ldaptor/__init__.py index ac6a38d7..296fe3a9 100644 --- a/ldaptor/__init__.py +++ b/ldaptor/__init__.py @@ -1,4 +1,5 @@ """A Pure-Python Twisted library for LDAP""" + __version__ = "21.2.1.dev0" __title__ = "ldaptor" diff --git a/ldaptor/_encoder.py b/ldaptor/_encoder.py index eb540d15..10df81e6 100644 --- a/ldaptor/_encoder.py +++ b/ldaptor/_encoder.py @@ -1,5 +1,5 @@ """ - Encoding / decoding utilities +Encoding / decoding utilities """ import warnings diff --git a/ldaptor/_scripts/ldap2dhcpconf.py b/ldaptor/_scripts/ldap2dhcpconf.py index a589e02c..992e8d2e 100644 --- a/ldaptor/_scripts/ldap2dhcpconf.py +++ b/ldaptor/_scripts/ldap2dhcpconf.py @@ -30,7 +30,7 @@ def my_aton_numbits(num): n = 0 while num > 0: n >>= 1 - n |= 2 ** 31 + n |= 2**31 num -= 1 return n diff --git a/ldaptor/dns.py b/ldaptor/dns.py index 0005e93e..710b3824 100644 --- a/ldaptor/dns.py +++ b/ldaptor/dns.py @@ -13,7 +13,7 @@ def aton_numbits(num): n = 0 while num > 0: n >>= 1 - n |= 2 ** 31 + n |= 2**31 num -= 1 return n @@ -35,7 +35,7 @@ def ntoa(n): def netmaskToNumbits(netmask): bits = aton(netmask) - i = 2 ** 31 + i = 2**31 n = 0 while bits and i > 0: if (bits & i) == 0: diff --git a/ldaptor/ldiftree.py b/ldaptor/ldiftree.py index c97738c1..7d2dff0a 100644 --- a/ldaptor/ldiftree.py +++ b/ldaptor/ldiftree.py @@ -1,6 +1,7 @@ """ Manage LDAP data as a tree of LDIF files. """ + import errno import os import uuid diff --git a/ldaptor/protocols/ldap/ldapsyntax.py b/ldaptor/protocols/ldap/ldapsyntax.py index 120e3411..1760d9f5 100644 --- a/ldaptor/protocols/ldap/ldapsyntax.py +++ b/ldaptor/protocols/ldap/ldapsyntax.py @@ -1,4 +1,5 @@ """Pythonic API for LDAP operations.""" + import functools from twisted.internet import defer diff --git a/ldaptor/protocols/ldap/merger.py b/ldaptor/protocols/ldap/merger.py index 7efc7573..6fb88fa3 100644 --- a/ldaptor/protocols/ldap/merger.py +++ b/ldaptor/protocols/ldap/merger.py @@ -1,7 +1,7 @@ """LDAP protocol server, which acts as a proxy which - forwards the requests to multiple LDAP servers and - merges the results. - Only Bind and Search requests are supported. +forwards the requests to multiple LDAP servers and +merges the results. +Only Bind and Search requests are supported. """ from twisted.internet import reactor, defer @@ -82,7 +82,7 @@ def queue(self, id, op): def connectionMade(self): clientCreator = ldapconnector.LDAPClientCreator(reactor, self.protocol) - for (c, tls) in zip(self.configs, self.use_tls): + for c, tls in zip(self.configs, self.use_tls): d = clientCreator.connect(dn="", overrides=c.getServiceLocationOverrides()) if tls: d.addCallback(lambda x: x.startTLS()) diff --git a/ldaptor/protocols/ldap/proxybase.py b/ldaptor/protocols/ldap/proxybase.py index d4b7b827..c1610f86 100755 --- a/ldaptor/protocols/ldap/proxybase.py +++ b/ldaptor/protocols/ldap/proxybase.py @@ -1,6 +1,7 @@ """ LDAP protocol proxy server. """ + from ldaptor.protocols.ldap import ldapserver, ldapconnector, ldaperrors from ldaptor.protocols import pureldap from twisted.internet import defer diff --git a/ldaptor/test/test_attributeset.py b/ldaptor/test/test_attributeset.py index c02747f8..e39185dc 100644 --- a/ldaptor/test/test_attributeset.py +++ b/ldaptor/test/test_attributeset.py @@ -1,6 +1,7 @@ """ Test cases for ldaptor.attributeset """ + from functools import total_ordering from twisted.trial import unittest diff --git a/ldaptor/test/test_autofill_samba.py b/ldaptor/test/test_autofill_samba.py index 6910d79c..ad44252e 100644 --- a/ldaptor/test/test_autofill_samba.py +++ b/ldaptor/test/test_autofill_samba.py @@ -1,6 +1,7 @@ """ Test cases for ldaptor.protocols.ldap.autofill.sambaAccount module. """ + from twisted.trial import unittest from ldaptor.protocols.ldap import ldapsyntax diff --git a/ldaptor/test/test_encoder.py b/ldaptor/test/test_encoder.py index 4aaea8d1..f137794d 100644 --- a/ldaptor/test/test_encoder.py +++ b/ldaptor/test/test_encoder.py @@ -1,5 +1,5 @@ """ - Test cases for ldaptor.encoder module +Test cases for ldaptor.encoder module """ from twisted.trial import unittest diff --git a/ldaptor/test/test_examples.py b/ldaptor/test/test_examples.py index ecb10d42..5b0201dc 100644 --- a/ldaptor/test/test_examples.py +++ b/ldaptor/test/test_examples.py @@ -1,6 +1,7 @@ """ Tests for the code from docs/source/example. """ + import os import sys diff --git a/ldaptor/test/test_inmemory.py b/ldaptor/test/test_inmemory.py index 78e9b22e..ff1ff6cc 100644 --- a/ldaptor/test/test_inmemory.py +++ b/ldaptor/test/test_inmemory.py @@ -1,6 +1,7 @@ """ Test cases for ldaptor.inmemory module. """ + from io import BytesIO from twisted.trial import unittest diff --git a/ldaptor/test/test_ldapclient.py b/ldaptor/test/test_ldapclient.py index 3c9ad8d4..2e593238 100644 --- a/ldaptor/test/test_ldapclient.py +++ b/ldaptor/test/test_ldapclient.py @@ -1,6 +1,7 @@ """ Test cases for ldaptor.protocols.ldap.ldapsyntax module. """ + from twisted.trial import unittest from twisted.test import proto_helpers from twisted.internet import defer diff --git a/ldaptor/test/test_ldaperrors.py b/ldaptor/test/test_ldaperrors.py index 7663a01a..0a63212a 100644 --- a/ldaptor/test/test_ldaperrors.py +++ b/ldaptor/test/test_ldaperrors.py @@ -1,5 +1,5 @@ """ - Test cases for ldaptor.protocols.ldap.ldaperrors module. +Test cases for ldaptor.protocols.ldap.ldaperrors module. """ from twisted.trial import unittest diff --git a/ldaptor/test/test_ldif.py b/ldaptor/test/test_ldif.py index 86ee9e2a..d263fe49 100644 --- a/ldaptor/test/test_ldif.py +++ b/ldaptor/test/test_ldif.py @@ -1,5 +1,5 @@ """ - Test cases for ldaptor.protocols.ldap.ldif module +Test cases for ldaptor.protocols.ldap.ldif module """ import base64 @@ -85,8 +85,8 @@ def test_contains_nonprintable_characters(self): Value is a string containing nonprintable characters. Returned value is base64 encoded. """ - result = attributeAsLDIF(b"key", b"val\xFFue") - self.assertEqual(result, b"key:: %s\n" % encode(b"val\xFFue")) + result = attributeAsLDIF(b"key", b"val\xffue") + self.assertEqual(result, b"key:: %s\n" % encode(b"val\xffue")) class AsLDIFTests(unittest.TestCase): diff --git a/ldaptor/test/test_match.py b/ldaptor/test/test_match.py index ccc524f2..bbed166d 100644 --- a/ldaptor/test/test_match.py +++ b/ldaptor/test/test_match.py @@ -1,6 +1,7 @@ """ Test cases for ldaptor.protocols.ldap.ldapserver module. """ + import re import attr diff --git a/ldaptor/test/test_proxybase.py b/ldaptor/test/test_proxybase.py index 6516cd76..f5181282 100644 --- a/ldaptor/test/test_proxybase.py +++ b/ldaptor/test/test_proxybase.py @@ -1,6 +1,7 @@ """ Test cases for ldaptor.protocols.ldap.proxybase module. """ + from functools import partial import itertools diff --git a/ldaptor/test/test_pureber.py b/ldaptor/test/test_pureber.py index ea4633c9..f1a02950 100644 --- a/ldaptor/test/test_pureber.py +++ b/ldaptor/test/test_pureber.py @@ -1,6 +1,7 @@ """ Test cases for ldaptor.protocols.pureber module. """ + from twisted.trial import unittest from ldaptor.protocols import pureber @@ -34,7 +35,7 @@ class BerLengths(unittest.TestCase): (257, [0x80 | 2, 1, 1]), (65535, [0x80 | 2, 0xFF, 0xFF]), (65536, [0x80 | 3, 0x01, 0x00, 0x00]), - (256 ** 127 - 1, [0x80 | 127] + 127 * [0xFF]), + (256**127 - 1, [0x80 | 127] + 127 * [0xFF]), ) def testToBER(self): @@ -61,7 +62,7 @@ def testPartialBER(self): pureber.BERExceptionInsufficientData, pureber.berDecodeLength, m[:1] ) - m = bytes(pureber.int2berlen(256 ** 100 - 1)) + m = bytes(pureber.int2berlen(256**100 - 1)) self.assertEqual(101, len(m)) self.assertRaises( pureber.BERExceptionInsufficientData, pureber.berDecodeLength, m[:100] diff --git a/ldaptor/test/test_pureldap.py b/ldaptor/test/test_pureldap.py index 6bdd4d8d..9d5f606b 100644 --- a/ldaptor/test/test_pureldap.py +++ b/ldaptor/test/test_pureldap.py @@ -1,6 +1,7 @@ """ Test cases for ldaptor.protocols.pureldap module. """ + from twisted.trial import unittest from ldaptor.protocols import pureldap, pureber @@ -419,8 +420,8 @@ class KnownValues(unittest.TestCase): "controls": [ ("1.2.3.4", None, None), ("2.3.4.5", False), - ("3.4.5.6", True, b"\x00\x01\x02\xFF"), - ("4.5.6.7", None, b"\x00\x01\x02\xFF"), + ("3.4.5.6", True, b"\x00\x01\x02\xff"), + ("4.5.6.7", None, b"\x00\x01\x02\xff"), ], }, pureldap.LDAPBERDecoderContext_TopLevel( @@ -447,12 +448,12 @@ class KnownValues(unittest.TestCase): pureldap.LDAPControl( controlType="3.4.5.6", criticality=True, - controlValue=b"\x00\x01\x02\xFF", + controlValue=b"\x00\x01\x02\xff", ), pureldap.LDAPControl( controlType="4.5.6.7", criticality=None, - controlValue=b"\x00\x01\x02\xFF", + controlValue=b"\x00\x01\x02\xff", ), ] ).toWire() diff --git a/ldaptor/test/test_server.py b/ldaptor/test/test_server.py index c65d8ab7..e3b64f3b 100644 --- a/ldaptor/test/test_server.py +++ b/ldaptor/test/test_server.py @@ -1,6 +1,7 @@ """ Test cases for ldaptor.protocols.ldap.ldapserver module. """ + import base64 import types diff --git a/ldaptor/test/test_usage.py b/ldaptor/test/test_usage.py index 90425168..2086d411 100644 --- a/ldaptor/test/test_usage.py +++ b/ldaptor/test/test_usage.py @@ -1,6 +1,7 @@ """ Test cases for ldaptor.usage """ + import re from twisted.python.usage import UsageError diff --git a/ldaptor/usage.py b/ldaptor/usage.py index 03669cfd..2c3f39cf 100644 --- a/ldaptor/usage.py +++ b/ldaptor/usage.py @@ -1,6 +1,7 @@ """ Command line argument/options available to various ldaptor tools. """ + from twisted.python import usage, reflect from twisted.python.usage import UsageError from ldaptor.protocols import pureldap