• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python publish.publish函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: testRequestEnvironment

    def testRequestEnvironment(self):
        req = self._createRequest()
        publish(req, handle_errors=0) # Force expansion of URL variables

        self.assertEqual(str(req.URL), 'http://foobar.com/folder/item')
        self.assertEqual(req.URL['-1'], 'http://foobar.com/folder')
        self.assertEqual(req.URL['-2'], 'http://foobar.com')
        self.assertRaises(KeyError, req.URL.__getitem__, '-3')

        self.assertEqual(req.URL['0'], 'http://foobar.com')
        self.assertEqual(req.URL['1'], 'http://foobar.com/folder')
        self.assertEqual(req.URL['2'], 'http://foobar.com/folder/item')
        self.assertRaises(KeyError, req.URL.__getitem__, '3')

        self.assertEqual(req.URL.get('0'), 'http://foobar.com')
        self.assertEqual(req.URL.get('1'), 'http://foobar.com/folder')
        self.assertEqual(req.URL.get('2'), 'http://foobar.com/folder/item')
        self.assertEqual(req.URL.get('3', 'none'), 'none')

        self.assertEqual(req['SERVER_URL'], 'http://foobar.com')
        self.assertEqual(req['HTTP_HOST'], 'foobar.com')
        self.assertEqual(req['PATH_INFO'], '/folder/item')
        self.assertEqual(req['CONTENT_LENGTH'], '0')
        self.assertRaises(KeyError, req.__getitem__, 'HTTP_AUTHORIZATION')
        self.assertEqual(req['GATEWAY_INTERFACE'], 'TestFooInterface/1.0')
        self.assertEqual(req['HTTP_OFF_THE_WALL'], "Spam 'n eggs")

        self.assertRaises(KeyError, req.__getitem__,
                          'HTTP_WE_DID_NOT_PROVIDE_THIS')
开发者ID:jean,项目名称:zope.publisher,代码行数:29,代码来源:test_http.py


示例2: _testBaseTags

    def _testBaseTags(self, url, expected):
        # Make sure I1 and O1 are visible in the module namespace
        # so that the classes can be pickled.
        import transaction

        pub = BrowserPublication(self.db)

        ztapi.browserView(I1, 'view', DummyView)
        ztapi.setDefaultViewName(I1, 'view')
        ztapi.browserViewProviding(None, TestTraverser, IBrowserPublisher)

        ob = O1()

        ## the following is for running the tests standalone
        principalRegistry.defineDefaultPrincipal(
            'tim', 'timbot', 'ai at its best')

        # now place our object inside the application

        connection = self.db.open()
        app = connection.root()['Application']
        app.somepath = ob
        transaction.commit()
        connection.close()

        defineChecker(app.__class__, NamesChecker(somepath='xxx'))

        req = self._createRequest(url, pub)
        response = req.response

        publish(req, handle_errors=0)

        self.assertEqual(response.getBase(), expected)
开发者ID:grodniewicz,项目名称:oship,代码行数:33,代码来源:test_browserpublication.py


示例3: _publisherResults

 def _publisherResults(self, extra_env={}, body=b""):
     request = self._createRequest(extra_env, body)
     response = request.response
     publish(request, handle_errors=False)
     headers = response.getHeaders()
     return (
         "Status: %s\r\n" % response.getStatusString()
         +
         "\r\n".join([("%s: %s" % h) for h in headers]) + "\r\n\r\n"
         +
         response.consumeBody().decode('utf8')
         )
开发者ID:minddistrict,项目名称:zope.publisher,代码行数:12,代码来源:test_http.py


示例4: executeRequest

    def executeRequest(self, task):
        """Overrides HTTPServer.executeRequest()."""
        env = task.getCGIEnvironment()
        env['HTTPS'] = 'ON'
        try:
            del env['HTTP']
        except KeyError:
            pass
        instream = task.request_data.getBodyStream()

        request = self.request_factory(instream, task, env)
        response = request.response
        response.setHeaderOutput(task)
        response.setHTTPTransaction(task)
        publish(request)
开发者ID:Bluehorn,项目名称:M2Crypto,代码行数:15,代码来源:publisherhttps_server.py


示例5: application

 def application(environ, start_response):
     request = BrowserRequest(environ['wsgi.input'], environ)
     request.setPublication(pub)
     request = publish(request)
     response = request.response
     start_response(response.getStatusString(), response.getHeaders())
     return response.consumeBodyIter()
开发者ID:jean,项目名称:zope.server,代码行数:7,代码来源:test_wsgiserver.py


示例6: __call__

    def __call__(self, environ, start_response):
        """See zope.app.wsgi.interfaces.IWSGIApplication"""
        request = self.requestFactory(environ['wsgi.input'], environ)

        # Let's support post-mortem debugging
        handle_errors = environ.get('wsgi.handleErrors', self.handleErrors)

        request = publish(request, handle_errors=handle_errors)
        response = request.response
        # Get logging info from principal for log use
        logging_info = ILoggingInfo(request.principal, None)
        if logging_info is None:
            message = b'-'
        else:
            message = logging_info.getLogMessage()

        if not PYTHON2:
            # In python 3, convert message bytes to native string
            message = message.decode('latin1')

        environ['wsgi.logging_info'] = message
        if 'REMOTE_USER' not in environ:
            environ['REMOTE_USER'] = message

        # Start the WSGI server response
        start_response(response.getStatusString(), response.getHeaders())

        # Return the result body iterable.
        return response.consumeBodyIter()
开发者ID:zopefoundation,项目名称:zope.app.wsgi,代码行数:29,代码来源:__init__.py


示例7: test_shiftNameToApplication

    def test_shiftNameToApplication(self):
        r = self._createRequest()
        publish(r, handle_errors=0)
        appurl = r.getApplicationURL()

        # Verify that we can shift. It would be a little more realistic
        # if we could test this during traversal, but the api doesn't
        # let us do that.
        r = self._createRequest(extra_env={"PATH_INFO": "/xxx"})
        publish(r, handle_errors=0)
        r.shiftNameToApplication()
        self.assertEqual(r.getApplicationURL(), appurl+"/xxx")

        # Verify that we can only shift if we've traversed only a single name
        r = self._createRequest(extra_env={"PATH_INFO": "/folder/item"})
        publish(r, handle_errors=0)
        self.assertRaises(ValueError, r.shiftNameToApplication)
开发者ID:jean,项目名称:zope.publisher,代码行数:17,代码来源:test_http.py


示例8: _execute

    def _execute(self, path, command, split=True, **kw):
        env = {}
        env.update(kw)
        env['command'] = command

        path = self._translate(path)

        if split:
            env['path'], env['name'] = posixpath.split(path)
        else:
            env['path'] = path

        env['credentials'] = self.credentials
        request = self.request_factory(BytesIO(b''), env)

        # Note that publish() calls close() on request, which deletes the
        # response from the request, so that we need to keep track of it.
        # agroszer: 2008.feb.1.: currently the above seems not to be true
        # request will KEEP the response on close()
        # even more if a retry occurs in the publisher,
        # the response will be LOST, so we must accept the returned request
        request = publish(request)
        return request.response.getResult()
开发者ID:zopefoundation,项目名称:zope.server,代码行数:23,代码来源:publisher.py


示例9: __call__

    def __call__(self, request_string, handle_errors=True, form=None):
        # Commit work done by previous python code.
        commit()

        # Discard leading white space to make call layout simpler
        request_string = request_string.lstrip()

        # split off and parse the command line
        l = request_string.find('\n')
        command_line = request_string[:l].rstrip()
        request_string = request_string[l + 1:]
        method, path, protocol = command_line.split()

        # If we don't feed bytes to Python 3, it gets stuck in a loop
        # and ultimately raises HTTPException: got more than 100 headers.
        instream = io.BytesIO(request_string.encode("latin-1")
                              if not isinstance(request_string, bytes)
                              else request_string)
        environment = {
            "HTTP_COOKIE": self.httpCookie(path),
            "HTTP_HOST": 'localhost',
            "REQUEST_METHOD": method,
            "SERVER_PROTOCOL": protocol,
            "REMOTE_ADDR": '127.0.0.1',
        }

        headers = [split_header(header)
                   for header in headers_factory(instream).headers]
        for name, value in headers:
            name = ('_'.join(name.upper().split('-')))
            if name not in ('CONTENT_TYPE', 'CONTENT_LENGTH'):
                name = 'HTTP_' + name
            environment[name] = value.rstrip()

        auth_key = 'HTTP_AUTHORIZATION'
        if auth_key in environment:
            environment[auth_key] = auth_header(environment[auth_key])

        old_site = getSite()
        setSite(None)

        request_cls, publication_cls = self.chooseRequestClass(method, path,
                                                               environment)
        app = FunctionalTestSetup().getApplication()

        request = app._request(
            path, instream,
            environment=environment,
            request=request_cls, publication=publication_cls)
        if ISkinnable.providedBy(request):
            # only ISkinnable requests have skins
            setDefaultSkin(request)

        if form is not None:
            if request.form:
                raise ValueError("only one set of form values can be provided")
            request.form = form

        request = publish(request, handle_errors=handle_errors)

        response = ResponseWrapper(
            request.response, path, request,
            omit=('x-content-type-warning', 'x-powered-by'),
            )

        self.saveCookies(response)
        setSite(old_site)

        # sync Python connection:
        getRootFolder()._p_jar.sync()

        return response
开发者ID:zopefoundation,项目名称:zope.app.testing,代码行数:72,代码来源:functional.py


示例10: _publisherResults

 def _publisherResults(self, path, **kw):
     request = self._createRequest(path, **kw)
     response = request.response
     publish(request, handle_errors=False)
     return response._result
开发者ID:Andyvs,项目名称:TrackMonthlyExpenses,代码行数:5,代码来源:test_publisher.py


示例11: publish

 def publish(self, path):
     return publish(self.makeRequest(path)).response
开发者ID:grodniewicz,项目名称:oship,代码行数:2,代码来源:test_vhosting.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python schema.getFieldNames函数代码示例发布时间:2022-05-26
下一篇:
Python publish.mapply函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap