aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2017-09-26 00:55:55 +0300
committerGitHub <noreply@github.com>2017-09-26 00:55:55 +0300
commit81108375d9b2ccd0add1572da745311d4dfac505 (patch)
tree54632e1d6ec58850f70941452634c4faf1ea7218 /Lib/gettext.py
parentbpo-31569: correct PCBuild/ case to PCbuild/ in build scripts and docs (GH-3711) (diff)
downloadcpython-81108375d9b2ccd0add1572da745311d4dfac505.tar.gz
cpython-81108375d9b2ccd0add1572da745311d4dfac505.tar.bz2
cpython-81108375d9b2ccd0add1572da745311d4dfac505.zip
bpo-30152: Reduce the number of imports for argparse. (#1269)
Diffstat (limited to 'Lib/gettext.py')
-rw-r--r--Lib/gettext.py14
1 files changed, 9 insertions, 5 deletions
diff --git a/Lib/gettext.py b/Lib/gettext.py
index 5ad7ff6bfce..4c3b80b0239 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)