From 24590669d8e132c9b8fa4ac6f6bb14d7f93acc91 Mon Sep 17 00:00:00 2001 From: Michael Barton Date: Wed, 22 Dec 2010 16:36:31 +0000 Subject: [PATCH] i18n finishup --- swift/account/auditor.py | 1 - swift/account/reaper.py | 1 - swift/account/server.py | 1 - swift/common/bench.py | 1 - swift/common/bufferedhttp.py | 1 - swift/common/daemon.py | 3 +++ swift/common/db.py | 1 - swift/common/db_replicator.py | 1 - swift/common/memcached.py | 1 - swift/common/middleware/catch_errors.py | 2 -- swift/common/middleware/ratelimit.py | 1 - swift/common/utils.py | 1 - swift/common/wsgi.py | 2 ++ swift/container/auditor.py | 1 - swift/container/server.py | 1 - swift/container/updater.py | 1 - swift/obj/auditor.py | 1 - swift/obj/replicator.py | 1 - swift/obj/server.py | 1 - swift/obj/updater.py | 1 - swift/proxy/server.py | 1 - test/__init__.py | 7 +++++++ test/unit/proxy/test_server.py | 20 ++++++++++---------- 23 files changed, 22 insertions(+), 30 deletions(-) diff --git a/swift/account/auditor.py b/swift/account/auditor.py index 01afb7d469..36e1e0a0d8 100644 --- a/swift/account/auditor.py +++ b/swift/account/auditor.py @@ -16,7 +16,6 @@ import os import time from random import random -from gettext import gettext as _ from swift.account import server as account_server from swift.common.db import AccountBroker diff --git a/swift/account/reaper.py b/swift/account/reaper.py index 0225209392..6d2112927f 100644 --- a/swift/account/reaper.py +++ b/swift/account/reaper.py @@ -18,7 +18,6 @@ import random from logging import DEBUG from math import sqrt from time import time -from gettext import gettext as _ from eventlet import GreenPool, sleep diff --git a/swift/account/server.py b/swift/account/server.py index 67572165f5..53d604ce93 100644 --- a/swift/account/server.py +++ b/swift/account/server.py @@ -20,7 +20,6 @@ import time import traceback from urllib import unquote from xml.sax import saxutils -from gettext import gettext as _ from webob import Request, Response from webob.exc import HTTPAccepted, HTTPBadRequest, \ diff --git a/swift/common/bench.py b/swift/common/bench.py index 1e525c2e7d..b698ff310b 100644 --- a/swift/common/bench.py +++ b/swift/common/bench.py @@ -18,7 +18,6 @@ import time import random from urlparse import urlparse from contextlib import contextmanager -from gettext import gettext as _ import eventlet.pools from eventlet.green.httplib import CannotSendRequest diff --git a/swift/common/bufferedhttp.py b/swift/common/bufferedhttp.py index 536793fc87..81c54d0722 100644 --- a/swift/common/bufferedhttp.py +++ b/swift/common/bufferedhttp.py @@ -29,7 +29,6 @@ BufferedHTTPResponse. from urllib import quote import logging import time -from gettext import gettext as _ from eventlet.green.httplib import CONTINUE, HTTPConnection, HTTPMessage, \ HTTPResponse, HTTPSConnection, _UNKNOWN diff --git a/swift/common/daemon.py b/swift/common/daemon.py index d305c247f6..e5ed3f7caa 100644 --- a/swift/common/daemon.py +++ b/swift/common/daemon.py @@ -16,7 +16,9 @@ import os import sys import signal +import gettext from re import sub + from swift.common import utils @@ -40,6 +42,7 @@ class Daemon(object): utils.validate_configuration() utils.capture_stdio(self.logger, **kwargs) utils.drop_privileges(self.conf.get('user', 'swift')) + gettext.install('swift', unicode=1) def kill_children(*args): signal.signal(signal.SIGTERM, signal.SIG_IGN) diff --git a/swift/common/db.py b/swift/common/db.py index 6f7372c22c..7315159bb7 100644 --- a/swift/common/db.py +++ b/swift/common/db.py @@ -27,7 +27,6 @@ import cPickle as pickle import errno from random import randint from tempfile import mkstemp -from gettext import gettext as _ from eventlet import sleep import simplejson as json diff --git a/swift/common/db_replicator.py b/swift/common/db_replicator.py index 89e0590f7e..0588b841a0 100644 --- a/swift/common/db_replicator.py +++ b/swift/common/db_replicator.py @@ -20,7 +20,6 @@ import random import math import time import shutil -from gettext import gettext as _ from eventlet import GreenPool, sleep, Timeout from eventlet.green import subprocess diff --git a/swift/common/memcached.py b/swift/common/memcached.py index d41b25616f..193456524a 100644 --- a/swift/common/memcached.py +++ b/swift/common/memcached.py @@ -26,7 +26,6 @@ import socket import time from bisect import bisect from hashlib import md5 -from gettext import gettext as _ CONN_TIMEOUT = 0.3 IO_TIMEOUT = 2.0 diff --git a/swift/common/middleware/catch_errors.py b/swift/common/middleware/catch_errors.py index 0dcedd201a..5fb8c33592 100644 --- a/swift/common/middleware/catch_errors.py +++ b/swift/common/middleware/catch_errors.py @@ -13,8 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -from gettext import gettext as _ - from webob import Request from webob.exc import HTTPServerError diff --git a/swift/common/middleware/ratelimit.py b/swift/common/middleware/ratelimit.py index 1679c1548c..c0827da88b 100644 --- a/swift/common/middleware/ratelimit.py +++ b/swift/common/middleware/ratelimit.py @@ -15,7 +15,6 @@ import time import eventlet from webob import Request, Response from webob.exc import HTTPNotFound -from gettext import gettext as _ from swift.common.utils import split_path, cache_from_env, get_logger from swift.proxy.server import get_container_memcache_key diff --git a/swift/common/utils.py b/swift/common/utils.py index 5ddac9ce84..c837456591 100644 --- a/swift/common/utils.py +++ b/swift/common/utils.py @@ -34,7 +34,6 @@ from ConfigParser import ConfigParser, NoSectionError, NoOptionError from optparse import OptionParser from tempfile import mkstemp import cPickle as pickle -from gettext import gettext as _ import eventlet from eventlet import greenio, GreenPool, sleep, Timeout, listen diff --git a/swift/common/wsgi.py b/swift/common/wsgi.py index a93c21aa8a..079e4277e1 100644 --- a/swift/common/wsgi.py +++ b/swift/common/wsgi.py @@ -21,6 +21,7 @@ import signal import sys import time import mimetools +import gettext import eventlet from eventlet import greenio, GreenPool, sleep, wsgi, listen @@ -120,6 +121,7 @@ def run_wsgi(conf_file, app_section, *args, **kwargs): sock = get_socket(conf, default_port=kwargs.get('default_port', 8080)) # remaining tasks should not require elevated privileges drop_privileges(conf.get('user', 'swift')) + gettext.install('swift', unicode=1) # finally after binding to ports and privilege drop, run app __init__ code app = loadapp('config:%s' % conf_file, global_conf={'log_name': log_name}) diff --git a/swift/container/auditor.py b/swift/container/auditor.py index a6f25538f5..082e6e2b37 100644 --- a/swift/container/auditor.py +++ b/swift/container/auditor.py @@ -16,7 +16,6 @@ import os import time from random import random -from gettext import gettext as _ from swift.container import server as container_server from swift.common.db import ContainerBroker diff --git a/swift/container/server.py b/swift/container/server.py index 4eb92f0dd9..fc06194de6 100644 --- a/swift/container/server.py +++ b/swift/container/server.py @@ -21,7 +21,6 @@ import traceback from urllib import unquote from xml.sax import saxutils from datetime import datetime -from gettext import gettext as _ import simplejson from eventlet.timeout import Timeout diff --git a/swift/container/updater.py b/swift/container/updater.py index 36f567ddc7..9056de3202 100644 --- a/swift/container/updater.py +++ b/swift/container/updater.py @@ -19,7 +19,6 @@ import signal import sys import time from random import random, shuffle -from gettext import gettext as _ from eventlet import spawn, patcher, Timeout diff --git a/swift/obj/auditor.py b/swift/obj/auditor.py index bdd47479b1..1d445ec65f 100644 --- a/swift/obj/auditor.py +++ b/swift/obj/auditor.py @@ -17,7 +17,6 @@ import os import time from hashlib import md5 from random import random -from gettext import gettext as _ from swift.obj import server as object_server from swift.obj.replicator import invalidate_hash diff --git a/swift/obj/replicator.py b/swift/obj/replicator.py index bd2b09af25..ed77bf5a10 100644 --- a/swift/obj/replicator.py +++ b/swift/obj/replicator.py @@ -22,7 +22,6 @@ import logging import hashlib import itertools import cPickle as pickle -from gettext import gettext as _ import eventlet from eventlet import GreenPool, tpool, Timeout, sleep, hubs diff --git a/swift/obj/server.py b/swift/obj/server.py index d47f2b0634..7c139d7775 100644 --- a/swift/obj/server.py +++ b/swift/obj/server.py @@ -26,7 +26,6 @@ from hashlib import md5 from tempfile import mkstemp from urllib import unquote from contextlib import contextmanager -from gettext import gettext as _ from webob import Request, Response, UTC from webob.exc import HTTPAccepted, HTTPBadRequest, HTTPCreated, \ diff --git a/swift/obj/updater.py b/swift/obj/updater.py index eb4638ea16..f958166679 100644 --- a/swift/obj/updater.py +++ b/swift/obj/updater.py @@ -19,7 +19,6 @@ import signal import sys import time from random import random -from gettext import gettext as _ from eventlet import patcher, Timeout diff --git a/swift/proxy/server.py b/swift/proxy/server.py index af0b1a48cc..9838f86802 100644 --- a/swift/proxy/server.py +++ b/swift/proxy/server.py @@ -28,7 +28,6 @@ from datetime import datetime from urllib import unquote, quote import uuid import functools -from gettext import gettext as _ from hashlib import md5 from eventlet import sleep diff --git a/test/__init__.py b/test/__init__.py index e69de29bb2..db145240dc 100644 --- a/test/__init__.py +++ b/test/__init__.py @@ -0,0 +1,7 @@ +# See http://code.google.com/p/python-nose/issues/detail?id=373 +# The code below enables nosetests to work with i18n _() blocks + +import __builtin__ + +setattr(__builtin__, '_', lambda x: x) + diff --git a/test/unit/proxy/test_server.py b/test/unit/proxy/test_server.py index b7d43c0fb2..4577cd4dac 100644 --- a/test/unit/proxy/test_server.py +++ b/test/unit/proxy/test_server.py @@ -3019,8 +3019,8 @@ class TestSegmentedIterable(unittest.TestCase): self.assertRaises(Exception, proxy_server.SegmentedIterable(self.controller, None, [None])._load_next_segment) - self.assertEquals(self.controller.exception_args[0], - 'ERROR: While processing manifest /a/c/o tx1') + self.assert_(self.controller.exception_args[0].startswith( + 'ERROR: While processing manifest')) def test_load_next_segment_with_no_segments(self): self.assertRaises(StopIteration, @@ -3079,8 +3079,8 @@ class TestSegmentedIterable(unittest.TestCase): self.assertRaises(Exception, proxy_server.SegmentedIterable(self.controller, 'lc', [{'name': 'o1'}])._load_next_segment) - self.assertEquals(self.controller.exception_args[0], - 'ERROR: While processing manifest /a/c/o tx1') + self.assert_(self.controller.exception_args[0].startswith( + 'ERROR: While processing manifest')) self.assertEquals(str(self.controller.exception_info[1]), 'Could not load object segment /a/lc/o1: 404') @@ -3088,8 +3088,8 @@ class TestSegmentedIterable(unittest.TestCase): # Iterator value isn't a dict self.assertRaises(Exception, ''.join, proxy_server.SegmentedIterable(self.controller, None, [None])) - self.assertEquals(self.controller.exception_args[0], - 'ERROR: While processing manifest /a/c/o tx1') + self.assert_(self.controller.exception_args[0].startswith( + 'ERROR: While processing manifest')) def test_iter_with_no_segments(self): segit = proxy_server.SegmentedIterable(self.controller, 'lc', []) @@ -3118,8 +3118,8 @@ class TestSegmentedIterable(unittest.TestCase): self.assertRaises(Exception, ''.join, proxy_server.SegmentedIterable(self.controller, 'lc', [{'name': 'o1'}])) - self.assertEquals(self.controller.exception_args[0], - 'ERROR: While processing manifest /a/c/o tx1') + self.assert_(self.controller.exception_args[0].startswith( + 'ERROR: While processing manifest')) self.assertEquals(str(self.controller.exception_info[1]), 'Could not load object segment /a/lc/o1: 404') @@ -3128,8 +3128,8 @@ class TestSegmentedIterable(unittest.TestCase): self.assertRaises(Exception, proxy_server.SegmentedIterable(self.controller, None, [None]).app_iter_range(None, None).next) - self.assertEquals(self.controller.exception_args[0], - 'ERROR: While processing manifest /a/c/o tx1') + self.assert_(self.controller.exception_args[0].startswith( + 'ERROR: While processing manifest')) def test_app_iter_range_with_no_segments(self): self.assertEquals(''.join(proxy_server.SegmentedIterable(