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


Python HTTPRequest.set方法代码示例

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


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

示例1: _executeAsUser

# 需要导入模块: from ZPublisher.HTTPRequest import HTTPRequest [as 别名]
# 或者: from ZPublisher.HTTPRequest.HTTPRequest import set [as 别名]
def _executeAsUser(context_path, portal_path, uf_path, user_id, func, *args,
    **kwargs):
    """Reconstruct environment and execute func."""
    transaction = Zope2.zpublisher_transactions_manager  # Supports isDoomed
    transaction.begin()
    app = Zope2.app()
    result = None
    try:
        try:
            portal = app.unrestrictedTraverse(portal_path, None)
            if portal is None:
                raise BadRequest(
                    'Portal path %s not found' % '/'.join(portal_path))
            setSite(portal)

            if uf_path:
                acl_users = app.unrestrictedTraverse(uf_path, None)
                if acl_users is None:
                    raise BadRequest(
                        'Userfolder path %s not found' % '/'.join(uf_path))
                user = acl_users.getUserById(user_id)
                if user is None:
                    raise BadRequest('User %s not found' % user_id)
                newSecurityManager(None, user)

            context = portal.unrestrictedTraverse(context_path, None)
            if context is None:
                raise BadRequest(
                    'Context path %s not found' % '/'.join(context_path))

            # Create a request to work with
            import sys
            from ZPublisher.HTTPResponse import HTTPResponse
            from ZPublisher.HTTPRequest import HTTPRequest
            response = HTTPResponse(stdout=sys.stdout)
            env = {'SERVER_NAME':'fake_server',
                   'SERVER_PORT':'80',
                   'REQUEST_METHOD':'GET'}
            request = HTTPRequest(sys.stdin, env, response)

            # Set values from original request
            original_request = kwargs.get('original_request')
            if original_request:
                for k,v in original_request.items():
                    request.set(k, v)
            context.REQUEST = request

            result = func(context, *args, **kwargs)

            del context.REQUEST #Avoid "can't pickle file objects"
            transaction.commit()
        except:
            transaction.abort()
            raise
    finally:
        noSecurityManager()
        setSite(None)
        app._p_jar.close()
    return result
开发者ID:gforcada,项目名称:plone.app.async,代码行数:61,代码来源:service.py

示例2: process_wrapper

# 需要导入模块: from ZPublisher.HTTPRequest import HTTPRequest [as 别名]
# 或者: from ZPublisher.HTTPRequest.HTTPRequest import set [as 别名]
def process_wrapper(pid, request_body, request_environ):
    # Sets up everything we need to run a view method in a new Zope-ish
    # context, then runs it and stores the result for later retrieval.
    
    _process = None

    def my_mapply(object, positional=(), keyword={},
                   debug=None, maybe=None,
                   missing_name=None,
                   handle_class=None,
                   context=None, bind=0):
        
        if not isinstance(keyword, Mapping):
            keyword = {}
        keyword['process_id'] = pid
        
        args = (getattr(object, '__run__', object),)
        kwargs = dict(positional=positional,
                      keyword=keyword,
                      debug=debug,
                      maybe=maybe,
                      context=context,
                      bind=bind
                      )
        if missing_name is not None:
            kwargs['missing_name'] = missing_name
        if handle_class is not None:
            kwargs['handle_class'] = handle_class
        return mapply(*args, **kwargs)
        
    response = HTTPResponse(stdout=StringIO(), stderr=StringIO())
    request = HTTPRequest(StringIO(request_body), request_environ, response)
    
    request.set('process_id', pid)
    
    import Zope2
    app = Zope2.bobo_application.__bobo_traverse__(request)
    reg = getProcessRegistry(app)
    _process = reg.get(pid)
    
    
    # Run
    try:
        try:
            response = publish(request, 'Zope2', [None], mapply=my_mapply)
            
            # We can't just pass the response back, as the data streams will not
            # be set up right.
            attr = (hasattr(response, 'cookies') and 'cookies') or \
                   (hasattr(response, '_cookies') and '_cookies')
            cookies = deepcopy(getattr(response, attr))
            
            if IHTTPResponse.providedBy(response):
                _process['result'] = (response.getStatus(),
                                      dict(response.getHeaders()),
                                      cookies,
                                      response.consumeBody())
            else:
                # Currently, ZPublisher.HTTPResponse doesn't implement
                # IHTTPResponse, even though HTTPRequest implements
                # IHTTPRequest.
                _process['result'] = (response.getStatus(),
                                      dict(response.headers),
                                      cookies,
                                      response.body)
                
        except Exception, e:
            # Set result to the exception raised
            _process['result'] = e
            raise
        else:
开发者ID:MrTango,项目名称:netsight.async,代码行数:73,代码来源:BaseAsyncView.py


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