"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "lib/accept.py" between
viewvc-1.1.28.tar.gz and viewvc-1.2.1.tar.gz

About: ViewVC is a browser interface for CVS and Subversion version control repositories.

accept.py  (viewvc-1.1.28):accept.py  (viewvc-1.2.1)
skipping to change at line 18 skipping to change at line 18
# #
# For more information, visit http://viewvc.org/ # For more information, visit http://viewvc.org/
# #
# ----------------------------------------------------------------------- # -----------------------------------------------------------------------
# #
# accept.py: parse/handle the various Accept headers from the client # accept.py: parse/handle the various Accept headers from the client
# #
# ----------------------------------------------------------------------- # -----------------------------------------------------------------------
import re import re
import string
def language(hdr): def language(hdr):
"Parse an Accept-Language header." "Parse an Accept-Language header."
# parse the header, storing results in a _LanguageSelector object # parse the header, storing results in a _LanguageSelector object
return _parse(hdr, _LanguageSelector()) return _parse(hdr, _LanguageSelector())
# ----------------------------------------------------------------------- # -----------------------------------------------------------------------
_re_token = re.compile(r'\s*([^\s;,"]+|"[^"]*")+\s*') _re_token = re.compile(r'\s*([^\s;,"]+|"[^"]*")+\s*')
skipping to change at line 42 skipping to change at line 41
def _parse(hdr, result): def _parse(hdr, result):
# quick exit for empty or not-supplied header # quick exit for empty or not-supplied header
if not hdr: if not hdr:
return result return result
pos = 0 pos = 0
while pos < len(hdr): while pos < len(hdr):
name = _re_token.match(hdr, pos) name = _re_token.match(hdr, pos)
if not name: if not name:
raise AcceptLanguageParseError() raise AcceptLanguageParseError()
a = result.item_class(string.lower(name.group(1))) a = result.item_class(name.group(1).lower())
pos = name.end() pos = name.end()
while 1: while 1:
# are we looking at a parameter? # are we looking at a parameter?
match = _re_param.match(hdr, pos) match = _re_param.match(hdr, pos)
if not match: if not match:
break break
param = match.group(1) param = match.group(1)
pos = match.end() pos = match.end()
# split up the pieces of the parameter # split up the pieces of the parameter
match = _re_split_param.match(param) match = _re_split_param.match(param)
if not match: if not match:
# the "=" was probably missing # the "=" was probably missing
continue continue
pname = string.lower(match.group(1)) pname = match.group(1).lower()
if pname == 'q' or pname == 'qs': if pname == 'q' or pname == 'qs':
try: try:
a.quality = float(match.group(2)) a.quality = float(match.group(2))
except ValueError: except ValueError:
# bad float literal # bad float literal
pass pass
elif pname == 'level': elif pname == 'level':
try: try:
a.level = float(match.group(2)) a.level = float(match.group(2))
except ValueError: except ValueError:
# bad float literal # bad float literal
pass pass
elif pname == 'charset': elif pname == 'charset':
a.charset = string.lower(match.group(2)) a.charset = match.group(2).lower()
result.append(a) result.append(a)
if hdr[pos:pos+1] == ',': if hdr[pos:pos+1] == ',':
pos = pos + 1 pos = pos + 1
return result return result
class _AcceptItem: class _AcceptItem:
def __init__(self, name): def __init__(self, name):
self.name = name self.name = name
 End of changes. 4 change blocks. 
4 lines changed or deleted 3 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)