Revert "Bump cherrypy from 18.8.0 to 18.9.0 (#2266)"

This reverts commit faef9a94c4.
This commit is contained in:
JonnyWong16 2024-03-24 17:40:56 -07:00
commit 2fc618c01f
No known key found for this signature in database
GPG key ID: B1F1F9807184697A
673 changed files with 11579 additions and 159846 deletions

View file

@ -11,18 +11,18 @@
# FOR A PARTICULAR PURPOSE
#
##############################################################################
import logging
import os
import errno
import logging
logger = logging.getLogger("zc.lockfile")
__metaclass__ = type
class LockError(Exception):
"""Couldn't get a lock
"""
try:
import fcntl
except ImportError:
@ -31,7 +31,6 @@ except ImportError:
except ImportError:
def _lock_file(file):
raise TypeError('No file-locking support on this platform')
def _unlock_file(file):
raise TypeError('No file-locking support on this platform')
@ -41,14 +40,14 @@ except ImportError:
# Lock just the first byte
try:
msvcrt.locking(file.fileno(), msvcrt.LK_NBLCK, 1)
except OSError:
except IOError:
raise LockError("Couldn't lock %r" % file.name)
def _unlock_file(file):
try:
file.seek(0)
msvcrt.locking(file.fileno(), msvcrt.LK_UNLCK, 1)
except OSError:
except IOError:
raise LockError("Couldn't unlock %r" % file.name)
else:
@ -58,16 +57,14 @@ else:
def _lock_file(file):
try:
fcntl.flock(file.fileno(), _flags)
except OSError:
except IOError:
raise LockError("Couldn't lock %r" % file.name)
def _unlock_file(file):
fcntl.flock(file.fileno(), fcntl.LOCK_UN)
class LazyHostName:
"""Avoid importing socket and calling gethostname() unnecessarily"""
def __str__(self):
import socket
return socket.gethostname()
@ -82,7 +79,7 @@ class SimpleLockFile:
try:
# Try to open for writing without truncation:
fp = open(path, 'r+')
except OSError:
except IOError:
# If the file doesn't exist, we'll get an IO error, try a+
# Note that there may be a race here. Multiple processes
# could fail on the r+ open and open the file a+, but only
@ -92,7 +89,7 @@ class SimpleLockFile:
try:
_lock_file(fp)
self._fp = fp
except BaseException:
except:
fp.close()
raise
@ -117,7 +114,7 @@ class LockFile(SimpleLockFile):
def __init__(self, path, content_template='{pid}'):
self._content_template = content_template
super().__init__(path)
super(LockFile, self).__init__(path)
def _on_lock(self):
content = self._content_template.format(

View file

@ -11,22 +11,23 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
import doctest
import os
import os, re, sys, unittest, doctest
import zc.lockfile, time, threading
from zope.testing import renormalizing, setupstack
import tempfile
import threading
import time
import unittest
from unittest.mock import Mock
from unittest.mock import patch
from zope.testing import setupstack
import zc.lockfile
try:
from unittest.mock import Mock, patch
except ImportError:
from mock import Mock, patch
checker = renormalizing.RENormalizing([
# Python 3 adds module path to error class name.
(re.compile("zc\.lockfile\.LockError:"),
r"LockError:"),
])
def inc():
while True:
while 1:
try:
lock = zc.lockfile.LockFile('f.lock')
except zc.lockfile.LockError:
@ -42,7 +43,6 @@ def inc():
f.close()
lock.close()
def many_threads_read_and_write():
r"""
>>> with open('f', 'w+b') as file:
@ -72,7 +72,6 @@ def many_threads_read_and_write():
"""
def pid_in_lockfile():
r"""
>>> import os, zc.lockfile
@ -89,7 +88,7 @@ def pid_in_lockfile():
>>> lock = zc.lockfile.LockFile("f.lock")
Traceback (most recent call last):
...
zc.lockfile.LockError: Couldn't lock 'f.lock'
LockError: Couldn't lock 'f.lock'
>>> f = open("f.lock")
>>> _ = f.seek(1)
@ -108,8 +107,7 @@ def hostname_in_lockfile():
>>> import zc.lockfile
>>> with patch('socket.gethostname', Mock(return_value='myhostname')):
... lock = zc.lockfile.LockFile(
... "f.lock", content_template='{hostname}')
... lock = zc.lockfile.LockFile("f.lock", content_template='{hostname}')
>>> f = open("f.lock")
>>> _ = f.seek(1)
>>> f.read().rstrip()
@ -121,7 +119,7 @@ def hostname_in_lockfile():
>>> lock = zc.lockfile.LockFile("f.lock", content_template='{hostname}')
Traceback (most recent call last):
...
zc.lockfile.LockError: Couldn't lock 'f.lock'
LockError: Couldn't lock 'f.lock'
>>> f = open("f.lock")
>>> _ = f.seek(1)
@ -133,7 +131,7 @@ def hostname_in_lockfile():
"""
class TestLogger:
class TestLogger(object):
def __init__(self):
self.log_entries = []
@ -143,7 +141,6 @@ class TestLogger:
class LockFileLogEntryTestCase(unittest.TestCase):
"""Tests for logging in case of lock failure"""
def setUp(self):
self.here = os.getcwd()
self.tmp = tempfile.mkdtemp(prefix='zc.lockfile-test-')
@ -157,8 +154,8 @@ class LockFileLogEntryTestCase(unittest.TestCase):
# PID and hostname are parsed and logged from lock file on failure
with patch('os.getpid', Mock(return_value=123)):
with patch('socket.gethostname', Mock(return_value='myhostname')):
lock = zc.lockfile.LockFile(
'f.lock', content_template='{pid}/{hostname}')
lock = zc.lockfile.LockFile('f.lock',
content_template='{pid}/{hostname}')
with open('f.lock') as f:
self.assertEqual(' 123/myhostname\n', f.read())
@ -194,10 +191,11 @@ class LockFileLogEntryTestCase(unittest.TestCase):
def test_suite():
suite = unittest.TestSuite()
suite.addTest(doctest.DocFileSuite(
'README.txt',
'README.txt', checker=checker,
setUp=setupstack.setUpDirectory, tearDown=setupstack.tearDown))
suite.addTest(doctest.DocTestSuite(
setUp=setupstack.setUpDirectory, tearDown=setupstack.tearDown))
setUp=setupstack.setUpDirectory, tearDown=setupstack.tearDown,
checker=checker))
# Add unittest test cases from this module
suite.addTest(unittest.defaultTestLoader.loadTestsFromName(__name__))
return suite