summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPavel Zuna <pzuna@redhat.com>2011-02-15 14:10:38 -0500
committerRob Crittenden <rcritten@redhat.com>2011-03-01 10:31:37 -0500
commitbfca99b420d72388cf0230ff6f5481878e336ca7 (patch)
treea1c18e8337a0f3f5d56aa39e9f707f4a12242b9e
parent6eb70ea8e2e61d20b6832a85ff4928b216f6f78c (diff)
downloadfreeipa-bfca99b420d72388cf0230ff6f5481878e336ca7.tar.gz
freeipa-bfca99b420d72388cf0230ff6f5481878e336ca7.tar.xz
freeipa-bfca99b420d72388cf0230ff6f5481878e336ca7.zip
Send Accept-Language header over XML-RPC and translate on server.
Fix #904 Fix #917
-rw-r--r--ipalib/rpc.py33
-rw-r--r--ipaserver/rpcserver.py14
2 files changed, 40 insertions, 7 deletions
diff --git a/ipalib/rpc.py b/ipalib/rpc.py
index 3457640e4..38be0c6c6 100644
--- a/ipalib/rpc.py
+++ b/ipalib/rpc.py
@@ -35,6 +35,7 @@ import threading
import sys
import os
import errno
+import locale
from xmlrpclib import Binary, Fault, dumps, loads, ServerProxy, Transport, ProtocolError
import kerberos
from ipalib.backend import Connectible
@@ -190,7 +191,23 @@ def xml_loads(data, encoding='UTF-8'):
raise decode_fault(e)
-class SSLTransport(Transport):
+class LanguageAwareTransport(Transport):
+ """Transport sending Accept-Language header"""
+ def get_host_info(self, host):
+ (host, extra_headers, x509) = Transport.get_host_info(self, host)
+
+ lang = locale.setlocale(locale.LC_ALL, '').split('.')[0].lower()
+
+ if not isinstance(extra_headers, list):
+ extra_headers = []
+
+ extra_headers.append(
+ ('Accept-Language', lang.replace('_', '-'))
+ )
+
+ return (host, extra_headers, x509)
+
+class SSLTransport(LanguageAwareTransport):
"""Handles an HTTPS transaction to an XML-RPC server."""
def make_connection(self, host):
@@ -247,9 +264,17 @@ class KerbTransport(SSLTransport):
except kerberos.GSSError, e:
self._handle_exception(e, service=service)
- extra_headers = [
+ if not isinstance(extra_headers, list):
+ extra_headers = []
+
+ for (h, v) in extra_headers:
+ if h == 'Authorization':
+ extra_headers.remove((h, v))
+ break
+
+ extra_headers.append(
('Authorization', 'negotiate %s' % kerberos.authGSSClientResponse(vc))
- ]
+ )
return (host, extra_headers, x509)
@@ -307,6 +332,8 @@ class xmlclient(Connectible):
kw['verbose'] = verbose
if server.startswith('https://'):
kw['transport'] = KerbTransport()
+ else:
+ kw['transport'] = LanguageAwareTransport()
self.log.info('trying %s' % server)
serverproxy = ServerProxy(server, **kw)
if len(servers) == 1 or not fallback:
diff --git a/ipaserver/rpcserver.py b/ipaserver/rpcserver.py
index 701ebb651..3d93abe95 100644
--- a/ipaserver/rpcserver.py
+++ b/ipaserver/rpcserver.py
@@ -193,11 +193,17 @@ class WSGIExecutioner(Executioner):
result = None
error = None
_id = None
- lang= os.environ['LANG']
+ lang = os.environ['LANG']
try:
if ('HTTP_ACCEPT_LANGUAGE' in environ):
- os.environ['LANG']=string.split(
- environ['HTTP_ACCEPT_LANGUAGE'],",")[0].split(';')[0]
+ lang_reg_w_q = environ['HTTP_ACCEPT_LANGUAGE'].split(',')[0]
+ lang_reg = lang_reg_w_q.split(';')[0]
+ lang_ = lang_reg.split('-')[0]
+ if '-' in lang_reg:
+ reg = lang_reg.split('-')[1].upper();
+ else:
+ reg = lang_.upper()
+ os.environ['LANG'] = '%s_%s' % (lang_, reg)
if (
environ.get('CONTENT_TYPE', '').startswith(self.content_type)
and environ['REQUEST_METHOD'] == 'POST'
@@ -217,7 +223,7 @@ class WSGIExecutioner(Executioner):
)
error = InternalError()
finally:
- os.environ['LANG']=lang
+ os.environ['LANG'] = lang
params = self.Command[name].args_options_2_params(*args, **options)
if error:
self.info('%s: %s(%s): %s', context.principal, name, ', '.join(self.Command[name]._repr_iter(**params)), e.__class__.__name__)