Envelope and header values consistently decoded from utf-8. See RFC 8616.

This commit is contained in:
Stuart D. Gathman
2020-04-21 18:20:16 -04:00
parent 2b1b01c1ef
commit 3844751ef0
9 changed files with 68 additions and 27 deletions
+8 -3
View File
@@ -349,13 +349,18 @@ class Base(object):
# @since 0.9.2
@nocallback
def data(self): return CONTINUE
## Called with bytes for header callback.
# Converts to unicode with surrogate escape. Can be overriden
# to pass bytes to @link #header the header callback @endlink.
## Called with bytes by default global header callback.
# @param fld name decoded as ascii
# @param val field value as bytes
# @since 1.0.5
# Converts from utf-8 to unicode with surrogate escape. Can be overriden
# to pass bytes to @link #header the header callback @endlink instead.
def header_bytes(self,fld,val):
s = val.decode(encoding='utf-8',errors='surrogateescape')
return self.header(fld,s)
## Called for each header field in the message body.
# @param field name decoded as ascii
# @param value field value decoded as utf-8 on python3
@nocallback
def header(self,field,value): return CONTINUE
## Called at the blank line that terminates the header fields.
-1
View File
@@ -1,4 +1,3 @@
"""A parser for SGML, using the derived class as a static DTD."""
# XXX This only supports those SGML features used by HTML.