本文整理汇总了Python中synapse.streams.config.PaginationConfig.from_request方法的典型用法代码示例。如果您正苦于以下问题:Python PaginationConfig.from_request方法的具体用法?Python PaginationConfig.from_request怎么用?Python PaginationConfig.from_request使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类synapse.streams.config.PaginationConfig
的用法示例。
在下文中一共展示了PaginationConfig.from_request方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: on_GET
# 需要导入模块: from synapse.streams.config import PaginationConfig [as 别名]
# 或者: from synapse.streams.config.PaginationConfig import from_request [as 别名]
def on_GET(self, request):
requester = yield self.auth.get_user_by_req(
request,
allow_guest=True,
)
is_guest = requester.is_guest
room_id = None
if is_guest:
if b"room_id" not in request.args:
raise SynapseError(400, "Guest users must specify room_id param")
if b"room_id" in request.args:
room_id = request.args[b"room_id"][0].decode('ascii')
pagin_config = PaginationConfig.from_request(request)
timeout = EventStreamRestServlet.DEFAULT_LONGPOLL_TIME_MS
if b"timeout" in request.args:
try:
timeout = int(request.args[b"timeout"][0])
except ValueError:
raise SynapseError(400, "timeout must be in milliseconds.")
as_client_event = b"raw" not in request.args
chunk = yield self.event_stream_handler.get_stream(
requester.user.to_string(),
pagin_config,
timeout=timeout,
as_client_event=as_client_event,
affect_presence=(not is_guest),
room_id=room_id,
is_guest=is_guest,
)
defer.returnValue((200, chunk))
示例2: on_GET
# 需要导入模块: from synapse.streams.config import PaginationConfig [as 别名]
# 或者: from synapse.streams.config.PaginationConfig import from_request [as 别名]
def on_GET(self, request):
auth_user, _, is_guest = yield self.auth.get_user_by_req(
request,
allow_guest=True
)
room_id = None
if is_guest:
if "room_id" not in request.args:
raise SynapseError(400, "Guest users must specify room_id param")
room_id = request.args["room_id"][0]
try:
handler = self.handlers.event_stream_handler
pagin_config = PaginationConfig.from_request(request)
timeout = EventStreamRestServlet.DEFAULT_LONGPOLL_TIME_MS
if "timeout" in request.args:
try:
timeout = int(request.args["timeout"][0])
except ValueError:
raise SynapseError(400, "timeout must be in milliseconds.")
as_client_event = "raw" not in request.args
chunk = yield handler.get_stream(
auth_user.to_string(), pagin_config, timeout=timeout,
as_client_event=as_client_event, affect_presence=(not is_guest),
room_id=room_id, is_guest=is_guest
)
except:
logger.exception("Event stream failed")
raise
defer.returnValue((200, chunk))
示例3: on_GET
# 需要导入模块: from synapse.streams.config import PaginationConfig [as 别名]
# 或者: from synapse.streams.config.PaginationConfig import from_request [as 别名]
def on_GET(self, request, room_id):
requester = yield self.auth.get_user_by_req(request, allow_guest=True)
pagination_config = PaginationConfig.from_request(request)
content = yield self.handlers.message_handler.room_initial_sync(
room_id=room_id,
requester=requester,
pagin_config=pagination_config,
)
defer.returnValue((200, content))
示例4: on_GET
# 需要导入模块: from synapse.streams.config import PaginationConfig [as 别名]
# 或者: from synapse.streams.config.PaginationConfig import from_request [as 别名]
def on_GET(self, request, room_id):
user = yield self.auth.get_user_by_req(request)
pagination_config = PaginationConfig.from_request(request)
content = yield self.handlers.message_handler.room_initial_sync(
room_id=urllib.unquote(room_id),
user_id=user.to_string(),
pagin_config=pagination_config,
)
defer.returnValue((200, content))
示例5: on_GET
# 需要导入模块: from synapse.streams.config import PaginationConfig [as 别名]
# 或者: from synapse.streams.config.PaginationConfig import from_request [as 别名]
def on_GET(self, request):
user = yield self.auth.get_user_by_req(request)
with_feedback = "feedback" in request.args
pagination_config = PaginationConfig.from_request(request)
handler = self.handlers.message_handler
content = yield handler.snapshot_all_rooms(
user_id=user.to_string(),
pagin_config=pagination_config,
feedback=with_feedback)
defer.returnValue((200, content))
示例6: on_GET
# 需要导入模块: from synapse.streams.config import PaginationConfig [as 别名]
# 或者: from synapse.streams.config.PaginationConfig import from_request [as 别名]
def on_GET(self, request):
requester = yield self.auth.get_user_by_req(request)
as_client_event = "raw" not in request.args
pagination_config = PaginationConfig.from_request(request)
include_archived = request.args.get("archived", None) == ["true"]
content = yield self.initial_sync_handler.snapshot_all_rooms(
user_id=requester.user.to_string(),
pagin_config=pagination_config,
as_client_event=as_client_event,
include_archived=include_archived,
)
defer.returnValue((200, content))
示例7: on_GET
# 需要导入模块: from synapse.streams.config import PaginationConfig [as 别名]
# 或者: from synapse.streams.config.PaginationConfig import from_request [as 别名]
def on_GET(self, request):
auth_user = yield self.auth.get_user_by_req(request)
handler = self.handlers.event_stream_handler
pagin_config = PaginationConfig.from_request(request)
timeout = EventStreamRestServlet.DEFAULT_LONGPOLL_TIME_MS
if "timeout" in request.args:
try:
timeout = int(request.args["timeout"][0])
except ValueError:
raise SynapseError(400, "timeout must be in milliseconds.")
chunk = yield handler.get_stream(auth_user.to_string(), pagin_config,
timeout=timeout)
defer.returnValue((200, chunk))
示例8: on_GET
# 需要导入模块: from synapse.streams.config import PaginationConfig [as 别名]
# 或者: from synapse.streams.config.PaginationConfig import from_request [as 别名]
def on_GET(self, request, room_id):
user, client = yield self.auth.get_user_by_req(request)
pagination_config = PaginationConfig.from_request(
request, default_limit=10,
)
with_feedback = "feedback" in request.args
as_client_event = "raw" not in request.args
handler = self.handlers.message_handler
msgs = yield handler.get_messages(
room_id=room_id,
user_id=user.to_string(),
pagin_config=pagination_config,
feedback=with_feedback,
as_client_event=as_client_event
)
defer.returnValue((200, msgs))
示例9: on_GET
# 需要导入模块: from synapse.streams.config import PaginationConfig [as 别名]
# 或者: from synapse.streams.config.PaginationConfig import from_request [as 别名]
def on_GET(self, request, room_id):
requester = yield self.auth.get_user_by_req(request, allow_guest=True)
pagination_config = PaginationConfig.from_request(
request, default_limit=10,
)
as_client_event = b"raw" not in request.args
filter_bytes = parse_string(request, b"filter", encoding=None)
if filter_bytes:
filter_json = urlparse.unquote(filter_bytes.decode("UTF-8"))
event_filter = Filter(json.loads(filter_json))
else:
event_filter = None
msgs = yield self.pagination_handler.get_messages(
room_id=room_id,
requester=requester,
pagin_config=pagination_config,
as_client_event=as_client_event,
event_filter=event_filter,
)
defer.returnValue((200, msgs))
示例10: on_GET
# 需要导入模块: from synapse.streams.config import PaginationConfig [as 别名]
# 或者: from synapse.streams.config.PaginationConfig import from_request [as 别名]
def on_GET(self, request, room_id):
requester = yield self.auth.get_user_by_req(request, allow_guest=True)
pagination_config = PaginationConfig.from_request(
request, default_limit=10,
)
as_client_event = "raw" not in request.args
filter_bytes = request.args.get("filter", None)
if filter_bytes:
filter_json = urllib.unquote(filter_bytes[-1]).decode("UTF-8")
event_filter = Filter(json.loads(filter_json))
else:
event_filter = None
handler = self.handlers.message_handler
msgs = yield handler.get_messages(
room_id=room_id,
requester=requester,
pagin_config=pagination_config,
as_client_event=as_client_event,
event_filter=event_filter,
)
defer.returnValue((200, msgs))