[issue3609] does parse_header really belong in CGI module?
Martin Panter
report at bugs.python.org
Thu Feb 19 03:39:32 CET 2015
Martin Panter added the comment:
HTTP policy sounds as good a place as any, especially if/when it is blessed as a stable API.
Another related function is the undocumented http.cookiejar.split_header_words(), which seems more flexible than cgi.parse_headers(). It accepts multiple and comma-separated header values, splits on spaces as well as semicolons, and retains parameters without equal signs. Currently I have code that abuses the Message.get_params() and get_param() methods, which could probably benefit from split_header_words():
# Parse RTSP Transport headers like
# Transport: RTP/AVP/TCP;interleaved=0-1, RTP/AVP;unicast;client_port=5004
for value in header_list(self.headers, "Transport"): # Splits at commas
header = email.message.Message()
# Default get_params() header is Content-Type
header["Content-Type"] = value
[transport, _] = header.get_params()[0] # Gets the RTP/AVP part
mode = header.get_param("mode", "PLAY")
channel = header.get_param("interleaved")
if header.get_param("unicast") is not None:
port = header.get_param("client_port")
...
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue3609>
_______________________________________
More information about the Python-bugs-list
mailing list