本文整理匯總了Python中mimetools.Message.keys方法的典型用法代碼示例。如果您正苦於以下問題:Python Message.keys方法的具體用法?Python Message.keys怎麽用?Python Message.keys使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類mimetools.Message
的用法示例。
在下文中一共展示了Message.keys方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: extract_http
# 需要導入模塊: from mimetools import Message [as 別名]
# 或者: from mimetools.Message import keys [as 別名]
def extract_http(request_text, dict_filed):
request_line, headers_alone = request_text.split('\r\n', 1)
headers = Message(StringIO(headers_alone))
# print request_line
request_line = request_line.split(' ', 2)
# print request_line[0]
if request_line[0] in {'GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'TRACE', 'CONNECT'}:
dict_filed['tags']['action'] = request_line[0]
dict_filed['tags']['Domain'] = headers['host']
dict_filed['tags']['URL'] = headers['host'] + request_line[1]
# print request_line[1]
else:
dict_filed['tags']['result_code'] = request_line[1]
if 'user_agent' in headers.keys():
dict_filed['tags']['user_agent'] = headers['user_agent']
if 'referer' in headers.keys():
dict_filed['tags']['referer'] = headers['referer']
if 'content-type' in headers.keys():
dict_filed['tags']['content-type'] = headers['content-type']
if 'accept' in headers.keys():
dict_filed['tags']['content-type'] = headers['accept']
# print headers.keys()
# print dict_filed['URL']
"""