本文整理匯總了Python中mimetools.Message.getheader方法的典型用法代碼示例。如果您正苦於以下問題:Python Message.getheader方法的具體用法?Python Message.getheader怎麽用?Python Message.getheader使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類mimetools.Message
的用法示例。
在下文中一共展示了Message.getheader方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: handshake
# 需要導入模塊: from mimetools import Message [as 別名]
# 或者: from mimetools.Message import getheader [as 別名]
def handshake(self):
data = self.request.recv(1024)
headers = Message(StringIO(data.split("\r\n", 1)[1]))
body = data.split("\r\n\r\n")[1]
upgrade = headers.get("Upgrade", "")
if upgrade.lower() != "websocket":
print "WebSockets client " + self.client_address[0] + " wrong Upgrade"
return
if headers.getheader("Sec-WebSocket-Key") != None:
self.ws_rfc = True
response = self.handshake_singleKey(headers)
elif (headers.getheader("Sec-WebSocket-Key1") != None) and (headers.getheader("Sec-WebSocket-Key2") != None):
self.ws_rfc = False
response = self.handshake_twoKeys(headers, body)
else:
print "WebSockets client " + self.client_address[0] + " wrong structure"
return
self.handshake_done = self.request.sendall(response)
self.server.clients += [self]
print "WebSockets client " + self.client_address[0] + " handshaken"