From 8ae0d582c09e1b7db7f9ef7c9b4fbee43a56fd0f Mon Sep 17 00:00:00 2001 From: ko-zu Date: Tue, 31 Jan 2023 03:58:46 +0000 Subject: [PATCH] Use os.replace for Windows compat Solves update script running on Windows, issue #23. --- publicsuffixlist/update.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/publicsuffixlist/update.py b/publicsuffixlist/update.py index 3f2f18a..bc41d66 100644 --- a/publicsuffixlist/update.py +++ b/publicsuffixlist/update.py @@ -38,7 +38,12 @@ def updatePSL(psl_file=PSLFILE): with open(psl_file + ".swp", "rb") as f: psl = PublicSuffixList(f) - os.rename(psl_file + ".swp", psl_file) + try: + os.replace(psl_file + ".swp", psl_file) + except AttributeError: + # will not work on python2 on Win. + os.rename(psl_file + ".swp", psl_file) + if lastmod: t = calendar.timegm(parsedate(lastmod)) os.utime(psl_file, (t, t))