def log_url(log, message, url, level = logging.DEBUG ):
"""Nicely logs the given url.
Print out the url with the first part (protocol, host, port, authority,
user info, path, ref) and in sequence all the query parameters.
log: the log into which write the message
message: a message to print before the url
url: the url to log
level: (optional) the log level to use"""
urls = url.split('?')
log.log( level, message + urllib2.unquote(urls[0]) )
if len(urls) > 1:
for a in sorted(urls[1].split('&')):
param = a.split('=')
if( len(param) < 2 ):
param.append('')
log.log( level, ' . %s = %s', urllib2.unquote(param[0]), urllib2.unquote(param[1]) )
评论列表
文章目录