本文整理汇总了Python中mimetools.Message.get方法的典型用法代码示例。如果您正苦于以下问题:Python Message.get方法的具体用法?Python Message.get怎么用?Python Message.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mimetools.Message
的用法示例。
在下文中一共展示了Message.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handshake
# 需要导入模块: from mimetools import Message [as 别名]
# 或者: from mimetools.Message import get [as 别名]
def handshake(self):
data = ""
for attempt in xrange(0, 20):
data += os.read(0, 1024)#.strip()
data = data.replace("\n\n", "\r\n")
with file('/tmp/log', 'w') as f:
f.write(data)
try:
headers = Message(StringIO(data.split('\r\n', 1)[1]))
if headers.get("Upgrade", None) == "websocket":
break
except:
continue
headers = Message(StringIO(data.split('\r\n', 1)[1]))
if headers.get("Upgrade", None) == "websocket":
return
key = headers['Sec-WebSocket-Key']
digest = b64encode(sha1(key + self.magic).hexdigest().decode('hex'))
response = 'HTTP/1.1 101 Switching Protocols\r\n'
response += 'Upgrade: websocket\r\n'
response += 'Connection: Upgrade\r\n'
response += 'Sec-WebSocket-Accept: %s\r\n\r\n' % digest
self.handshake_done = os.write(1, response)
示例2: test_spamc_tcp_process
# 需要导入模块: from mimetools import Message [as 别名]
# 或者: from mimetools.Message import get [as 别名]
def test_spamc_tcp_process(self):
with open(self.filename) as _handle:
data = _handle.read()
handle = StringIO(data)
result = self.spamc_tcp.process(handle)
self.assertIn("message", result)
with open(self.filename) as headerhandle:
headers1 = Message(headerhandle)
headers2 = Message(StringIO(result["message"]))
self.assertEqual(headers1.get("Subject"), headers2.get("Subject"))
示例3: test_spamc_unix_process
# 需要导入模块: from mimetools import Message [as 别名]
# 或者: from mimetools.Message import get [as 别名]
def test_spamc_unix_process(self):
with open(self.filename) as handle:
result = self.spamc_unix.process(handle)
self.assertIn('message', result)
with open(self.filename) as headerhandle:
headers1 = Message(headerhandle)
headers2 = Message(StringIO(result['message']))
self.assertEqual(
headers1.get('Subject'),
headers2.get('Subject')
)
示例4: handshake
# 需要导入模块: from mimetools import Message [as 别名]
# 或者: from mimetools.Message import get [as 别名]
def handshake(self):
data = self.request.recv(1024).strip()
new_data = data.split('\r\n', 1)
if not new_data:
return
headers = Message(StringIO(data.split('\r\n', 1)[1]))
if headers.get("Upgrade", None) == "Websocket" or headers.get("Upgrade", None) == "websocket":
key = headers['Sec-WebSocket-Key']
digest = b64encode(sha1(key + self.magic).hexdigest().decode('hex'))
response = 'HTTP/1.1 101 Switching Protocols\r\n'
response += 'Upgrade: websocket\r\n'
response += 'Connection: Upgrade\r\n'
response += 'Sec-WebSocket-Accept: %s\r\n\r\n' % digest
self.handshake_done = self.request.send(response)
self.valid_client = True
示例5: handshake
# 需要导入模块: from mimetools import Message [as 别名]
# 或者: from mimetools.Message import get [as 别名]
def handshake(self):
data = self.sock.readTo('\r\n\r\n').strip()
headers = Message(StringIO(data.split('\r\n', 1)[1]))
if headers.get('Upgrade', None).lower() != 'websocket':
print self.client_address, 'missing header "Upgrade: websocket"'
return False
self.client_ip = headers.get('X-Forwarded-For', self.client_address[0])
key = headers['Sec-WebSocket-Key']
digest = b64encode(sha1(key + self.magic).hexdigest().decode('hex'))
response = 'HTTP/1.1 101 Switching Protocols\r\n'
response += 'Upgrade: websocket\r\n'
response += 'Connection: Upgrade\r\n'
response += 'Sec-WebSocket-Accept: %s\r\n\r\n' % digest
self.sock.send(response)
self.on_handshake()
return True
示例6: _perform_handshake
# 需要导入模块: from mimetools import Message [as 别名]
# 或者: from mimetools.Message import get [as 别名]
def _perform_handshake(self):
"""Perform The WebSocket Handshake"""
try:
Log.add("Got To Handshake")
data = self.recv(1024).strip()
# Log.add("Data: %s" % data)
headers = Message(StringIO(data.split('\r\n', 1)[1]))
Log.add("Parsed Headers:")
# Log.add(headers)
if headers.get('Upgrade', None) == 'websocket':
Log.add("Attempting Handshake")
# create response key
key = b64encode(sha1(headers['Sec-WebSocket-Key'] + self.SALT).digest())
# create response headers
response = (
"HTTP/1.1 101 Web Socket Protocol Handshake\r\n"
"Upgrade: websocket\r\n"
"Connection: Upgrade\r\n"
"Sec-WebSocket-Origin: %s\r\n"
"Sec-WebSocket-Accept: %s\r\n\r\n" % (headers["Origin"], key)
)
if self.send_bytes(response):
Log.add("Handshake successful")
self._assign_room(data)
self._ready_state = "authenticating"
except Exception as e:
Log.add(e.args)
示例7: handshake
# 需要导入模块: from mimetools import Message [as 别名]
# 或者: from mimetools.Message import get [as 别名]
def handshake(self):
log.debug("Request")
data = self.request.recv(1024).strip()
headers = Message(StringIO(data.split('\r\n', 1)[1]))
log.debug("Headers")
if headers.get("Upgrade", None) != "websocket":
return
log.debug("Handshake")
key = headers['Sec-WebSocket-Key']
digest = b64encode(sha1(key + self.magic).hexdigest().decode('hex'))
response = 'HTTP/1.1 101 Switching Protocols\r\n'
response += 'Upgrade: websocket\r\n'
response += 'Connection: Upgrade\r\n'
response += 'Sec-WebSocket-Accept: %s\r\n\r\n' % digest
self.handshake_done = self.request.send(response)
global clients
clients += [self];
# Send over a full delta
combo = {
"name": "combo",
"connections": connections,
"links": links
}
c = json.dumps(combo)
self.send_message(c)
示例8: test_spamc_unix_headers
# 需要导入模块: from mimetools import Message [as 别名]
# 或者: from mimetools.Message import get [as 别名]
def test_spamc_unix_headers(self):
with open(self.filename) as handle:
result = self.spamc_unix.headers(handle)
self.assertIn('message', result)
with open(self.filename) as headerhandle:
headers = Message(headerhandle)
org_subject = "Subject: %s" % headers.get('Subject')
new_subject = "Subject: %s" % result['headers'].get('Subject')
self.assertEqual(org_subject, new_subject)
示例9: _receive_handshake
# 需要导入模块: from mimetools import Message [as 别名]
# 或者: from mimetools.Message import get [as 别名]
def _receive_handshake(self):
while True:
buf = self.sock.recv(2048)
if "\r\n\r\n" in buf: break
headers, buf = buf.split("\r\n\r\n", 1)
status_line, headers = headers.split("\r\n", 1)
headers = Message(StringIO(headers))
if (
(not status_line.startswith('HTTP/1.1 101'))
or headers.get('Connection') != 'Upgrade'
or headers.get('Upgrade') != 'WebSocket'
):
raise WebSocketError('Invalid handshake')
return buf.split("fQJ,fN/4F4!~K~MH")[-1]
示例10: _receive_handshake
# 需要导入模块: from mimetools import Message [as 别名]
# 或者: from mimetools.Message import get [as 别名]
def _receive_handshake(self):
while True:
buf = self.sock.recv(2048)
if "\r\n\r\n" in buf: break
headers, buf = buf.split("\r\n\r\n", 1)
status_line, headers = headers.split("\r\n", 1)
headers = Message(StringIO(headers))
if (
status_line != 'HTTP/1.1 101 Web Socket Protocol Handshake'
or headers.get('Connection') != 'Upgrade'
or headers.get('Upgrade') != 'WebSocket'
):
raise WebSocketError('Invalid handshake')
return buf
示例11: test_spamc_tcp_headers
# 需要导入模块: from mimetools import Message [as 别名]
# 或者: from mimetools.Message import get [as 别名]
def test_spamc_tcp_headers(self):
with open(self.filename) as _handle:
data = _handle.read()
handle = StringIO(data)
result = self.spamc_tcp.headers(handle)
self.assertIn("message", result)
with open(self.filename) as headerhandle:
headers = Message(headerhandle)
org_subject = "Subject: %s" % headers.get("Subject")
new_subject = "Subject: %s" % result["headers"].get("Subject")
self.assertEqual(org_subject, new_subject)
示例12: handshake
# 需要导入模块: from mimetools import Message [as 别名]
# 或者: from mimetools.Message import get [as 别名]
def handshake(self):
data = self.request.recv(1024).strip()
headers = Message(StringIO(data.split('\r\n', 1)[1]))
if headers.get("Upgrade", None) != "websocket":
return
print "\r", self.thread.getName(), 'Handshaking'
key = headers['Sec-WebSocket-Key']
digest = b64encode(sha1(key + self.magic).hexdigest().decode('hex'))
response = 'HTTP/1.1 101 Switching Protocols\r\n'
response += 'Upgrade: websocket\r\n'
response += 'Connection: Upgrade\r\n'
response += 'Sec-WebSocket-Accept: %s\r\n\r\n' % digest
self.handshake_done = self.request.send(response)
示例13: handshake
# 需要导入模块: from mimetools import Message [as 别名]
# 或者: from mimetools.Message import get [as 别名]
def handshake(self):
print "handshake"
data = self.request.recv(1024).strip()
dSplit = data.split('\r\n', 1)
if len(dSplit) > 1 :
headers = Message(StringIO(data.split('\r\n', 1)[1]))
else:
headers = Message(StringIO(data.split('\r\n', 1)))
if headers.get("Upgrade", None) == None:
return
if headers.get("Upgrade", None).lower() != "websocket":
return
try:
key = headers['Sec-WebSocket-Key']
digest = b64encode(sha1(key + self.magic).hexdigest().decode('hex'))
print "has key"
except KeyError:
self.hasSecKey = False
print "no Sec-WebSocket-Key"
response = 'HTTP/1.1 101 Switching Protocols\r\n'
response += 'Upgrade: websocket\r\n'
response += 'Connection: Upgrade\r\n'
#this is also where we can distinguish a wifly from a browers
if(self.hasSecKey):
response += 'Sec-WebSocket-Accept: %s\r\n\r\n' % digest
print "sending back handshake"
self.handshake_done = self.request.send(response)
if(self.hasSecKey):
self.server.addBrowser(self)
else:
self.server.addWiFly(self)
示例14: handshake
# 需要导入模块: from mimetools import Message [as 别名]
# 或者: from mimetools.Message import get [as 别名]
def handshake(self, data):
print(data)
headers = Message(StringIO(data.strip().split('\r\n', 1)[1]))
if headers.get("Upgrade", None) != "websocket":
return False
logging.debug("handshaking...")
key = headers['Sec-WebSocket-Key']
digest = b64encode(sha1(key + self.magic).hexdigest().decode('hex'))
response = 'HTTP/1.1 101 Switching Protocols\r\n'
response += 'Upgrade: websocket\r\n'
response += 'Connection: Upgrade\r\n'
response += 'Sec-WebSocket-Accept: %s\r\n\r\n' % digest
#self.handshake_done = self.request.send(response)
self.out_buffer = response
return True
示例15: handshake
# 需要导入模块: from mimetools import Message [as 别名]
# 或者: from mimetools.Message import get [as 别名]
def handshake(self):
data = self.request.recv(1024).strip()
headers = Message(StringIO(data.split('\r\n', 1)[1]))
self.originally_recieved_headers = headers
if headers.get("Upgrade", None) != "websocket":
return
print 'Handshaking...'
key = headers['Sec-WebSocket-Key']
digest = b64encode(sha1(key + self.magic).hexdigest().decode('hex'))
response = 'HTTP/1.1 101 Switching Protocols\r\n'
response += 'Upgrade: websocket\r\n'
response += 'Connection: Upgrade\r\n'
response += 'Sec-WebSocket-Accept: %s\r\n\r\n' % digest
self.handshake_done = self.request.send(response)
if self.handshake_done:
Thread(target=self.send_notif_to_client).start()