當前位置: 首頁>>代碼示例>>Python>>正文


Python Protocol.transport方法代碼示例

本文整理匯總了Python中protocol.Protocol.transport方法的典型用法代碼示例。如果您正苦於以下問題:Python Protocol.transport方法的具體用法?Python Protocol.transport怎麽用?Python Protocol.transport使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在protocol.Protocol的用法示例。


在下文中一共展示了Protocol.transport方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _perform_request

# 需要導入模塊: from protocol import Protocol [as 別名]
# 或者: from protocol.Protocol import transport [as 別名]
    def _perform_request(self, _, request, session):
        request.setHeader('content-type', 'application/stratum')
        request.setHeader('server', settings.USER_AGENT)
        request.setHeader('x-session-timeout', session.sessionTimeout)
        request.setHeader('access-control-allow-origin', '*') # Allow access from any other domain
          
        # Update client's IP address     
        session.transport.peer = request.getHost()
 
        # Although it isn't intuitive at all, request.getHeader reads request headers,
        # but request.setHeader (few lines above) writes response headers...
        if 'application/stratum' not in request.getHeader('content-type'):
            session.transport.write("%s\n" % json.dumps({'id': None, 'result': None, 'error': (-1, "Content-type must be 'application/stratum'. See http://stratum.bitcoin.cz for more info.", "")}))
            self._finish(None, request, session.transport, session.lock)
            return
        
        if not session.protocol:            
            # Build a "protocol connection"
            proto = Protocol()
            proto.transport = session.transport
            proto.factory = self
            proto.connectionMade()
            session.protocol = proto
        else:
            proto = session.protocol
 
        # Update callback URL if presented
        callback_url = request.getHeader('x-callback-url')
        if callback_url != None:
            if callback_url == '':
                # Blank value of callback URL switches HTTP Push back to HTTP Poll
                session.transport.push_url = None
            else:
                session.transport.push_url = callback_url 
                  
        data = request.content.read()
        if data:
            counter = RequestCounter()
            counter.on_finish.addCallback(self._finish, request, session.transport, session.lock)
            proto.dataReceived(data, request_counter=counter)
        else:
            # Ping message (empty request) of HTTP Polling
            self._finish(None, request, session.transport, session.lock) 
開發者ID:300184,項目名稱:eth-stratum-mining-proxy,代碼行數:45,代碼來源:http_transport.py


注:本文中的protocol.Protocol.transport方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。