[Zope-Checkins] CVS: Zope3/lib/python/Zope/Publisher/Browser - BrowserCharsets.py:1.1
Stephan Richter
srichter@cbu.edu
Fri, 14 Jun 2002 04:56:29 -0400
Update of /cvs-repository/Zope3/lib/python/Zope/Publisher/Browser
In directory cvs.zope.org:/tmp/cvs-serv23607/Zope/Publisher/Browser
Added Files:
BrowserCharsets.py
Log Message:
Similar to the Language Negotiator I created a Charset negotiator, which
should help us with defining an output charset for the browser.
=== Added File Zope3/lib/python/Zope/Publisher/Browser/BrowserCharsets.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Retrieval of browser character set information.
$Id: BrowserCharsets.py,v 1.1 2002/06/14 08:56:29 srichter Exp $
"""
from Zope.I18n.IUserPreferredCharsets import IUserPreferredCharsets
class BrowserCharsets:
__implements__ = IUserPreferredCharsets
def __init__(self, request):
self.request = request
############################################################
# Implementation methods for interface
# Zope.I18n.IUserPreferredCharsets.
def getPreferredCharsets(self):
'''See interface IUserPreferredCharsets'''
charsets = []
for charset in self.request['HTTP_ACCEPT_CHARSET'].split(','):
charset = charset.strip()
if charset:
if ';' in charset:
charset, quality = charset.split(';')
quality = float(quality[2:])
else:
quality = 1.0
charsets.append((quality, charset))
charsets.sort()
charsets.reverse()
return map(lambda c: c[1], charsets)
#
############################################################