diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2017-09-26 00:55:55 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-26 00:55:55 +0300 |
commit | 81108375d9b2ccd0add1572da745311d4dfac505 (patch) | |
tree | 54632e1d6ec58850f70941452634c4faf1ea7218 /Lib/gettext.py | |
parent | f1502d097c29b266a5748312ee2451a2d6ac0af6 (diff) | |
download | cpython-git-81108375d9b2ccd0add1572da745311d4dfac505.tar.gz |
bpo-30152: Reduce the number of imports for argparse. (#1269)
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) |