[FIX] _vendor: fix compatibility with werkzeug 2.0+

As of werkzeug 2.0, the `posixemulation` compatibility layer for atomic
rename operations is abandoned[1]. In the mean time an atomic,
cross-platform file renaming function was introduced in the stdlib, as of
Python 3.3: `os.replace()`.

By using `os.replace()` instead of `posixemulation.rename()`, we can
ensure compatibility with versions 0.x, 1.x and 2.x of werkzeug.

We've always required Python 3.5+ since the P3 support, so
`os.replace()` is always available.

This is a follow-up of the work for supporting werkzeug 1.x [2]

References:
[1] https://github.com/pallets/werkzeug/pull/1790
[2] vendoring of werkzeug.sessions: odoo/odoo#45931

Part-of: odoo/odoo#91927
This commit is contained in:
Olivier Dony
2022-05-23 08:29:52 +02:00
committed by Christophe Monniez
parent 2041f55c85
commit 959059fb5e
+1 -2
View File
@@ -20,14 +20,13 @@ import os
import re
import tempfile
from hashlib import sha1
from os import path
from os import path, replace as rename
from pickle import dump
from pickle import HIGHEST_PROTOCOL
from pickle import load
from time import time
from werkzeug.datastructures import CallbackDict
from werkzeug.posixemulation import rename
_logger = logging.getLogger(__name__)
_sha1_re = re.compile(r"^[a-f0-9]{40}$")