[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[OpenTAL-checkins] opental/PlacelessTranslationService Negotiator.py
From: |
Fernando Lalo Martins |
Subject: |
[OpenTAL-checkins] opental/PlacelessTranslationService Negotiator.py |
Date: |
Thu, 28 Aug 2003 15:12:11 -0400 |
CVSROOT: /cvsroot/opental
Module name: opental
Branch:
Changes by: Fernando Lalo Martins <address@hidden> 03/08/28 15:12:10
Modified files:
PlacelessTranslationService: Negotiator.py
Log message:
adding "rudimentary" (his words) support to quality factors, thanks to
Simon Eisenmann <address@hidden>
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/opental/opental/PlacelessTranslationService/Negotiator.py.diff?tr1=1.7&tr2=1.8&r1=text&r2=text
Patches:
Index: opental/PlacelessTranslationService/Negotiator.py
diff -u opental/PlacelessTranslationService/Negotiator.py:1.7
opental/PlacelessTranslationService/Negotiator.py:1.8
--- opental/PlacelessTranslationService/Negotiator.py:1.7 Fri Feb 21
18:29:40 2003
+++ opental/PlacelessTranslationService/Negotiator.py Thu Aug 28 15:12:10 2003
@@ -17,7 +17,7 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
"""
-$Id: Negotiator.py,v 1.7 2003/02/21 23:29:40 lalo Exp $
+$Id: Negotiator.py,v 1.8 2003/08/28 19:12:10 lalo Exp $
"""
_langPrefsRegistry = []
@@ -67,11 +67,45 @@
req_langs = http_langs
else:
req_langs = (user_langs +','+ http_langs).split(',')
- langs = []
+
+ langs = []
+ i=0
+ length=len(req_langs)
+
+ # parse quality strings and build a tuple
+ # like ((float(quality), lang), (float(quality), lang))
+ # which is sorted afterwards
+ # if no quality string is given then the list order
+ # is used as quality indicator
for lang in req_langs:
lang = lang.strip().lower().replace('_', '-')
if lang:
- langs.append(lang.split(';')[0])
+ l = lang.split(';', 2)
+ quality = []
+
+ if len(l) == 2:
+ try:
+ q = l[1]
+ if q.startswith('q='):
+ q = q.split('=', 2)[1]
+ quality = float(q)
+ except:
+ pass
+
+ if quality == []:
+ quality = float(length-i)
+
+ language = l[0]
+ langs.append((quality, language))
+ i += 1
+
+ # sort and reverse it
+ langs.sort()
+ langs.reverse()
+
+ # filter quality string
+ langs = map(lambda x: x[1], langs)
+
self.langs = langs
def getPreferredLanguages(self):
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [OpenTAL-checkins] opental/PlacelessTranslationService Negotiator.py,
Fernando Lalo Martins <=