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`.
fix/44-verbose-arg
Isis Lovecruft 2014-09-26 02:24:46 +00:00
parent 7dc3b66de4
commit eb25ef2b91
No known key found for this signature in database
GPG Key ID: 18C16EC5F9F1D673
1 changed files with 4 additions and 2 deletions

View File

@ -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)