本文整理汇总了Python中mimetools.Message类的典型用法代码示例。如果您正苦于以下问题:Python Message类的具体用法?Python Message怎么用?Python Message使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Message类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _perform_handshake
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)
开发者ID:iam4423,项目名称:WebSocket,代码行数:32,代码来源:Client.py
示例2: handshake
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)
开发者ID:mk270,项目名称:oxmud-client,代码行数:26,代码来源:WebsocketSplitScreen.py
示例3: handshake
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)
开发者ID:blackcathikari,项目名称:coms4200gh,代码行数:27,代码来源:monitor22.py
示例4: test_spamc_unix_headers
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)
开发者ID:akissa,项目名称:spamc,代码行数:9,代码来源:test_spamc_unix.py
示例5: test_spamc_tcp_process
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"))
开发者ID:akissa,项目名称:spamc,代码行数:10,代码来源:test_spamc_stringio.py
示例6: test_spamc_unix_process
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')
)
开发者ID:akissa,项目名称:spamc,代码行数:11,代码来源:test_spamc_unix.py
示例7: handshake
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 'Handshaking...'
key = headers['Sec-WebSocket-Key']
digest = b64encode(sha1(key + self.magic).hexdigest().decode('hex'))
response = 'HTTP/1.1 101 Switching Protocols\r\n'+'Upgrade: websocket\r\n'+'Connection: Upgrade\r\n'
response += 'Sec-WebSocket-Accept: %s\r\n\r\n' % digest
self.handshake_done = self.request.send(response)
开发者ID:SushisMakis,项目名称:SmWebSocket,代码行数:11,代码来源:chat.py
示例8: test_spamc_tcp_headers
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)
开发者ID:akissa,项目名称:spamc,代码行数:11,代码来源:test_spamc_stringio.py
示例9: parse_headers
def parse_headers(header_string):
""" Parse a header-string into individual headers
Implementation based on: http://stackoverflow.com/a/5955949/95122
"""
# First line is request line, strip it out
if not header_string:
return dict()
request, headers = header_string.split('\r\n', 1)
if not headers:
return dict()
else:
header_msg = Message(StringIO(headers))
return dict(header_msg.items())
开发者ID:jishi9,项目名称:pyresttest,代码行数:13,代码来源:resttest.py
示例10: handshake
def handshake(self):
data = self.channel.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.channel.send(response)
self.valid_client = True
开发者ID:beelives,项目名称:EaST,代码行数:15,代码来源:WebSocketServer.py
示例11: handshake
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
开发者ID:sphaero,项目名称:WatMotje,代码行数:15,代码来源:websocketserver.py
示例12: handshake
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
开发者ID:ogoodman,项目名称:serf,代码行数:16,代码来源:ws_transport.py
示例13: _receive_handshake
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]
开发者ID:bpartridge,项目名称:amitu-websocket-client,代码行数:18,代码来源:websocket_client.py
示例14: _receive_handshake
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
开发者ID:grevian,项目名称:amitu-websocket-client,代码行数:18,代码来源:websocket_client.py
示例15: _open_stream
def _open_stream(self):
self.conn.request("GET", self.path, headers=self.request_headers)
resp = self.conn.getresponse()
content_type = None
try:
if resp.status != 200 or resp.msg.getmaintype() != 'multipart':
raise ConnectionError(
u"Unexpected response: {resp.status}\n"
u"{resp.msg}\n{data}"
.format(data=resp.read(), **locals()))
log.debug("Opened stream\n%s", resp.msg)
boundary = resp.msg.getparam('boundary')
assert boundary
fp = ReadlineAdapter(resp)
while True:
sep = fp.readline().rstrip()
if not sep:
# XXX: instead of this should just read two bytes
# after the end of the data?
sep = fp.readline().rstrip()
if sep != b'--' + boundary:
if sep != b'--' + boundary + b'--':
raise StreamingError(u"Bad boundary %r" % sep)
break
msg = Message(fp, seekable=0)
content_length = int(msg['content-length'])
# XXX: impose maximum limit on content_length?
data = fp.read(content_length)
if content_type:
bad_type = msg.gettype() != content_type
else:
bad_type = msg.getmaintype() != 'image'
content_type = msg.gettype()
if bad_type:
raise StreamingError(
u"Unexpected content-type\n{msg}\n{data}"
.format(**locals()))
log.debug("Got part\n%s", msg)
yield VideoFrame(data, msg.gettype())
finally:
resp.close()
开发者ID:dairiki,项目名称:puppyserv,代码行数:43,代码来源:webcam.py
示例16: handshake
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 '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:
me = {}
me["type"]="m"
me["time"]=time.time()
me["x"]=0
me["y"]=0
me["d"]=0
me["v"]=0
players.append(self)
me["pid"]=players.index(self)
memsg=jsone.encode(me)
for p in players:
if not p == self:
other = {}
other["type"]="m"
other["time"]=p.lastUpdate
other["x"]=p.lastX
other["y"]=p.lastY
other["d"]=p.lastDir
other["v"]=p.lastV
other["pid"]=players.index(p)
self.send_message(jsone.encode(other))
p.send_message(memsg)
tellAboutAsteroids(self)
tellAboutBot(self)
print "Player connected ("+str(len(players))+")"
开发者ID:programistagd,项目名称:space-robots-gameon,代码行数:39,代码来源:websocket.py
示例17: parseRequestHeaders
def parseRequestHeaders(self):
header_bytes = ""
header_count = 0
while True:
if header_count >= self.max_headers:
self.requestError(BAD_REQUEST,
"Bad request (too many headers)")
line = self.rin.readline()
header_bytes += line
header_count += 1
if line == '\r\n' or line == '\n' or line == '':
break
header_input = StringIO(header_bytes)
self.request_headers = Message(header_input)
开发者ID:Angel666,项目名称:android_hardware_intel,代码行数:14,代码来源:http.py
示例18: handshake
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)
开发者ID:flxhbck,项目名称:MarioKard,代码行数:37,代码来源:app.py
示例19: extract_http
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']
"""
开发者ID:BU-NU-CLOUD-SP16,项目名称:Network-traffic-collection,代码行数:24,代码来源:http.py
示例20: handshake
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"
开发者ID:davidbrazdil,项目名称:rhythmbox-mobile,代码行数:24,代码来源:ws.py
注:本文中的mimetools.Message类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论