本文整理汇总了Python中pyramid.response.Response.__init__方法的典型用法代码示例。如果您正苦于以下问题:Python Response.__init__方法的具体用法?Python Response.__init__怎么用?Python Response.__init__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid.response.Response
的用法示例。
在下文中一共展示了Response.__init__方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import __init__ [as 别名]
def __init__(
self,
detail=None,
headers=None,
comment=None,
body_template=None,
json_formatter=None,
**kw
):
status = '%s %s' % (self.code, self.title)
Response.__init__(self, status=status, **kw)
Exception.__init__(self, detail)
self.detail = self.message = detail
if headers:
self.headers.extend(headers)
self.comment = comment
if body_template is not None:
self.body_template = body_template
self.body_template_obj = Template(body_template)
if json_formatter is not None:
self._json_formatter = json_formatter
if self.empty_body:
del self.content_type
del self.content_length
示例2: __init__
# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import __init__ [as 别名]
def __init__(self, code=None, errors=None):
if code:
self.code = code
if errors:
self.errors = errors
body = {
'code': self.code,
'errors': self.errors
}
Response.__init__(self, json.dumps(body))
self.status = str(self.code)
self.content_type = 'application/json'
示例3: __init__
# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import __init__ [as 别名]
def __init__(self):
# explicitly avoid calling the HTTPException init magic
if not self.empty_body:
Response.__init__(self, status=self.code,
json_body=self.json_body())
else:
Response.__init__(self, status=self.code)
Exception.__init__(self)
self.detail = self.message
if self.empty_body:
del self.content_type
del self.content_length
示例4: __init__
# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import __init__ [as 别名]
def __init__(self, code=None, json_data=None, **kw):
if json_data is None:
json_data = ''
if code in HTTP_STATUSES:
status = HTTP_STATUSES[code]
else:
status = HTTP_STATUSES[httpcode.InternalServerError]
json_data = {'error': 'JSONResponse: Unable to determine HTTP status code.'}
Response.__init__(self, status=status, body=json.dumps(json_data),
content_type='application/json', **kw)
self.charset = 'utf-8'
示例5: __init__
# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import __init__ [as 别名]
def __init__(self, request):
# NOTE I: Pode parecer excesso de zelo... Mas, mesmo não havendo,
# necessariamente, "views" para esses métodos eu optei por tentar
# fechar a conexão AQUI TAMBÉM para garantir que um "raise exception"
# da vida impeça a conexão de ser fechada! By Questor
# NOTE II: Tentar fechar a conexão de qualquer forma!
# -> Na criação da conexão "coautocommit=True"!
# By Questor
try:
if request.context.session.is_active:
request.context.session.close()
except:
pass
self._error_message = self.title
self.request = request
Response.__init__(self, self.get_error(), status=self.code)
self.content_type = 'application/json'
示例6: __init__
# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import __init__ [as 别名]
def __init__(self, **kw):
Response.__init__(self, **kw)
Exception.__init__(self)
示例7: __init__
# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.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'
示例8: __init__
# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import __init__ [as 别名]
def __init__(self, error):
Response.__init__(self, utils.object2json(error), status=self.code)
self.content_type = 'application/json'
示例9: __init__
# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import __init__ [as 别名]
def __init__(self, error):
Response.__init__(self, json.dumps(error), status=self.code)
self.content_type = 'application/json'
示例10: __init__
# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.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'
示例11: __init__
# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import __init__ [as 别名]
def __init__(self, errors, status=400):
body = {'errors': errors}
Response.__init__(self, dumps(body))
self.status = status
self.content_type = 'application/json'
示例12: __init__
# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import __init__ [as 别名]
def __init__(self, request):
self._error_message = self.title
self.request = request
Response.__init__(self, self.get_error(), status=self.code)
self.content_type = 'application/json'
示例13: __init__
# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import __init__ [as 别名]
def __init__(self, errors, code=400):
self.code = code
body = {'status': "error", "errors": errors}
Response.__init__(self, status=code, body=render("json", body))
self.content_type = 'application/json'
示例14: __init__
# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import __init__ [as 别名]
def __init__(self, msg=None):
body = {'status': self.code, 'message': msg or self.msg}
Response.__init__(self, json.dumps(body))
self.status = self.code
self.content_type = 'application/json'
示例15: __init__
# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import __init__ [as 别名]
def __init__(self):
# explicitly avoid calling the HTTPException init magic
Response.__init__(self, status=self.code, json_body=self.json_body())
Exception.__init__(self)
self.detail = self.message