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


Python IRequest.providedBy方法代码示例

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


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

示例1: allows

# 需要导入模块: from pyramid.interfaces import IRequest [as 别名]
# 或者: from pyramid.interfaces.IRequest import providedBy [as 别名]
    def allows(self, principals, permission=None):
        """ ``principals`` may either be 1) a sequence of principal
        indentifiers, 2) a single principal identifier, or 3) a Pyramid
        request, which indicates that all the effective principals implied by
        the request are used.

        ``permission`` may be ``None`` if this index is configured with
        only a single permission.  Otherwise a permission name must be passed
        or an error will be raised.
        """
        permissions = self.discriminator.permissions
        if permission is None:
            if len(permissions) > 1:
                raise ValueError('Must pass a permission')
            else:
                permission = list(permissions)[0]
        else:
            if permissions is not None and not permission in permissions:
                raise ValueError(
                    'This index does not support the %s '
                    'permission' % (permission,)
                    )
        if IRequest.providedBy(principals):
            principals = effective_principals(principals)
        elif not is_nonstr_iter(principals):
            principals = (principals,)
        principals = [ get_principal_repr(p) for p in principals ]
        values = [(principal, permission) for principal in principals]
        return hypatia.query.Any(self, values)
开发者ID:Web5design,项目名称:substanced,代码行数:31,代码来源:indexes.py

示例2: _authorize

# 需要导入模块: from pyramid.interfaces import IRequest [as 别名]
# 或者: from pyramid.interfaces.IRequest import providedBy [as 别名]
    def _authorize(*args, **kwargs):
        login_required = HTTPUnauthorized()
        login_required.headers['WWW-Authenticate'] = \
            'Basic realm="Manage bridge"'

        if IRequest.providedBy(args[0]):
            request = args[0]
        else:
            request = args[0].request

        authorization = request.headers.get('Authorization', None)
        if not authorization:
            raise login_required

        _basic, authorization = authorization.split(' ', 1)
        username, password = authorization.decode('base64').split(':', 1)

        settings = getUtility(ISettings)
        admin_user = settings.get('bridge.admin.username', object())
        admin_pass = settings.get('bridge.admin.password', object())

        if username != admin_user or password != admin_pass:
            raise login_required

        return fun(*args, **kwargs)
开发者ID:4teamwork,项目名称:ftw.bridge.proxy,代码行数:27,代码来源:utils.py

示例3: apply_async_web_process

# 需要导入模块: from pyramid.interfaces import IRequest [as 别名]
# 或者: from pyramid.interfaces.IRequest import providedBy [as 别名]
    def apply_async_web_process(self, args, kwargs):
        """Schedule a task from web process.

        Do not trigger the task until transaction commit. Check that we pass Request to the task as the first argument always. This is an extra complex sanity check.
        """
        #  Intercept request argumetn going to the function
        args_ = kwargs.get("args", [])
        kwargs_ = kwargs.get("kwargs", {})

        request, args_, kwargs_ = _pop_request_argument(args_, kwargs_)
        kwargs["args"] = args_
        kwargs["kwargs"] = kwargs_

        if not IRequest.providedBy(request):
            raise BadAsyncLifeCycleException("You must explicitly pass request as the first argument to asynchronous tasks as these tasks are bound to happen when the database transaction tied to the request lifecycle completes.")

        # If for whatever reason we were unable to get a request we'll just
        # skip this and call the original method to send this immediately.
        if not hasattr(request, "tm"):
            return super().apply_async(*args, **kwargs)

        # This will break things that expect to get an AsyncResult because
        # we're no longer going to be returning an async result from this when
        # called from within a request, response cycle. Ideally we shouldn't be
        # waiting for responses in a request/response cycle anyways though.
        request.tm.get().addAfterCommitHook(
            self._after_commit_hook,
            args=args,
            kws=kwargs,
        )
开发者ID:agronholm,项目名称:websauna,代码行数:32,代码来源:tasks.py

示例4: get_domain

# 需要导入模块: from pyramid.interfaces import IRequest [as 别名]
# 或者: from pyramid.interfaces.IRequest import providedBy [as 别名]
def get_domain(request):
    if IRequest.providedBy(request):
        referrer = get_referrer(request)
    else:
        referrer = request
    if not referrer:
        return ''
    return urlsplit(referrer).netloc.split(':')[0]
开发者ID:sixfeetup,项目名称:speak_friend,代码行数:10,代码来源:utils.py

示例5: guess_request

# 需要导入模块: from pyramid.interfaces import IRequest [as 别名]
# 或者: from pyramid.interfaces.IRequest import providedBy [as 别名]
def guess_request(view, *args, **kwargs):
    """Extract request from view arguments.

    Pyramid may place request as the first or second argumetn depending if view gets a context argument."""

    request = kwargs.get("request")
    if request:
        return request

    first_arg = args[0]
    if IRequest.providedBy(first_arg):
        return first_arg

    if len(args) >= 2:
        second_arg = args[1]
        if IRequest.providedBy(second_arg):
            return second_arg

    raise AssertionError("Could not determine request argument for view: {} args: {} kwargs: {}".format(view, args, kwargs))
开发者ID:agronholm,项目名称:websauna,代码行数:21,代码来源:csrf.py

示例6: __init__

# 需要导入模块: from pyramid.interfaces import IRequest [as 别名]
# 或者: from pyramid.interfaces.IRequest import providedBy [as 别名]
    def __init__(self, request: Request, obj: object):
        """
        :param obj: The underlying object we wish to wrap for traversing. Usually SQLALchemy model instance.
        """

        # Some safety checks we get arguments correctly.n
        assert IRequest.providedBy(request)

        self.request = request
        self.obj = obj
开发者ID:LukeSwart,项目名称:websauna,代码行数:12,代码来源:__init__.py

示例7: query_layout

# 需要导入模块: from pyramid.interfaces import IRequest [as 别名]
# 或者: from pyramid.interfaces.IRequest import providedBy [as 别名]
def query_layout(context, request, name=''):
    """ query named layout for context """
    assert IRequest.providedBy(request), u"must pass in a request object"

    for context in lineage(context):
        layout = request.registry.queryMultiAdapter(
            (context, request), ILayout, name)
        if layout is not None:
            return layout

    return None
开发者ID:WouterVH,项目名称:ptah,代码行数:13,代码来源:layout.py

示例8: allows

# 需要导入模块: from pyramid.interfaces import IRequest [as 别名]
# 或者: from pyramid.interfaces.IRequest import providedBy [as 别名]
    def allows(self, principals, permission):
        """ ``principals`` may either be 1) a sequence of principal
        indentifiers, 2) a single principal identifier, or 3) a Pyramid
        request, which indicates that all the effective principals implied by
        the request are used.

        ``permission`` must be a permission name.
        """
        if IRequest.providedBy(principals):
            principals = effective_principals(principals)
        elif not is_nonstr_iter(principals):
            principals = (principals,)
        return AllowsComparator(self, (principals, permission))
开发者ID:Pylons,项目名称:substanced,代码行数:15,代码来源:indexes.py

示例9: test_subclass_mutate_before_providedBy

# 需要导入模块: from pyramid.interfaces import IRequest [as 别名]
# 或者: from pyramid.interfaces.IRequest import providedBy [as 别名]
    def test_subclass_mutate_before_providedBy(self):
        from pyramid.interfaces import IRequest
        from pyramid.request import Request
        from pyramid.util import InstancePropertyHelper

        class RequestSub(Request):
            pass

        req = RequestSub({})
        helper = InstancePropertyHelper()
        helper.apply_properties(req, {'b': 'b'})

        self.assertTrue(IRequest.providedBy(req))
        self.assertTrue(IRequest.implementedBy(RequestSub))
开发者ID:AlanMachado,项目名称:pyramid,代码行数:16,代码来源:test_request.py

示例10: query_layout

# 需要导入模块: from pyramid.interfaces import IRequest [as 别名]
# 或者: from pyramid.interfaces.IRequest import providedBy [as 别名]
def query_layout(context, request, name=''):
    """ query named layout for context """
    assert IRequest.providedBy(request), "must pass in a request object"

    try:
        iface = request.request_iface
    except AttributeError:
        iface = IRequest

    adapters = request.registry.adapters

    for context in lineage(context):
        layout_factory = adapters.lookup(
            (providedBy(context), iface), ILayout, name=name)

        if layout_factory is not None:
            return layout_factory, context

    return None, None
开发者ID:runyaga,项目名称:ptah,代码行数:21,代码来源:layout.py

示例11: test_subclass_with_implementer

# 需要导入模块: from pyramid.interfaces import IRequest [as 别名]
# 或者: from pyramid.interfaces.IRequest import providedBy [as 别名]
    def test_subclass_with_implementer(self):
        from pyramid.interfaces import IRequest
        from pyramid.request import Request
        from pyramid.util import InstancePropertyHelper
        from zope.interface import implementer

        @implementer(IRequest)
        class RequestSub(Request):
            pass

        self.assertTrue(hasattr(Request, '__provides__'))
        self.assertTrue(hasattr(Request, '__implemented__'))
        self.assertTrue(hasattr(Request, '__providedBy__'))
        self.assertTrue(hasattr(RequestSub, '__provides__'))
        self.assertTrue(hasattr(RequestSub, '__providedBy__'))
        self.assertTrue(hasattr(RequestSub, '__implemented__'))

        req = RequestSub({})
        helper = InstancePropertyHelper()
        helper.apply_properties(req, {'b': 'b'})

        self.assertTrue(IRequest.providedBy(req))
        self.assertTrue(IRequest.implementedBy(RequestSub))
开发者ID:AlanMachado,项目名称:pyramid,代码行数:25,代码来源:test_request.py

示例12: test_instance_provides

# 需要导入模块: from pyramid.interfaces import IRequest [as 别名]
# 或者: from pyramid.interfaces.IRequest import providedBy [as 别名]
 def test_instance_provides(self):
     from pyramid.interfaces import IRequest
     inst = self._makeOne({})
     self.assertTrue(IRequest.providedBy(inst))
开发者ID:deshank,项目名称:pyramid,代码行数:6,代码来源:test_request.py

示例13: get_registration_service

# 需要导入模块: from pyramid.interfaces import IRequest [as 别名]
# 或者: from pyramid.interfaces.IRequest import providedBy [as 别名]
def get_registration_service(request: IRequest) -> IRegistrationService:
    assert IRequest.providedBy(request)
    return request.registry.queryAdapter(request, IRegistrationService)
开发者ID:agronholm,项目名称:websauna,代码行数:5,代码来源:utils.py

示例14: get_credential_activity_service

# 需要导入模块: from pyramid.interfaces import IRequest [as 别名]
# 或者: from pyramid.interfaces.IRequest import providedBy [as 别名]
def get_credential_activity_service(request: IRequest) -> ICredentialActivityService:
    assert IRequest.providedBy(request)
    return request.registry.queryAdapter(request, ICredentialActivityService)
开发者ID:agronholm,项目名称:websauna,代码行数:5,代码来源:utils.py

示例15: get_oauth_login_service

# 需要导入模块: from pyramid.interfaces import IRequest [as 别名]
# 或者: from pyramid.interfaces.IRequest import providedBy [as 别名]
def get_oauth_login_service(request: IRequest) -> IOAuthLoginService:
    assert IRequest.providedBy(request)
    return request.registry.queryAdapter(request, IOAuthLoginService)
开发者ID:agronholm,项目名称:websauna,代码行数:5,代码来源:utils.py


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