本文整理汇总了Python中inbox.api.kellogs.APIEncoder.jsonify方法的典型用法代码示例。如果您正苦于以下问题:Python APIEncoder.jsonify方法的具体用法?Python APIEncoder.jsonify怎么用?Python APIEncoder.jsonify使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类inbox.api.kellogs.APIEncoder
的用法示例。
在下文中一共展示了APIEncoder.jsonify方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ns_all
# 需要导入模块: from inbox.api.kellogs import APIEncoder [as 别名]
# 或者: from inbox.api.kellogs.APIEncoder import jsonify [as 别名]
def ns_all():
""" Return all namespaces """
# We do this outside the blueprint to support the case of an empty
# public_id. However, this means the before_request isn't run, so we need
# to make our own session
with global_session_scope() as db_session:
parser = reqparse.RequestParser(argument_class=ValidatableArgument)
parser.add_argument('limit', default=DEFAULT_LIMIT, type=limit,
location='args')
parser.add_argument('offset', default=0, type=int, location='args')
parser.add_argument('email_address', type=bounded_str, location='args')
args = strict_parse_args(parser, request.args)
query = db_session.query(Namespace)
if args['email_address']:
query = query.join(Account)
query = query.filter_by(email_address=args['email_address'])
query = query.limit(args['limit'])
if args['offset']:
query = query.offset(args['offset'])
namespaces = query.all()
encoder = APIEncoder(legacy_nsid=request.path.startswith('/n'))
return encoder.jsonify(namespaces)
示例2: message_read_api
# 需要导入模块: from inbox.api.kellogs import APIEncoder [as 别名]
# 或者: from inbox.api.kellogs.APIEncoder import jsonify [as 别名]
def message_read_api(public_id):
g.parser.add_argument('view', type=view, location='args')
args = strict_parse_args(g.parser, request.args)
encoder = APIEncoder(g.namespace.public_id, args['view'] == 'expanded')
try:
valid_public_id(public_id)
message = g.db_session.query(Message).filter(
Message.public_id == public_id,
Message.namespace_id == g.namespace.id).one()
except NoResultFound:
raise NotFoundError("Couldn't find message {0} ".format(public_id))
if request.headers.get('Accept', None) == 'message/rfc822':
if message.full_body is not None:
return Response(message.full_body.data,
mimetype='message/rfc822')
else:
g.log.error("Message without full_body attribute: id='{0}'"
.format(message.id))
raise NotFoundError(
"Couldn't find raw contents for message `{0}` "
.format(public_id))
return encoder.jsonify(message)
示例3: ns_all
# 需要导入模块: from inbox.api.kellogs import APIEncoder [as 别名]
# 或者: from inbox.api.kellogs.APIEncoder import jsonify [as 别名]
def ns_all():
""" Return all namespaces """
# We do this outside the blueprint to support the case of an empty
# public_id. However, this means the before_request isn't run, so we need
# to make our own session
with session_scope() as db_session:
namespaces = db_session.query(Namespace).all()
encoder = APIEncoder()
return encoder.jsonify(namespaces)
示例4: message_query_api
# 需要导入模块: from inbox.api.kellogs import APIEncoder [as 别名]
# 或者: from inbox.api.kellogs.APIEncoder import jsonify [as 别名]
def message_query_api():
g.parser.add_argument('subject', type=bounded_str, location='args')
g.parser.add_argument('to', type=bounded_str, location='args')
g.parser.add_argument('from', type=bounded_str, location='args')
g.parser.add_argument('cc', type=bounded_str, location='args')
g.parser.add_argument('bcc', type=bounded_str, location='args')
g.parser.add_argument('any_email', type=bounded_str, location='args')
g.parser.add_argument('started_before', type=timestamp, location='args')
g.parser.add_argument('started_after', type=timestamp, location='args')
g.parser.add_argument('last_message_before', type=timestamp,
location='args')
g.parser.add_argument('last_message_after', type=timestamp,
location='args')
g.parser.add_argument('filename', type=bounded_str, location='args')
g.parser.add_argument('in', type=bounded_str, location='args')
g.parser.add_argument('thread_id', type=valid_public_id, location='args')
g.parser.add_argument('unread', type=strict_bool, location='args')
g.parser.add_argument('starred', type=strict_bool, location='args')
g.parser.add_argument('view', type=view, location='args')
# For backwards-compatibility -- remove after deprecating tags API.
g.parser.add_argument('tag', type=bounded_str, location='args')
args = strict_parse_args(g.parser, request.args)
# For backwards-compatibility -- remove after deprecating tags API.
in_ = args['in'] or args['tag']
messages = filtering.messages_or_drafts(
namespace_id=g.namespace.id,
drafts=False,
subject=args['subject'],
thread_public_id=args['thread_id'],
to_addr=args['to'],
from_addr=args['from'],
cc_addr=args['cc'],
bcc_addr=args['bcc'],
any_email=args['any_email'],
started_before=args['started_before'],
started_after=args['started_after'],
last_message_before=args['last_message_before'],
last_message_after=args['last_message_after'],
filename=args['filename'],
in_=in_,
unread=args['unread'],
starred=args['starred'],
limit=args['limit'],
offset=args['offset'],
view=args['view'],
db_session=g.db_session)
# Use a new encoder object with the expand parameter set.
encoder = APIEncoder(g.namespace.public_id, args['view'] == 'expanded')
return encoder.jsonify(messages)
示例5: thread_api
# 需要导入模块: from inbox.api.kellogs import APIEncoder [as 别名]
# 或者: from inbox.api.kellogs.APIEncoder import jsonify [as 别名]
def thread_api(public_id):
g.parser.add_argument('view', type=view, location='args')
args = strict_parse_args(g.parser, request.args)
# Use a new encoder object with the expand parameter set.
encoder = APIEncoder(g.namespace.public_id, args['view'] == 'expanded')
try:
valid_public_id(public_id)
thread = g.db_session.query(Thread).filter(
Thread.public_id == public_id,
Thread.namespace_id == g.namespace.id).one()
return encoder.jsonify(thread)
except NoResultFound:
raise NotFoundError("Couldn't find thread `{0}`".format(public_id))
示例6: thread_query_api
# 需要导入模块: from inbox.api.kellogs import APIEncoder [as 别名]
# 或者: from inbox.api.kellogs.APIEncoder import jsonify [as 别名]
def thread_query_api():
g.parser.add_argument('subject', type=bounded_str, location='args')
g.parser.add_argument('to', type=bounded_str, location='args')
g.parser.add_argument('from', type=bounded_str, location='args')
g.parser.add_argument('cc', type=bounded_str, location='args')
g.parser.add_argument('bcc', type=bounded_str, location='args')
g.parser.add_argument('any_email', type=bounded_str, location='args')
g.parser.add_argument('started_before', type=timestamp, location='args')
g.parser.add_argument('started_after', type=timestamp, location='args')
g.parser.add_argument('last_message_before', type=timestamp,
location='args')
g.parser.add_argument('last_message_after', type=timestamp,
location='args')
g.parser.add_argument('filename', type=bounded_str, location='args')
g.parser.add_argument('thread_id', type=valid_public_id, location='args')
g.parser.add_argument('tag', type=bounded_str, location='args')
g.parser.add_argument('view', type=view, location='args')
args = strict_parse_args(g.parser, request.args)
threads = filtering.threads(
namespace_id=g.namespace.id,
subject=args['subject'],
thread_public_id=args['thread_id'],
to_addr=args['to'],
from_addr=args['from'],
cc_addr=args['cc'],
bcc_addr=args['bcc'],
any_email=args['any_email'],
started_before=args['started_before'],
started_after=args['started_after'],
last_message_before=args['last_message_before'],
last_message_after=args['last_message_after'],
filename=args['filename'],
tag=args['tag'],
limit=args['limit'],
offset=args['offset'],
view=args['view'],
db_session=g.db_session)
# Use a new encoder object with the expand parameter set.
encoder = APIEncoder(g.namespace.public_id, args['view'] == 'expanded')
return encoder.jsonify(threads)