当前位置: 首页>>代码示例>>Python>>正文


Python Message.get方法代码示例

本文整理汇总了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)
开发者ID:mk270,项目名称:oxmud-client,代码行数:28,代码来源:WebsocketSplitScreen.py

示例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"))
开发者ID:akissa,项目名称:spamc,代码行数:12,代码来源:test_spamc_stringio.py

示例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')
     )
开发者ID:akissa,项目名称:spamc,代码行数:13,代码来源:test_spamc_unix.py

示例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
开发者ID:lkheh,项目名称:EaST,代码行数:17,代码来源:WebSocketServer.py

示例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
开发者ID:ogoodman,项目名称:serf,代码行数:18,代码来源:ws_transport.py

示例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)
开发者ID:iam4423,项目名称:WebSocket,代码行数:34,代码来源:Client.py

示例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)
开发者ID:blackcathikari,项目名称:coms4200gh,代码行数:29,代码来源:monitor22.py

示例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)
开发者ID:akissa,项目名称:spamc,代码行数:11,代码来源:test_spamc_unix.py

示例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]
开发者ID:bpartridge,项目名称:amitu-websocket-client,代码行数:20,代码来源:websocket_client.py

示例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
开发者ID:grevian,项目名称:amitu-websocket-client,代码行数:20,代码来源:websocket_client.py

示例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)
开发者ID:akissa,项目名称:spamc,代码行数:13,代码来源:test_spamc_stringio.py

示例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)
开发者ID:Cougar,项目名称:websockets-test,代码行数:15,代码来源:websocketserver.py

示例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)
开发者ID:flxhbck,项目名称:MarioKard,代码行数:39,代码来源:app.py

示例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
开发者ID:sphaero,项目名称:WatMotje,代码行数:17,代码来源:websocketserver.py

示例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()
开发者ID:Mause,项目名称:websocket-notifications,代码行数:18,代码来源:server.py


注:本文中的mimetools.Message.get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。