From 73806ecb5d5a0bc441ad6b48391e6fac3418153a Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Sun, 5 May 2024 20:41:57 +0200 Subject: [PATCH] Unix: Disable 'crypt' command on Python >= 3.13 The module is not available anymore --- plugins/Internet/test.py | 1 - plugins/Unix/plugin.py | 44 +++++++++++++++++++++++----------------- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/plugins/Internet/test.py b/plugins/Internet/test.py index 019cc80f8..4d5f5cb32 100644 --- a/plugins/Internet/test.py +++ b/plugins/Internet/test.py @@ -40,7 +40,6 @@ def testDns(self): 'Host not found.') def testWhois(self): - self.assertNotError('internet whois ohio-state.edu') self.assertNotError('internet whois microsoft.com') self.assertNotError('internet whois inria.fr') self.assertNotError('internet whois slime.com.au') diff --git a/plugins/Unix/plugin.py b/plugins/Unix/plugin.py index b55338035..b559ec060 100644 --- a/plugins/Unix/plugin.py +++ b/plugins/Unix/plugin.py @@ -33,7 +33,6 @@ import re import pwd import sys -import crypt import errno import random import select @@ -41,6 +40,12 @@ import subprocess import shlex +try: + import crypt +except ImportError: + # Python >= 3.13 + crypt = None + import supybot.conf as conf import supybot.utils as utils from supybot.commands import * @@ -119,25 +124,26 @@ def pid(self, irc, msg, args): irc.reply(format('%i', os.getpid()), private=True) pid = wrap(pid, [('checkCapability', 'owner')]) - _cryptre = re.compile(b'[./0-9A-Za-z]') - @internationalizeDocstring - def crypt(self, irc, msg, args, password, salt): - """ [] + if crypt is not None: # Python < 3.13 + _cryptre = re.compile(b'[./0-9A-Za-z]') + @internationalizeDocstring + def crypt(self, irc, msg, args, password, salt): + """ [] - Returns the resulting of doing a crypt() on . If is - not given, uses a random salt. If running on a glibc2 system, - prepending '$1$' to your salt will cause crypt to return an MD5sum - based crypt rather than the standard DES based crypt. - """ - def makeSalt(): - s = b'\x00' - while self._cryptre.sub(b'', s) != b'': - s = struct.pack('. If is + not given, uses a random salt. If running on a glibc2 system, + prepending '$1$' to your salt will cause crypt to return an MD5sum + based crypt rather than the standard DES based crypt. + """ + def makeSalt(): + s = b'\x00' + while self._cryptre.sub(b'', s) != b'': + s = struct.pack('