Permalink
Browse files

Fix request.languages so it works like it used to

  • Loading branch information...
1 parent 114171f commit ab588e7e59a2f44f6b3678db6d735870a385333c @bbangert bbangert committed Dec 13, 2011
View
13 pylons/controllers/util.py
@@ -27,7 +27,7 @@
except ImportError:
import sha as sha1
-from webob import Request as WebObRequest
+from webob import BaseRequest as WebObRequest
from webob import Response as WebObResponse
from webob.exc import status_map
@@ -54,7 +54,16 @@ def determine_browser_charset(self):
return self.accept_charset
def languages(self):
- return self.accept_language.best_matches(self.language)
+ # And we now have the old best_matches code that webob ditched!
+ al = self.accept_language
+ items = [i for i, q in sorted(al._parsed, key=lambda iq: -iq[1])]
+ for index, item in enumerate(items):
+ if al._match(item, self.language):
+ items[index:] = [self.language]
+ break
+ else:
+ items.append(self.language)
+ return items
languages = property(languages)
def match_accept(self, mimetypes):
View
2 pylons/middleware.py
@@ -6,10 +6,10 @@
from paste.urlparser import StaticURLParser
from weberror.evalexception import EvalException
from weberror.errormiddleware import ErrorMiddleware
-from webob import Request, Response
from webhelpers.html import literal
import pylons
+from pylons.controllers.util import Request, Response
from pylons.error import template_error_formatters
from pylons.util import call_wsgi_application
View
9 setup.py
@@ -98,7 +98,7 @@ def index(self):
Pylons development uses the Mercuial distributed version control system (DVCS)
with BitBucket hosting the main repository here:
-
+
`Pylons Bitbucket repository <https://github.com/Pylons/pylons>`_
@@ -130,12 +130,13 @@ def index(self):
"License :: OSI Approved :: BSD License",
"Framework :: Pylons",
"Programming Language :: Python",
+ "Programming Language :: Python :: 2 :: Only",
"Topic :: Internet :: WWW/HTTP",
"Topic :: Internet :: WWW/HTTP :: Dynamic Content",
"Topic :: Internet :: WWW/HTTP :: WSGI",
"Topic :: Software Development :: Libraries :: Python Modules",
],
- extras_require = {
+ extras_require={
'genshi': ['Genshi>=0.6'],
'jinja2': ['Jinja2'],
},
@@ -149,10 +150,10 @@ def index(self):
[paste.paster_create_template]
pylons = pylons.util:PylonsTemplate
pylons_minimal = pylons.util:MinimalPylonsTemplate
-
+
[paste.filter_factory]
debugger = pylons.middleware:debugger_filter_factory
-
+
[paste.filter_app_factory]
debugger = pylons.middleware:debugger_filter_app_factory
""",
View
1 test_files/sample_controllers/controllers/i18nc.py
@@ -27,6 +27,7 @@ def _set_lang(self, gettext):
return resp_unicode
def i18n_index(self):
+ obj = request._current_obj()
locale_list = request.languages
set_lang(request.languages)
return unicode(_('basic index page'))
View
13 tests/test_units/test_i18n.py
@@ -8,6 +8,7 @@
lang_setup = None
+
def setup_py_trans():
global lang_setup
import pylons
@@ -19,13 +20,14 @@ def setup_py_trans():
glob_set = []
+
class TestI18N(object):
def setUp(self):
setup_py_trans()
-
+
def test_lazify(self):
from pylons.i18n.translation import lazify
-
+
def show_str(st):
return '%s%s' % (st, len(glob_set))
lazy_show_str = lazify(show_str)
@@ -34,17 +36,18 @@ def show_str(st):
assert str(result1) == str(result2)
glob_set.append('1')
assert str(result1) != str(result2)
-
+
def test_noop(self):
import pylons
from pylons.i18n.translation import _, N_, set_lang
foo = N_('Hello')
+
class Bar(object):
def __init__(self):
self.local_foo = _(foo)
-
+
assert Bar().local_foo == 'Hello'
-
+
t = set_lang('fr', set_environ=False, pylons_config=lang_setup)
pylons.translator._push_object(t)
assert Bar().local_foo == 'Bonjour'

0 comments on commit ab588e7

Please sign in to comment.