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


Python server.NOT_DONE_YET属性代码示例

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


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

示例1: render

# 需要导入模块: from twisted.web import server [as 别名]
# 或者: from twisted.web.server import NOT_DONE_YET [as 别名]
def render(self, request):
        """Render this request, from my server.

        This will always be asynchronous, and therefore return NOT_DONE_YET.
        It spins off a request to the pb client, and either adds it to the list
        of pending issues or requests it immediately, depending on if the
        client is already connected.
        """
        if not self.publisher:
            self.pending.append(request)
            if not self.waiting:
                self.waiting = 1
                bf = pb.PBClientFactory()
                timeout = 10
                if self.host == "unix":
                    reactor.connectUNIX(self.port, bf, timeout)
                else:
                    reactor.connectTCP(self.host, self.port, bf, timeout)
                d = bf.getRootObject()
                d.addCallbacks(self.connected, self.notConnected)

        else:
            i = Issue(request)
            self.publisher.callRemote('request', request).addCallbacks(i.finished, i.failed)
        return server.NOT_DONE_YET 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:27,代码来源:distrib.py

示例2: render

# 需要导入模块: from twisted.web import server [as 别名]
# 或者: from twisted.web.server import NOT_DONE_YET [as 别名]
def render(self, resource):
        """
        Render the given resource as a response to this request.

        This implementation only handles a few of the most common behaviors of
        resources.  It can handle a render method that returns a string or
        C{NOT_DONE_YET}.  It doesn't know anything about the semantics of
        request methods (eg HEAD) nor how to set any particular headers.
        Basically, it's largely broken, but sufficient for some tests at least.
        It should B{not} be expanded to do all the same stuff L{Request} does.
        Instead, L{DummyRequest} should be phased out and L{Request} (or some
        other real code factored in a different way) used.
        """
        result = resource.render(self)
        if result is NOT_DONE_YET:
            return
        self.write(result)
        self.finish() 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:20,代码来源:requesthelper.py

示例3: test_simpleRender

# 需要导入模块: from twisted.web import server [as 别名]
# 或者: from twisted.web.server import NOT_DONE_YET [as 别名]
def test_simpleRender(self):
        """
        L{renderElement} returns NOT_DONE_YET and eventually
        writes the rendered L{Element} to the request before finishing the
        request.
        """
        element = TestElement()

        d = self.request.notifyFinish()

        def check(_):
            self.assertEqual(
                b"".join(self.request.written),
                b"<!DOCTYPE html>\n"
                b"<p>Hello, world.</p>")
            self.assertTrue(self.request.finished)

        d.addCallback(check)

        self.assertIdentical(NOT_DONE_YET, renderElement(self.request, element))

        return d 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:24,代码来源:test_template.py

示例4: authenticated

# 需要导入模块: from twisted.web import server [as 别名]
# 或者: from twisted.web.server import NOT_DONE_YET [as 别名]
def authenticated(func):
        def _authenticate(self, request):
            session = request.getSession()
            if session not in self.authenticated_sessions and "localhost" not in self.authenticated_sessions:
                session.expire()
                request.setResponseCode(401)
                request.write('<html><body><div><span style="color:red">Authorization Error</span></div>'
                              '<h2>Permission Denied</h2></body></html>')
                request.finish()
                return server.NOT_DONE_YET
            else:
                if request.getHeader("Content-Type") == "application/json":
                    request.args = json.loads(request.content.read())
                func(self, request)
                return server.NOT_DONE_YET
        return wraps(func)(_authenticate) 
开发者ID:OpenBazaar,项目名称:OpenBazaar-Server,代码行数:18,代码来源:restapi.py

示例5: add_social_account

# 需要导入模块: from twisted.web import server [as 别名]
# 或者: from twisted.web.server import NOT_DONE_YET [as 别名]
def add_social_account(self, request):
        try:
            p = Profile(self.db)
            if "account_type" in request.args and "username" in request.args:
                p.add_social_account(request.args["account_type"][0],
                                     request.args["username"][0],
                                     request.args["proof"][0] if
                                     "proof" in request.args else None)
            else:
                raise Exception("Missing required fields")
            request.write(json.dumps({"success": True}))
            request.finish()
            return server.NOT_DONE_YET
        except Exception, e:
            request.write(json.dumps({"success": False, "reason": e.message}, indent=4))
            request.finish()
            return server.NOT_DONE_YET 
开发者ID:OpenBazaar,项目名称:OpenBazaar-Server,代码行数:19,代码来源:restapi.py

示例6: check_for_payment

# 需要导入模块: from twisted.web import server [as 别名]
# 或者: from twisted.web.server import NOT_DONE_YET [as 别名]
def check_for_payment(self, request):
        if not self.protocol.blockchain.connected:
            request.write(json.dumps({"success": False, "reason": "libbitcoin server offline"}, indent=4))
            request.finish()
            return server.NOT_DONE_YET
        try:
            check_order_for_payment(request.args["order_id"][0], self.db,
                                    self.protocol.blockchain,
                                    self.mserver.protocol.get_notification_listener(),
                                    self.protocol.testnet)
            request.write(json.dumps({"success": True}, indent=4))
            request.finish()
            return server.NOT_DONE_YET
        except Exception, e:
            request.write(json.dumps({"success": False, "reason": e.message}, indent=4))
            request.finish()
            return server.NOT_DONE_YET 
开发者ID:OpenBazaar,项目名称:OpenBazaar-Server,代码行数:19,代码来源:restapi.py

示例7: migrate

# 需要导入模块: from twisted.web import server [as 别名]
# 或者: from twisted.web.server import NOT_DONE_YET [as 别名]
def migrate(self, request):
        try:
            path = migratev2(self.db)
            request.setHeader('content-disposition', 'filename="listings.csv"')
            request.setHeader('content-type', "text/csv")
            f = open(path)
            while 1:
                d = f.read(2048)
                if not d:
                    break
                request.write(d)
            f.close()
            request.finish()
            return server.NOT_DONE_YET
        except Exception, e:
            request.write(json.dumps({"success": False, "reason": e.message}))
            request.finish()
            return server.NOT_DONE_YET 
开发者ID:OpenBazaar,项目名称:OpenBazaar-Server,代码行数:20,代码来源:restapi.py

示例8: render

# 需要导入模块: from twisted.web import server [as 别名]
# 或者: from twisted.web.server import NOT_DONE_YET [as 别名]
def render(self, request):
        try:
            data = super(JsonResource, self).render(request)
            if data == NOT_DONE_YET:
                return data
            data = {
                **{'status': 'ok'},
                **data
            }
            return self.render_json(request, data)
        except Exception as e:
            request.setResponseCode(400)
            data = {
                'status': 'error',
                'msg': str(e)
            }
            return self.render_json(request, data)


#------------------------------------------------------------------------------- 
开发者ID:ljanyst,项目名称:scrapy-do,代码行数:22,代码来源:webservice.py

示例9: render

# 需要导入模块: from twisted.web import server [as 别名]
# 或者: from twisted.web.server import NOT_DONE_YET [as 别名]
def render(self, resource):
        """
        Render the given resource as a response to this request.

        This implementation only handles a few of the most common behaviors of
        resources.  It can handle a render method that returns a string or
        C{NOT_DONE_YET}.  It doesn't know anything about the semantics of
        request methods (eg HEAD) nor how to set any particular headers.
        Basically, it's largely broken, but sufficient for some tests at least.
        It should B{not} be expanded to do all the same stuff L{Request} does.
        Instead, L{DummyRequest} should be phased out and L{Request} (or some
        other real code factored in a different way) used.
        """
        result = resource.render(self)
        if result is server.NOT_DONE_YET:
            return
        self.write(result)
        self.finish() 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:20,代码来源:test_web.py

示例10: test_render_POST_queue_messages

# 需要导入模块: from twisted.web import server [as 别名]
# 或者: from twisted.web.server import NOT_DONE_YET [as 别名]
def test_render_POST_queue_messages(self):
        status_worker = Mock()
        status_worker.queueMessage = Mock()
        status_worker.queueMessage.return_value = succeed(None)
        resource = StatusHandlerResource(status_worker)
        message = {
            "event_type": (
                factory.make_name("type") + "/" + factory.make_name("sub_type")
            ),
            "origin": factory.make_name("origin"),
            "name": factory.make_name("name"),
            "description": factory.make_name("description"),
        }
        token = factory.make_name("token")
        request = self.make_request(
            content=json.dumps(message).encode("ascii"), token=token
        )
        output = resource.render_POST(request)
        self.assertEquals(NOT_DONE_YET, output)
        self.assertEquals(204, request.responseCode)
        self.assertThat(
            status_worker.queueMessage, MockCalledOnceWith(token, message)
        ) 
开发者ID:maas,项目名称:maas,代码行数:25,代码来源:test_api_twisted.py

示例11: test_processMessages_calls_loseConnection_if_missing_type_field

# 需要导入模块: from twisted.web import server [as 别名]
# 或者: from twisted.web.server import NOT_DONE_YET [as 别名]
def test_processMessages_calls_loseConnection_if_missing_type_field(self):
        protocol, factory = self.make_protocol()
        protocol.user = maas_factory.make_User()
        mock_loseConnection = self.patch_autospec(protocol, "loseConnection")
        self.patch_autospec(
            protocol, "handleRequest"
        ).return_value = NOT_DONE_YET
        messages = [
            {"request_id": 1},
            {"type": MSG_TYPE.REQUEST, "request_id": 2},
        ]
        protocol.messages = deque(messages)
        self.expectThat([messages[0]], Equals(protocol.processMessages()))
        self.expectThat(
            mock_loseConnection,
            MockCalledOnceWith(
                STATUSES.PROTOCOL_ERROR,
                "Missing type field in the received message.",
            ),
        ) 
开发者ID:maas,项目名称:maas,代码行数:22,代码来源:test_protocol.py

示例12: delayed

# 需要导入模块: from twisted.web import server [as 别名]
# 或者: from twisted.web.server import NOT_DONE_YET [as 别名]
def delayed(f):
    def decorator(resource, request):
        @defer.inlineCallbacks
        def wrapper():
            try:
                yield f(resource, request)
            except Exception as e:
                log.error("Error in delayed decorator wrapped function: {e}", e=e)
                request.setResponseCode(http.INTERNAL_SERVER_ERROR)
                request.finish()
        wrapper()
        return server.NOT_DONE_YET
    return decorator 
开发者ID:moira-alert,项目名称:worker,代码行数:15,代码来源:request.py

示例13: render

# 需要导入模块: from twisted.web import server [as 别名]
# 或者: from twisted.web.server import NOT_DONE_YET [as 别名]
def render(self, request):
        """
        Turn the request into the appropriate C{environ} C{dict} suitable to be
        passed to the WSGI application object and then pass it on.

        The WSGI application object is given almost complete control of the
        rendering process.  C{NOT_DONE_YET} will always be returned in order
        and response completion will be dictated by the application object, as
        will the status, headers, and the response body.
        """
        response = _WSGIResponse(
            self._reactor, self._threadpool, self._application, request)
        response.start()
        return NOT_DONE_YET 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:16,代码来源:wsgi.py

示例14: render

# 需要导入模块: from twisted.web import server [as 别名]
# 或者: from twisted.web.server import NOT_DONE_YET [as 别名]
def render(self, request):
        """Handle a SOAP command."""
        data = request.content.read()

        p, header, body, attrs = SOAPpy.parseSOAPRPC(data, 1, 1, 1)

        methodName, args, kwargs = p._name, p._aslist, p._asdict

        # deal with changes in SOAPpy 0.11
        if callable(args):
            args = args()
        if callable(kwargs):
            kwargs = kwargs()

        function = self.lookupFunction(methodName)

        if not function:
            self._methodNotFound(request, methodName)
            return server.NOT_DONE_YET
        else:
            if hasattr(function, "useKeywords"):
                keywords = {}
                for k, v in kwargs.items():
                    keywords[str(k)] = v
                d = defer.maybeDeferred(function, **keywords)
            else:
                d = defer.maybeDeferred(function, *args)

        d.addCallback(self._gotResult, request, methodName)
        d.addErrback(self._gotError, request, methodName)
        return server.NOT_DONE_YET 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:33,代码来源:soap.py

示例15: finished

# 需要导入模块: from twisted.web import server [as 别名]
# 或者: from twisted.web.server import NOT_DONE_YET [as 别名]
def finished(self, result):
        if result != server.NOT_DONE_YET:
            assert isinstance(result, str), "return value not a string"
            self.request.write(result)
            self.request.finish() 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:7,代码来源:distrib.py


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