diff options
Diffstat (limited to 'Lib/gettext.py')
| -rw-r--r-- | Lib/gettext.py | 15 | 
1 files changed, 14 insertions, 1 deletions
| diff --git a/Lib/gettext.py b/Lib/gettext.py index 1591e7ee1c..7032efae7f 100644 --- a/Lib/gettext.py +++ b/Lib/gettext.py @@ -189,7 +189,7 @@ def c2py(plural):                  return int(%s)              ''' % result, ns)          return ns['func'] -    except RuntimeError: +    except RecursionError:          # Recursion error can be raised in _parse() or exec().          raise ValueError('plural form expression is too complex') @@ -311,6 +311,13 @@ class GNUTranslations(NullTranslations):      LE_MAGIC = 0x950412de      BE_MAGIC = 0xde120495 +    # Acceptable .mo versions +    VERSIONS = (0, 1) + +    def _get_versions(self, version): +        """Returns a tuple of major version, minor version""" +        return (version >> 16, version & 0xffff) +      def _parse(self, fp):          """Override this method to support alternative .mo formats."""          unpack = struct.unpack @@ -331,6 +338,12 @@ class GNUTranslations(NullTranslations):              ii = '>II'          else:              raise OSError(0, 'Bad magic number', filename) + +        major_version, minor_version = self._get_versions(version) + +        if major_version not in self.VERSIONS: +            raise OSError(0, 'Bad version number ' + str(major_version), filename) +          # Now put all messages from the .mo file buffer into the catalog          # dictionary.          for i in range(0, msgcount): | 
