Changeset 1480
- Timestamp:
- 12/09/06 12:31:08
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/cherrypy-2.x/cherrypy/filters/encodingfilter.py
r1396 r1480 20 20 21 21 22 def encode_stream(encoding ):22 def encode_stream(encoding, errors='strict'): 23 23 """Encode a streaming response body. 24 24 … … 28 28 def encoder(body): 29 29 for line in body: 30 yield line.encode(encoding )30 yield line.encode(encoding, errors) 31 31 cherrypy.response.body = encoder(cherrypy.response.body) 32 32 return True 33 33 34 def encode_string(encoding ):34 def encode_string(encoding, errors='strict'): 35 35 """Encode a buffered response body.""" 36 36 try: 37 37 body = [] 38 38 for chunk in cherrypy.response.body: 39 body.append(chunk.encode(encoding ))39 body.append(chunk.encode(encoding, errors)) 40 40 cherrypy.response.body = body 41 41 except (LookupError, UnicodeError): … … 59 59 failmsg = "The response could not be encoded with %s" 60 60 61 errors = conf('encoding_filter.errors', 'strict') 61 62 enc = conf('encoding_filter.encoding', None) 62 63 if enc is not None: 63 64 # If specified, force this encoding to be used, or fail. 64 if encode(enc ):65 if encode(enc, errors): 65 66 return enc 66 67 else: … … 75 76 # Any character-set is acceptable. 76 77 charsets = [] 77 if encode(default_enc ):78 if encode(default_enc, errors): 78 79 return default_enc 79 80 else: … … 89 90 if iso not in charsets: 90 91 attempted_charsets.append(iso) 91 if encode(iso ):92 if encode(iso, errors): 92 93 return iso 93 94 … … 98 99 if default_enc not in attempted_charsets: 99 100 attempted_charsets.append(default_enc) 100 if encode(default_enc ):101 if encode(default_enc, errors): 101 102 return default_enc 102 103 else: … … 104 105 if encoding not in attempted_charsets: 105 106 attempted_charsets.append(encoding) 106 if encode(encoding ):107 if encode(encoding, errors): 107 108 return encoding 108 109

