]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/pybind/mgr/dashboard/cherrypy_backports.py
import ceph quincy 17.2.4
[ceph.git] / ceph / src / pybind / mgr / dashboard / cherrypy_backports.py
index 9be4c9ba9f7db9f46218de796b05bbe04975f1e8..8871004fed2df7ff0f6247da7816ad593e73232f 100644 (file)
@@ -32,7 +32,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 """
 
-from distutils.version import StrictVersion
+from pkg_resources import parse_version
 
 # The SSL code in CherryPy 3.5.0 is buggy.  It was fixed long ago,
 # but 3.5.0 is still shipping in major linux distributions
@@ -42,7 +42,7 @@ from distutils.version import StrictVersion
 def patch_http_connection_init(v):
     # It was fixed in 3.7.0.  Exact lower bound version is probably earlier,
     # but 3.5.0 is what this monkey patch is tested on.
-    if StrictVersion("3.5.0") <= v < StrictVersion("3.7.0"):
+    if parse_version("3.5.0") <= v < parse_version("3.7.0"):
         from cherrypy.wsgiserver.wsgiserver2 import CP_fileobject, HTTPConnection
 
         def fixed_init(hc_self, server, sock, makefile=CP_fileobject):
@@ -63,7 +63,7 @@ def patch_http_connection_init(v):
 def skip_wait_for_occupied_port(v):
     # the issue was fixed in 3.2.3. it's present in 3.2.2 (current version on
     # centos:7) and back to at least 3.0.0.
-    if StrictVersion("3.1.2") <= v < StrictVersion("3.2.3"):
+    if parse_version("3.1.2") <= v < parse_version("3.2.3"):
         # https://github.com/cherrypy/cherrypy/issues/1100
         from cherrypy.process import servers
         servers.wait_for_occupied_port = lambda host, port: None
@@ -71,7 +71,7 @@ def skip_wait_for_occupied_port(v):
 
 # cherrypy.wsgiserver was extracted wsgiserver into cheroot in cherrypy v9.0.0
 def patch_builtin_ssl_wrap(v, new_wrap):
-    if v < StrictVersion("9.0.0"):
+    if v < parse_version("9.0.0"):
         from cherrypy.wsgiserver.ssl_builtin import BuiltinSSLAdapter as builtin_ssl
     else:
         from cheroot.ssl.builtin import BuiltinSSLAdapter as builtin_ssl  # type: ignore
@@ -81,7 +81,7 @@ def patch_builtin_ssl_wrap(v, new_wrap):
 def accept_exceptions_from_builtin_ssl(v):
     # the fix was included by cheroot v5.2.0, which was included by cherrypy
     # 10.2.0.
-    if v < StrictVersion("10.2.0"):
+    if v < parse_version("10.2.0"):
         # see https://github.com/cherrypy/cheroot/pull/4
         import ssl
 
@@ -117,11 +117,11 @@ def accept_socket_error_0(v):
     # see https://github.com/cherrypy/cherrypy/issues/1618
     try:
         import cheroot
-        cheroot_version = cheroot.__version__
+        cheroot_version = parse_version(cheroot.__version__)
     except ImportError:
         pass
 
-    if v < StrictVersion("9.0.0") or cheroot_version < StrictVersion("6.5.5"):
+    if v < parse_version("9.0.0") or cheroot_version < parse_version("6.5.5"):
         generic_socket_error = OSError
 
         def accept_socket_error_0(func):
@@ -157,7 +157,7 @@ def patch_request_unique_id(v):
     Monkey-patching is preferred over alternatives as inheritance, as it'd break
     type checks (cherrypy/lib/cgtools.py: `isinstance(obj, _cprequest.Request)`)
     """
-    if v < StrictVersion('11.1.0'):
+    if v < parse_version('11.1.0'):
         import uuid
         from functools import update_wrapper
 
@@ -191,8 +191,9 @@ def patch_request_unique_id(v):
 
 
 def patch_cherrypy(v):
-    patch_http_connection_init(v)
-    skip_wait_for_occupied_port(v)
-    accept_exceptions_from_builtin_ssl(v)
-    accept_socket_error_0(v)
-    patch_request_unique_id(v)
+    ver = parse_version(v)
+    patch_http_connection_init(ver)
+    skip_wait_for_occupied_port(ver)
+    accept_exceptions_from_builtin_ssl(ver)
+    accept_socket_error_0(ver)
+    patch_request_unique_id(ver)