Download Install Tutorial Docs FAQ Tools WikiLicense Team IRC Planet Involvement Shop Book

Changeset 1762

Show
Ignore:
Timestamp:
10/21/07 20:29:33
Author:
zakj
Message:

Primarily to support text-based content types that do not start with "text/",
added text_only and add_charset boolean arguments to lib.encoding.encode(),
both defaulting to True.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/cherrypy/lib/encoding.py

    r1722 r1762  
    5151# Encoding 
    5252 
    53 def encode(encoding=None, errors='strict'): 
     53def encode(encoding=None, errors='strict', text_only=True, add_charset=True): 
    5454    # Guard against running twice 
    5555    if getattr(cherrypy.request, "_encoding_attempted", False): 
     
    6060    if ct: 
    6161        ct = ct[0] 
    62         if ct.value.lower().startswith("text/"): 
     62        if (not text_only) or ct.value.lower().startswith("text/"): 
    6363            # Set "charset=..." param on response Content-Type header 
    6464            ct.params['charset'] = find_acceptable_charset(encoding, errors=errors) 
    65             cherrypy.response.headers["Content-Type"] = str(ct) 
     65            if add_charset: 
     66                cherrypy.response.headers["Content-Type"] = str(ct) 
    6667 
    6768def encode_stream(encoding, errors='strict'): 

Hosted by WebFaction

Log in as guest/cpguest to create tickets