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


Python mimetools.Message类代码示例

本文整理汇总了Python中mimetools.Message的典型用法代码示例。如果您正苦于以下问题:Python Message类的具体用法?Python Message怎么用?Python Message使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Message类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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


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