本文整理汇总了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()
示例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'
示例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
示例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)
示例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'
示例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
示例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'
示例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))
示例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)
示例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'
示例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'
示例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)
示例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"
示例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'
示例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'