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


Python Response.__init__方法代码示例

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


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

示例1: __init__

# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import __init__ [as 别名]
    def __init__(self, environ, *d, **kw):
        method = environ['REQUEST_METHOD']
        if method not in self.supported_methods():
            raise exc.HTTPMethodNotAllowed(allow = self.supported_methods())

        pos_args, named_args = environ['wsgiorg.routing_args']
        # remove keys with value None
        named_args = dict((k, v) for k, v in named_args.iteritems() if v is not None)

        param = named_args.get(self.__param_arg__, None)
        if param is None:
            handler_name = method
        else:
            del named_args[self.__param_arg__]

            handler_name = "%s_%s" % (method, param)
            if method == 'HEAD':
                if not hasattr(self, handler_name):
                    handler_name = "GET_%s" % param

        h = getattr(self, handler_name, None)
        if not h:
            raise exc.HTTPNotFound()
        else:
            # add data to environ
            environ['sancus.args'] = named_args
            environ['sancus.handler_name'] = handler_name
            environ['sancus.handler'] = h

            req = Request(environ)

            Response.__init__(self, *d, request=req, **kw)
            self.allow = self.supported_methods()
开发者ID:sancus-project,项目名称:sancus-python-old,代码行数:35,代码来源:resource.py

示例2: __init__

# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import __init__ [as 别名]
 def __init__(self, status=400, location='body', name='', description=''):
     body = {'status': status, 'errors':
             [{'location': location, 'name': name, 'description': description}]
             }
     Response.__init__(self, json.dumps(body))
     self.status = status
     self.content_type = 'application/json'
开发者ID:almet,项目名称:tokenserver,代码行数:9,代码来源:util.py

示例3: __init__

# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import __init__ [as 别名]
    def __init__(self, environ, *d, **kw):
        """
        """
        # method
        handlers = self.supported_methods(environ)
        try:
            handler_name = handlers[environ['REQUEST_METHOD']]
        except:
            raise exc.HTTPMethodNotAllowed(allow = handlers)

        # handler
        handler = getattr(self, handler_name, None)
        if not handler:
            raise exc.HTTPNotFound()

        environ['sancus.handler_name'] = handler_name
        environ['sancus.handler'] = handler

        # arguments
        pos_args, named_args = environ.get('wsgiorg.routing_args', ((), {}))
        named_args = dict((k, v) for k, v in named_args.iteritems() if v is not None)

        environ['sancus.pos_args'] = pos_args
        environ['sancus.named_args'] = named_args

        # webob
        req = Request(environ)
        Response.__init__(self, *d, request=req, **kw)
        self.allow = handlers
开发者ID:sancus-project,项目名称:sancus-python,代码行数:31,代码来源:resource.py

示例4: __init__

# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import __init__ [as 别名]
    def __init__(self, code, label, title, explanation, **kw):
        self.code = code
        self.label = label
        self.title = title
        self.explanation = explanation

        Response.__init__(self, status='%s %s' % (self.code, self.title), **kw)
        webob.exc.HTTPException.__init__(self, self.explanation, self)
开发者ID:Oneiroi,项目名称:keystone,代码行数:10,代码来源:wsgi.py

示例5: __init__

# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import __init__ [as 别名]
 def __init__(self, status_code, message):
     body = {
         'status': status_code,
         'errors': [
             {'description': message or self.message}
         ]
     }
     Response.__init__(self, json.dumps(body))
     self.status = status_code
     self.content_type = 'application/vnd.collection+json'
开发者ID:LiberTIC,项目名称:ODE,代码行数:12,代码来源:exceptions.py

示例6: __init__

# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import __init__ [as 别名]
 def __init__(self, detail=None, headers=None, comment=None, body_template=None, **kw):
     Response.__init__(self, status="%s %s" % (self.code, self.title), **kw)
     Exception.__init__(self, detail)
     if headers:
         self.headers.extend(headers)
     self.detail = detail
     self.comment = comment
     if body_template is not None:
         self.body_template = body_template
         self.body_template_obj = Template(body_template)
     if self.empty_body:
         del self.content_type
         del self.content_length
开发者ID:anmnsg,项目名称:webapp-improved,代码行数:15,代码来源:exc.py

示例7: __init__

# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import __init__ [as 别名]
    def __init__(self, msgs, status=400):

        # XXX: status code is pulled from the first error message
        # (probably not the most intuitive way)

        msg = next((msg for msg in msgs if 'status' in msg), None)
        log.debug("JSONError.__init__: errors -> %r", msgs)

        if msg:
            status = msg.pop('status')

        # leave only debugging info
        if not DEBUG:
            body = [{"description": "", "name": m['name'], "location": ""} for \
                    m in msgs]
        else:
            body = msgs

        Response.__init__(self, json.dumps(body))

        self.status = status
        self.content_type = 'application/json'
开发者ID:codeqqby,项目名称:emokykla,代码行数:24,代码来源:errors.py

示例8: __init__

# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import __init__ [as 别名]
 def __init__(self, r):
     Response.__init__(self, content_type="application/json", body=simplejson.dumps(r))
开发者ID:fivehut,项目名称:wsgijson,代码行数:4,代码来源:wsgijson.py

示例9: __init__

# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import __init__ [as 别名]
 def __init__(self, **kwargs):
     Response.__init__(self, body=self.serialize(kwargs.pop('body', None)),
                       **kwargs)
开发者ID:ieure,项目名称:dream,代码行数:5,代码来源:__init__.py

示例10: __init__

# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import __init__ [as 别名]
 def __init__(self, msg='Not Implemented'):
     body = {'status': 501, 'message': msg}
     Response.__init__(self, json.dumps(body))
     self.status = 501
     self.content_type = 'application/json'
开发者ID:digitaldreamer,项目名称:fivesquare,代码行数:7,代码来源:http.py

示例11: __init__

# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import __init__ [as 别名]
 def __init__(self, msg='Not Found'):
     body = {'status': 404, 'message': msg}
     Response.__init__(self, write_json(body))
     self.status = 404
     self.content_type = 'application/json'
开发者ID:spurton,项目名称:scramble-api,代码行数:7,代码来源:utils.py

示例12: __init__

# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import __init__ [as 别名]
 def __init__(self, callback=None, **kwargs):
     body = self.serialize(kwargs.pop('body'))
     if callback is not None:
         self.default_content_type = 'application/javascript'
         body = '%s(%s);' % (callback, body)
     Response.__init__(self, body=body, charset='utf8', **kwargs)
开发者ID:Crazy4Tech,项目名称:kestrelweb,代码行数:8,代码来源:dream.py

示例13: __init__

# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import __init__ [as 别名]
 def __init__(self, msg="Unauthorized"):
     body = {"status": 401, "message": msg}
     Response.__init__(self, json.dumps(body))
     self.status = 401
     self.content_type = "application/json"
开发者ID:ashaycool,项目名称:syncform,代码行数:7,代码来源:views.py

示例14: __init__

# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import __init__ [as 别名]
 def __init__(self, *args, **kargs):
     Response.__init__(self, *args, **kargs)
     self.content_type = 'text/plain'
开发者ID:llacroix,项目名称:Git-Python-Http,代码行数:5,代码来源:__init__.py

示例15: __init__

# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import __init__ [as 别名]
 def __init__(self, errors, status=400):
     body = {'status': 'error', 'errors': errors}
     Response.__init__(self, json.dumps(body, use_decimal=True))
     self.status = status
     self.content_type = 'application/json'
开发者ID:tarekziade,项目名称:cornice,代码行数:7,代码来源:util.py


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