diff options
author | Erik Johnston <erik@matrix.org> | 2014-08-21 10:56:31 +0100 |
---|---|---|
committer | Erik Johnston <erik@matrix.org> | 2014-08-21 11:01:33 +0100 |
commit | 81a95937de91078d4a9d46ab6f7a565e659b0560 (patch) | |
tree | 40090480b759ec3718bad129888742180b719944 | |
parent | Add in StreamToken type (diff) | |
download | synapse-81a95937de91078d4a9d46ab6f7a565e659b0560.tar.xz |
Use new StreamToken in pagination config
-rw-r--r-- | synapse/api/streams/__init__.py | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/synapse/api/streams/__init__.py b/synapse/api/streams/__init__.py index d831eafbab..0ba4783ea2 100644 --- a/synapse/api/streams/__init__.py +++ b/synapse/api/streams/__init__.py @@ -14,6 +14,7 @@ # limitations under the License. from synapse.api.errors import SynapseError +from synapse.types import StreamToken class PaginationConfig(object): @@ -21,10 +22,10 @@ class PaginationConfig(object): """A configuration object which stores pagination parameters.""" def __init__(self, from_tok=None, to_tok=None, direction='f', limit=0): - self.from_tok = from_tok - self.to_tok = to_tok - self.direction = direction - self.limit = limit + self.from_tok = StreamToken(from_tok) if from_tok else None + self.to_tok = StreamToken(to_tok) if to_tok else None + self.direction = 'f' if direction == 'f' else 'b' + self.limit = int(limit) @classmethod def from_request(cls, request, raise_invalid_params=True): @@ -47,7 +48,10 @@ class PaginationConfig(object): elif raise_invalid_params: raise SynapseError(400, "%s parameter is invalid." % qp) - return PaginationConfig(**params) + try: + return PaginationConfig(**params) + except: + raise SynapseError(400, "Invalid request.") def __str__(self): return ( |