From eb25ef2b91c5dc6a7c7d1d7960e5656888d9739d Mon Sep 17 00:00:00 2001 From: Isis Lovecruft Date: Fri, 26 Sep 2014 02:24:46 +0000 Subject: [PATCH] Only compile the version string regex once on module import. * MOVE the compiled regex for matching the GnuPG binary's version to a module-level variable in `gnupg._util`. --- gnupg/_util.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/gnupg/_util.py b/gnupg/_util.py index ab8a22b..9f0a5c1 100644 --- a/gnupg/_util.py +++ b/gnupg/_util.py @@ -70,6 +70,9 @@ _conf = os.path.join(os.path.join(_user, '.config'), 'python-gnupg') ## Logger is disabled by default log = _logger.create_logger(0) +#: Compiled regex for determining a GnuPG binary's version: +_VERSION_STRING_REGEX = re.compile('(\d)*(\.)*(\d)*(\.)*(\d)*') + def find_encodings(enc=None, system=False): """Find functions for encoding translations for a specific codec. @@ -436,8 +439,7 @@ def _match_version_string(version): :param str version: A version string in the form x.x.x """ - regex = re.compile('(\d)*(\.)*(\d)*(\.)*(\d)*') - matched = regex.match(version) + matched = _VERSION_STRING_REGEX.match(version) g = matched.groups() major, minor, micro = int(g[0]), int(g[2]), int(g[4]) return (major, minor, micro)