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


Python Protocol.factory方法代码示例

本文整理汇总了Python中protocol.Protocol.factory方法的典型用法代码示例。如果您正苦于以下问题:Python Protocol.factory方法的具体用法?Python Protocol.factory怎么用?Python Protocol.factory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在protocol.Protocol的用法示例。


在下文中一共展示了Protocol.factory方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _perform_request

# 需要导入模块: from protocol import Protocol [as 别名]
# 或者: from protocol.Protocol import factory [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.factory方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。