當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。