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

Changeset 1480

Show
Ignore:
Timestamp:
12/09/06 12:31:08
Author:
fumanchu
Message:

2.x Fix for #328 (encoding 'errors' argument).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/cherrypy-2.x/cherrypy/filters/encodingfilter.py

    r1396 r1480  
    2020 
    2121 
    22 def encode_stream(encoding): 
     22def encode_stream(encoding, errors='strict'): 
    2323    """Encode a streaming response body. 
    2424     
     
    2828    def encoder(body): 
    2929        for line in body: 
    30             yield line.encode(encoding
     30            yield line.encode(encoding, errors
    3131    cherrypy.response.body = encoder(cherrypy.response.body) 
    3232    return True 
    3333 
    34 def encode_string(encoding): 
     34def encode_string(encoding, errors='strict'): 
    3535    """Encode a buffered response body.""" 
    3636    try: 
    3737        body = [] 
    3838        for chunk in cherrypy.response.body: 
    39             body.append(chunk.encode(encoding)) 
     39            body.append(chunk.encode(encoding, errors)) 
    4040        cherrypy.response.body = body 
    4141    except (LookupError, UnicodeError): 
     
    5959    failmsg = "The response could not be encoded with %s" 
    6060     
     61    errors = conf('encoding_filter.errors', 'strict') 
    6162    enc = conf('encoding_filter.encoding', None) 
    6263    if enc is not None: 
    6364        # If specified, force this encoding to be used, or fail. 
    64         if encode(enc): 
     65        if encode(enc, errors): 
    6566            return enc 
    6667        else: 
     
    7576        # Any character-set is acceptable. 
    7677        charsets = [] 
    77         if encode(default_enc): 
     78        if encode(default_enc, errors): 
    7879            return default_enc 
    7980        else: 
     
    8990            if iso not in charsets: 
    9091                attempted_charsets.append(iso) 
    91                 if encode(iso): 
     92                if encode(iso, errors): 
    9293                    return iso 
    9394         
     
    9899                    if default_enc not in attempted_charsets: 
    99100                        attempted_charsets.append(default_enc) 
    100                         if encode(default_enc): 
     101                        if encode(default_enc, errors): 
    101102                            return default_enc 
    102103                else: 
     
    104105                    if encoding not in attempted_charsets: 
    105106                        attempted_charsets.append(encoding) 
    106                         if encode(encoding): 
     107                        if encode(encoding, errors): 
    107108                            return encoding 
    108109     

Hosted by WebFaction

Log in as guest/cpguest to create tickets