Skip to content

Commit

Permalink
SedRegex: remove compatibility workaround for Python 2.7.6 and lower
Browse files Browse the repository at this point in the history
  • Loading branch information
jlu5 committed Sep 2, 2017
1 parent 7579498 commit c9bcbbb
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions SedRegex/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,21 @@
import supybot.utils as utils

import re
import sys

try:
from supybot.i18n import PluginInternationalization
_ = PluginInternationalization('SedRegex')
except ImportError:
_ = lambda x: x

# Note: {0,3} is used for matching the flags instead of "*" to work around a Python bug in versions
# lower than 2.7.6: see https://stackoverflow.com/questions/3675144/regex-error-nothing-to-repeat
# and https://bugs.python.org/issue18647
if sys.version_info[0] < 3:
raise ImportError('This plugin requires Python 3. For a legacy version of this plugin that still '
'supports Python 2, consult the python2-legacy branch at '
'https://github.com/GLolol/SupyPlugins/tree/python2-legacy')

SED_REGEX = re.compile(r"^(?:(?P<nick>.+?)[:,] )?s(?P<delim>[^\w\s])(?P<pattern>.*?)(?P=delim)"
r"(?P<replacement>.*?)(?P=delim)(?P<flags>[a-z]{0,3})$")
r"(?P<replacement>.*?)(?P=delim)(?P<flags>[a-z]*)$")

# Replace newlines and friends with things like literal "\n" (backslash and "n")
axe_spaces = utils.str.MultipleReplacer({'\n': '\\n', '\t': '\\t', '\r': '\\r'})
Expand Down

0 comments on commit c9bcbbb

Please sign in to comment.