summary refs log tree commit diff
path: root/synapse/types.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2016-12-06 10:43:48 +0000
committerErik Johnston <erik@matrix.org>2016-12-06 16:12:27 +0000
commitf32fb6555246adec537bfbca1ddca19e8fe5f4ba (patch)
tree1e275b7f28f35e8954144e4b1568a89ebb968192 /synapse/types.py
parentTravis config (#1674) (diff)
downloadsynapse-f32fb6555246adec537bfbca1ddca19e8fe5f4ba.tar.xz
Add new API appservice specific public room list
Diffstat (limited to 'synapse/types.py')
-rw-r--r--synapse/types.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/synapse/types.py b/synapse/types.py
index ffab12df09..3a3ab21d17 100644
--- a/synapse/types.py
+++ b/synapse/types.py
@@ -274,3 +274,37 @@ class RoomStreamToken(namedtuple("_StreamToken", "topological stream")):
             return "t%d-%d" % (self.topological, self.stream)
         else:
             return "s%d" % (self.stream,)
+
+
+class ThirdPartyInstanceID(
+        namedtuple("ThirdPartyInstanceID", ("appservice_id", "network_id"))
+):
+    # Deny iteration because it will bite you if you try to create a singleton
+    # set by:
+    #    users = set(user)
+    def __iter__(self):
+        raise ValueError("Attempted to iterate a %s" % (type(self).__name__,))
+
+    # Because this class is a namedtuple of strings, it is deeply immutable.
+    def __copy__(self):
+        return self
+
+    def __deepcopy__(self, memo):
+        return self
+
+    @classmethod
+    def from_string(cls, s):
+        bits = s.split("|", 2)
+        if len(bits) != 2:
+            raise SynapseError(400, "Invalid ID %r" % (s,))
+
+        return cls(appservice_id=bits[0], network_id=bits[1])
+
+    def to_string(self):
+        return "%s|%s" % (self.appservice_id, self.network_id,)
+
+    __str__ = to_string
+
+    @classmethod
+    def create(cls, appservice_id, network_id,):
+        return cls(appservice_id=appservice_id, network_id=network_id)