diff options
Diffstat (limited to 'Lib/gettext.py')
-rw-r--r-- | Lib/gettext.py | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/Lib/gettext.py b/Lib/gettext.py index 5ad7ff6bfc..4c3b80b023 100644 --- a/Lib/gettext.py +++ b/Lib/gettext.py @@ -46,13 +46,10 @@ internationalized, to the local language and cultural habits. # find this format documented anywhere. -import copy import locale import os import re -import struct import sys -from errno import ENOENT __all__ = ['NullTranslations', 'GNUTranslations', 'Catalog', @@ -342,7 +339,9 @@ class GNUTranslations(NullTranslations): def _parse(self, fp): """Override this method to support alternative .mo formats.""" - unpack = struct.unpack + # Delay struct import for speeding up gettext import when .mo files + # are not used. + from struct import unpack filename = getattr(fp, 'name', '') # Parse the .mo file header, which consists of 5 little endian 32 # bit words. @@ -520,7 +519,9 @@ def translation(domain, localedir=None, languages=None, if not mofiles: if fallback: return NullTranslations() - raise OSError(ENOENT, 'No translation file found for domain', domain) + from errno import ENOENT + raise FileNotFoundError(ENOENT, + 'No translation file found for domain', domain) # Avoid opening, reading, and parsing the .mo file after it's been done # once. result = None @@ -533,6 +534,9 @@ def translation(domain, localedir=None, languages=None, # Copy the translation object to allow setting fallbacks and # output charset. All other instance data is shared with the # cached object. + # Delay copy import for speeding up gettext import when .mo files + # are not used. + import copy t = copy.copy(t) if codeset: t.set_output_charset(codeset) |