Define __repr__ methods for StreamConfig and PaginationConfig

So that they can be used with "%r" log formats.
This commit is contained in:
Mark Haines 2015-09-22 15:13:10 +01:00
parent ee2d722f0f
commit b35baf6f3c
1 changed files with 8 additions and 3 deletions

View File

@ -34,6 +34,11 @@ class SourcePaginationConfig(object):
self.direction = 'f' if direction == 'f' else 'b' self.direction = 'f' if direction == 'f' else 'b'
self.limit = int(limit) if limit is not None else None self.limit = int(limit) if limit is not None else None
def __repr__(self):
return (
"StreamConfig(from_key=%r, to_key=%r, direction=%r, limit=%r)"
) % (self.from_key, self.to_key, self.direction, self.limit)
class PaginationConfig(object): class PaginationConfig(object):
@ -94,10 +99,10 @@ class PaginationConfig(object):
logger.exception("Failed to create pagination config") logger.exception("Failed to create pagination config")
raise SynapseError(400, "Invalid request.") raise SynapseError(400, "Invalid request.")
def __str__(self): def __repr__(self):
return ( return (
"<PaginationConfig from_tok=%s, to_tok=%s, " "PaginationConfig(from_tok=%r, to_tok=%r,"
"direction=%s, limit=%s>" " direction=%r, limit=%r)"
) % (self.from_token, self.to_token, self.direction, self.limit) ) % (self.from_token, self.to_token, self.direction, self.limit)
def get_source_config(self, source_name): def get_source_config(self, source_name):