Removed a Python 2 fallback in certbot.Reverter. (#8694)

* Removed a Python 2 fallback in certbot.Reverter.

* Removed a Python < 3.6 fallback in certbot-apache._internal.parser.
This commit is contained in:
Mads Jensen
2021-03-04 08:10:56 +11:00
committed by GitHub
parent 9643e85b4c
commit a3abcc001a
2 changed files with 3 additions and 10 deletions
@@ -3,8 +3,6 @@ import copy
import fnmatch import fnmatch
import logging import logging
import re import re
import sys
from acme.magic_typing import Dict from acme.magic_typing import Dict
from acme.magic_typing import List from acme.magic_typing import List
@@ -737,9 +735,6 @@ class ApacheParser:
:rtype: str :rtype: str
""" """
if sys.version_info < (3, 6):
# This strips off final /Z(?ms)
return fnmatch.translate(clean_fn_match)[:-7] # pragma: no cover
# Since Python 3.6, it returns a different pattern like (?s:.*\.load)\Z # Since Python 3.6, it returns a different pattern like (?s:.*\.load)\Z
return fnmatch.translate(clean_fn_match)[4:-3] # pragma: no cover return fnmatch.translate(clean_fn_match)[4:-3] # pragma: no cover
+3 -5
View File
@@ -3,7 +3,6 @@ import csv
import glob import glob
import logging import logging
import shutil import shutil
import sys
import time import time
import traceback import traceback
@@ -251,11 +250,10 @@ class Reverter:
def _run_undo_commands(self, filepath): def _run_undo_commands(self, filepath):
"""Run all commands in a file.""" """Run all commands in a file."""
# NOTE: csv module uses native strings. That is, bytes on Python 2 and # NOTE: csv module uses native strings. That is unicode on Python 3
# unicode on Python 3
# It is strongly advised to set newline = '' on Python 3 with CSV, # It is strongly advised to set newline = '' on Python 3 with CSV,
# and it fixes problems on Windows. # and it fixes problems on Windows.
kwargs = {'newline': ''} if sys.version_info[0] > 2 else {} kwargs = {'newline': ''}
with open(filepath, 'r', **kwargs) as csvfile: # type: ignore with open(filepath, 'r', **kwargs) as csvfile: # type: ignore
csvreader = csv.reader(csvfile) csvreader = csv.reader(csvfile)
for command in reversed(list(csvreader)): for command in reversed(list(csvreader)):
@@ -354,7 +352,7 @@ class Reverter:
command_file = None command_file = None
# It is strongly advised to set newline = '' on Python 3 with CSV, # It is strongly advised to set newline = '' on Python 3 with CSV,
# and it fixes problems on Windows. # and it fixes problems on Windows.
kwargs = {'newline': ''} if sys.version_info[0] > 2 else {} kwargs = {'newline': ''}
try: try:
if os.path.isfile(commands_fp): if os.path.isfile(commands_fp):
command_file = open(commands_fp, "a", **kwargs) # type: ignore command_file = open(commands_fp, "a", **kwargs) # type: ignore