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


Python IBrowserRequest.providedBy方法代码示例

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


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

示例1: __bobo_traverse__

# 需要导入模块: from zope.publisher.interfaces.browser import IBrowserRequest [as 别名]
# 或者: from zope.publisher.interfaces.browser.IBrowserRequest import providedBy [as 别名]
    def __bobo_traverse__(self, REQUEST, name):
        """Hook for Zope 2 traversal

        This method is called by Zope 2's ZPublisher upon traversal.
        It allows us to trick it into faking the Zope 3 traversal system
        by using an ITraverser adapter.
        """
        if not IBrowserRequest.providedBy(REQUEST):
            # Try to get the REQUEST by acquisition
            REQUEST = getattr(self, 'REQUEST', None)
            if not IBrowserRequest.providedBy(REQUEST):
                REQUEST = FakeRequest()
        try:
            kw = dict(path=[name], request=REQUEST)
            return ITraverser(self).traverse(**kw).__of__(self)
        except (ComponentLookupError, NotFoundError,
                AttributeError, KeyError, NotFound):
            pass
        try:
            return getattr(self, name)
        except AttributeError:
            pass
        try:
            return self[name]
        except (AttributeError, KeyError):
            pass
        return self.__fallback_traverse__(REQUEST, name)
开发者ID:goschtl,项目名称:zope,代码行数:29,代码来源:traversable.py

示例2: test_stub_request

# 需要导入模块: from zope.publisher.interfaces.browser import IBrowserRequest [as 别名]
# 或者: from zope.publisher.interfaces.browser.IBrowserRequest import providedBy [as 别名]
    def test_stub_request(self):
        html_request = self.stub_request()
        js_request = self.stub_request(
            content_type='text/javascript', status=401, interfaces=IFoo)
        iface_request = self.stub_request(interfaces=[IFoo, IBar])

        self.replay()

        self.assertTrue(IDefaultBrowserLayer.providedBy(html_request))
        self.assertTrue(IBrowserRequest.providedBy(html_request))
        self.assertEqual(html_request.debug, False)
        self.assertEqual(html_request.response.getHeader(
                'Content-Type'), 'text/html')
        self.assertEqual(html_request.response.getStatus(), 200)

        self.assertTrue(IDefaultBrowserLayer.providedBy(js_request))
        self.assertTrue(IBrowserRequest.providedBy(js_request))
        self.assertTrue(IFoo.providedBy(js_request))
        self.assertEqual(js_request.debug, False)
        self.assertEqual(js_request.response.getHeader(
                'Content-Type'), 'text/javascript')
        self.assertEqual(js_request.response.getStatus(), 401)

        self.assertTrue(IFoo.providedBy(iface_request))
        self.assertTrue(IBar.providedBy(iface_request))
        self.assertTrue(IDefaultBrowserLayer.providedBy(iface_request))
        self.assertTrue(IBrowserRequest.providedBy(iface_request))
        self.assertEqual(html_request.debug, False)
        self.assertEqual(html_request.response.getHeader(
                'Content-Type'), 'text/html')
        self.assertEqual(html_request.response.getStatus(), 200)
开发者ID:4teamwork,项目名称:ftw.testing,代码行数:33,代码来源:test_testcase.py

示例3: translate

# 需要导入模块: from zope.publisher.interfaces.browser import IBrowserRequest [as 别名]
# 或者: from zope.publisher.interfaces.browser.IBrowserRequest import providedBy [as 别名]
    def translate(self, domain, msgid, mapping=None, context=None,
                  target_language=None, default=None):
        """
        Translate a message using Unicode.
        """
        if not msgid:
            # refuse to translate an empty msgid
            return default

        # ZPT passes the object as context.  That's wrong according to spec.
        if not IBrowserRequest.providedBy(context):
            context = aq_acquire(context, 'REQUEST')
        text = msgid

        catalogs = self.getCatalogsForTranslation(context, domain, target_language)
        for catalog in catalogs:
            try:
                text = getMessage(catalog, msgid, default)
            except KeyError:
                # it's not in this catalog, try the next one
                continue
            # found!
            break
        else:
            # Did the fallback fail? Sigh, use the default if it is not None.
            if default is not None:
                text = default

        # Now we need to do the interpolation
        return self.interpolate(text, mapping)
开发者ID:dtgit,项目名称:dtedu,代码行数:32,代码来源:PlacelessTranslationService.py

示例4: traverse

# 需要导入模块: from zope.publisher.interfaces.browser import IBrowserRequest [as 别名]
# 或者: from zope.publisher.interfaces.browser.IBrowserRequest import providedBy [as 别名]
 def traverse(self, name, furtherPath):
     # For some reason, when the adapter is constructed, the adapted
     # object is stored as self._subject rather than self.context.
     # I like self.context.
     #import pdb; pdb.set_trace()
     self.context = self._subject
     if name == 'keywords':
         tag_class = Keyword
     else:
         # We ignore it...
         return super(ImageRepositoryTraversable, self).traverse(name, furtherPath)
     # Now the guts of it...
     subpath = self.popFurtherPath(furtherPath)
     # furtherPath is now an empty list
     # Find the REQUEST
     REQUEST = getattr(self.context, 'REQUEST', None)
     if not IBrowserRequest.providedBy(REQUEST):
         REQUEST = FakeRequest()
     if len(subpath) == 0:
         return zapi.getView(self.context, name, REQUEST)
     #print name, furtherPath, subpath
     if len(subpath) == 1:
         furtherPath.append('index.html')
         tag = tag_class(subpath[0]).__of__(self.context)
     elif subpath[-1].startswith('@@'):
         furtherPath.append(subpath[-1])
         tag = tag_class(subpath[:-1]).__of__(self.context)
     else:
         furtherPath.append('index.html')
         tag = tag_class(subpath).__of__(self.context)
     return tag
开发者ID:a25kk,项目名称:stv2,代码行数:33,代码来源:traversal.py

示例5: endRequest

# 需要导入模块: from zope.publisher.interfaces.browser import IBrowserRequest [as 别名]
# 或者: from zope.publisher.interfaces.browser.IBrowserRequest import providedBy [as 别名]
    def endRequest(self, request, object):
        superclass = zope.app.publication.browser.BrowserPublication
        superclass.endRequest(self, request, object)

        da.clear_request_started()

        getUtility(IOpenLaunchBag).clear()

        # Maintain operational statistics.
        if getattr(request, '_wants_retry', False):
            OpStats.stats['retries'] += 1
        else:
            OpStats.stats['requests'] += 1

            # Increment counters for HTTP status codes we track individually
            # NB. We use IBrowserRequest, as other request types such as
            # IXMLRPCRequest use IHTTPRequest as a superclass.
            # This should be fine as Launchpad only deals with browser
            # and XML-RPC requests.
            if IBrowserRequest.providedBy(request):
                OpStats.stats['http requests'] += 1
                status = request.response.getStatus()
                if status == 404:  # Not Found
                    OpStats.stats['404s'] += 1
                elif status == 500:  # Unhandled exceptions
                    OpStats.stats['500s'] += 1
                elif status == 503:  # Timeouts
                    OpStats.stats['503s'] += 1

                # Increment counters for status code groups.
                status_group = str(status)[0] + 'XXs'
                OpStats.stats[status_group] += 1

                # Increment counter for 5XXs_b.
                if is_browser(request) and status_group == '5XXs':
                    OpStats.stats['5XXs_b'] += 1

        # Make sure our databases are in a sane state for the next request.
        thread_name = threading.currentThread().getName()
        for name, store in getUtility(IZStorm).iterstores():
            try:
                assert store._connection._state != STATE_DISCONNECTED, (
                    "Bug #504291: Store left in a disconnected state.")
            except AssertionError:
                # The Store is in a disconnected state. This should
                # not happen, as store.rollback() should have been called
                # by now. Log an OOPS so we know about this. This
                # is Bug #504291 happening.
                getUtility(IErrorReportingUtility).raising(
                    sys.exc_info(), request)
                # Repair things so the server can remain operational.
                store.rollback()
            # Reset all Storm stores when not running the test suite.
            # We could reset them when running the test suite but
            # that'd make writing tests a much more painful task. We
            # still reset the slave stores though to minimize stale
            # cache issues.
            if thread_name != 'MainThread' or name.endswith('-slave'):
                store.reset()
开发者ID:pombreda,项目名称:UnnaturalCodeFork,代码行数:61,代码来源:publication.py

示例6: utranslate

# 需要导入模块: from zope.publisher.interfaces.browser import IBrowserRequest [as 别名]
# 或者: from zope.publisher.interfaces.browser.IBrowserRequest import providedBy [as 别名]
def utranslate(domain, msgid, mapping=None, context=None, target_language=None, default=None):
    # We used to pass an object as context.
    if not IBrowserRequest.providedBy(context):
        context = aq_acquire(context, "REQUEST")
    # The signature of zope.i18n's translate has the msgid and domain switched
    return translate(
        msgid, domain=domain, mapping=mapping, context=context, target_language=target_language, default=default
    )
开发者ID:adam139,项目名称:Products.CMFPlone,代码行数:10,代码来源:i18nl10n.py

示例7: schoolToolTraverseSubscriber

# 需要导入模块: from zope.publisher.interfaces.browser import IBrowserRequest [as 别名]
# 或者: from zope.publisher.interfaces.browser.IBrowserRequest import providedBy [as 别名]
def schoolToolTraverseSubscriber(event):
    """A subscriber to BeforeTraverseEvent.

    Adds DevMode layer to the request.
    """
    if (ISchoolToolApplication.providedBy(event.object) and
        IBrowserRequest.providedBy(event.request)):
        directlyProvides(event.request,
                         directlyProvidedBy(event.request) + IDevModeLayer)
开发者ID:achouhans,项目名称:schooltool-2.8.5,代码行数:11,代码来源:skin.py

示例8: __call__

# 需要导入模块: from zope.publisher.interfaces.browser import IBrowserRequest [as 别名]
# 或者: from zope.publisher.interfaces.browser.IBrowserRequest import providedBy [as 别名]
 def __call__(self, objectId, instance, *args, **kw):
     request = instance.request
     if IBrowserRequest.providedBy(request):
         return {'request:SERVER_NAME':
                     (request.get('SERVER_NAME', u''),
                      request.get('SERVER_PORT', u''),
                      request.getApplicationURL(),)}
     else:
         return ()
开发者ID:Zojax,项目名称:zojax.cache,代码行数:11,代码来源:default.py

示例9: _translate

# 需要导入模块: from zope.publisher.interfaces.browser import IBrowserRequest [as 别名]
# 或者: from zope.publisher.interfaces.browser.IBrowserRequest import providedBy [as 别名]
def _translate(context, msg):
    """helper to translate a term if its a messageid
    """
    if not isinstance(msg, Message):
        return msg
    if not IBrowserRequest.providedBy(context):
        context = aq_acquire(context, 'REQUEST')
    msg = translate(msg, context=context).strip()
    msg = '\n'.join([_.strip() for _ in msg.split('\n')])  # needed if vdex
    return msg
开发者ID:collective,项目名称:collective.dynatree,代码行数:12,代码来源:utils.py

示例10: getEmptyTitle

# 需要导入模块: from zope.publisher.interfaces.browser import IBrowserRequest [as 别名]
# 或者: from zope.publisher.interfaces.browser.IBrowserRequest import providedBy [as 别名]
def getEmptyTitle(context, translated=True):
    """Returns string to be used for objects with no title or id"""
    # The default is an extra fancy unicode elipsis
    empty = unicode("\x5b\xc2\xb7\xc2\xb7\xc2\xb7\x5d", "utf-8")
    if translated:
        if context is not None:
            if not IBrowserRequest.providedBy(context):
                context = aq_get(context, "REQUEST", None)
        empty = translate("title_unset", domain="plone", context=context, default=empty)
    return empty
开发者ID:nrb,项目名称:Products.CMFPlone,代码行数:12,代码来源:utils.py

示例11: translate

# 需要导入模块: from zope.publisher.interfaces.browser import IBrowserRequest [as 别名]
# 或者: from zope.publisher.interfaces.browser.IBrowserRequest import providedBy [as 别名]
    def translate(self, msgid, domain=None, mapping=None, context=None,
                  target_language=None, default=None):
        # Translate method for resticted code like skins.
        if context is not None:
            if not IBrowserRequest.providedBy(context):
                context = aq_get(context, 'REQUEST', None)

        return translate(msgid, domain=domain, mapping=mapping,
                         context=context, target_language=target_language,
                         default=default)
开发者ID:erral,项目名称:Products.CMFPlone,代码行数:12,代码来源:TranslationServiceTool.py

示例12: unauthorized

# 需要导入模块: from zope.publisher.interfaces.browser import IBrowserRequest [as 别名]
# 或者: from zope.publisher.interfaces.browser.IBrowserRequest import providedBy [as 别名]
 def unauthorized(self, id, request):
     if not IBrowserRequest.providedBy(request) or request.method == 'PUT':
         next = getNextUtility(self, IAuthentication)
         return next.unauthorized(id, request)
     if str(request.URL).endswith('.ics'):
         # Special case: testing shows that Mozilla Calendar does not send
         # the Authorization header unless challenged.  It is pointless
         # to redirect an iCalendar client to an HTML login form.
         next = getNextUtility(self, IAuthentication)
         return next.unauthorized(id, request)
     return self.authPlugin.unauthorized(id, request)
开发者ID:achouhans,项目名称:schooltool-2.8.5,代码行数:13,代码来源:security.py

示例13: translate

# 需要导入模块: from zope.publisher.interfaces.browser import IBrowserRequest [as 别名]
# 或者: from zope.publisher.interfaces.browser.IBrowserRequest import providedBy [as 别名]
    def translate(self, domain, msgid, mapping=None, context=None, target_language=None, default=None):
        # Translate a message using Unicode.
        if not msgid:
            # refuse to translate an empty msgid
            return default

        # ZPT passes the object as context.  That's wrong according to spec.
        if not IBrowserRequest.providedBy(context):
            context = aq_acquire(context, "REQUEST")
        text = msgid

        return z3translate(msgid, domain, mapping, context, target_language, default)
开发者ID:plone,项目名称:Products.PlacelessTranslationService,代码行数:14,代码来源:PlacelessTranslationService.py

示例14: traverse

# 需要导入模块: from zope.publisher.interfaces.browser import IBrowserRequest [as 别名]
# 或者: from zope.publisher.interfaces.browser.IBrowserRequest import providedBy [as 别名]
 def traverse(self, name, furtherPath):
     context = self._subject
     __traceback_info__ = (context, name, furtherPath)
     # Find the REQUEST
     REQUEST = getattr(context, 'REQUEST', None)
     if not IBrowserRequest.providedBy(REQUEST):
         REQUEST = FakeRequest()
     # Try to lookup a view
     try:
         return getView(context, name, REQUEST)
     except ComponentLookupError:
         pass
开发者ID:goschtl,项目名称:zope,代码行数:14,代码来源:traversable.py

示例15: traverse

# 需要导入模块: from zope.publisher.interfaces.browser import IBrowserRequest [as 别名]
# 或者: from zope.publisher.interfaces.browser.IBrowserRequest import providedBy [as 别名]
 def traverse(self, name, furtherPath):
     context = self._subject
     __traceback_info__ = (context, name, furtherPath)
     # Find the REQUEST
     REQUEST = getattr(context, "REQUEST", None)
     if not IBrowserRequest.providedBy(REQUEST):
         REQUEST = FakeRequest()
         setDefaultSkin(REQUEST)
     # Try to lookup a view
     try:
         return getMultiAdapter((context, REQUEST), Interface, name)
     except ComponentLookupError:
         pass
开发者ID:wpjunior,项目名称:proled,代码行数:15,代码来源:traversable.py


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