From d3c065bf76dfdd6d6a403aa1b51b5a8f681148b0 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Fri, 27 Dec 2013 05:15:33 +0000 Subject: [PATCH 1/3] ENH: add PyPy compatibility --- .travis.yml | 1 + ChangeLog | 1 + README.md | 2 +- fail2ban/server/failregex.py | 3 ++- 4 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1a0de9af..ea84432e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,7 @@ python: - "2.7" - "3.2" - "3.3" + - "pypy" before_install: - sudo apt-get update -qq install: diff --git a/ChangeLog b/ChangeLog index e55188eb..9494afe9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -63,6 +63,7 @@ code-review and minor additions from Yaroslav Halchenko. support these. ISO8601 now defaults to localtime unless specified otherwise. Some filters have been change as required to capture these elements in the right timezone correctly. + * Support PyPy ver. 0.8.12 (2013/12/XX) - things-can-only-get-better ----------- diff --git a/README.md b/README.md index 129d24f7..0f033cf3 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Installation: this case, you should use it instead.** Required: -- [Python2 >= 2.4 or Python3 >= 3.2](http://www.python.org) +- [Python2 >= 2.4 or Python3 >= 3.2](http://www.python.org) or [PyPy](http://pypy.org) Optional: - [pyinotify >= 0.8.3](https://github.com/seb-m/pyinotify) diff --git a/fail2ban/server/failregex.py b/fail2ban/server/failregex.py index d5732c80..60ea5cfd 100644 --- a/fail2ban/server/failregex.py +++ b/fail2ban/server/failregex.py @@ -136,7 +136,8 @@ class Regex: if self._matchCache.group("skiplines%i" % n) is not None: skippedLines += self._matchCache.group("skiplines%i" % n) n += 1 - except IndexError: + # KeyError is because of PyPy + except (IndexError, KeyError): break return skippedLines.splitlines(False) From 1f1fe254a63a6ba2c28c4071b6b480aa9d5b631c Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Fri, 27 Dec 2013 12:59:37 +0000 Subject: [PATCH 2/3] DOC: document PyPy version that use KeyError instead of IndexError --- fail2ban/server/failregex.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fail2ban/server/failregex.py b/fail2ban/server/failregex.py index 60ea5cfd..ba176ceb 100644 --- a/fail2ban/server/failregex.py +++ b/fail2ban/server/failregex.py @@ -136,7 +136,7 @@ class Regex: if self._matchCache.group("skiplines%i" % n) is not None: skippedLines += self._matchCache.group("skiplines%i" % n) n += 1 - # KeyError is because of PyPy + # KeyError is because of PyPy issue1665 affecting pypy <= 2.2.1 except (IndexError, KeyError): break return skippedLines.splitlines(False) From 18fbfed91f426206860227ca32fab4283f998451 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Fri, 27 Dec 2013 20:01:43 +0000 Subject: [PATCH 3/3] ENH: error handling on re.group KeyError exception only for PyPy --- fail2ban/server/failregex.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/fail2ban/server/failregex.py b/fail2ban/server/failregex.py index ba176ceb..d3299144 100644 --- a/fail2ban/server/failregex.py +++ b/fail2ban/server/failregex.py @@ -21,7 +21,7 @@ __author__ = "Cyril Jaquier" __copyright__ = "Copyright (c) 2004 Cyril Jaquier" __license__ = "GPL" -import re, sre_constants +import re, sre_constants, sys ## # Regular expression class. @@ -136,8 +136,12 @@ class Regex: if self._matchCache.group("skiplines%i" % n) is not None: skippedLines += self._matchCache.group("skiplines%i" % n) n += 1 + except IndexError: + break # KeyError is because of PyPy issue1665 affecting pypy <= 2.2.1 - except (IndexError, KeyError): + except KeyError: + if 'PyPy' not in sys.version: # pragma: no cover - not sure this is even reachable + raise break return skippedLines.splitlines(False)