Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions matrix_client/checks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
def check_room_id(room_id):
if not room_id.startswith("!"):
raise ValueError("RoomIDs start with !")

if ":" not in room_id:
raise ValueError("RoomIDs must have a domain component, seperated by a :")


def check_user_id(user_id):
if not user_id.startswith("@"):
raise ValueError("UserIDs start with @")

if ":" not in user_id:
raise ValueError("UserIDs must have a domain component, seperated by a :")
2 changes: 2 additions & 0 deletions matrix_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from .api import MatrixHttpApi
from .checks import check_user_id
from .errors import MatrixRequestError, MatrixUnexpectedResponse
from .room import Room
from .user import User
Expand Down Expand Up @@ -146,6 +147,7 @@ def __init__(self, base_url, token=None, user_id=None,
# room_id: Room
}
if token:
check_user_id(user_id)
self.user_id = user_id
self._sync()

Expand Down
7 changes: 2 additions & 5 deletions matrix_client/room.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import re
from uuid import uuid4

from .checks import check_room_id
from .user import User
from .errors import MatrixRequestError

Expand All @@ -16,11 +17,7 @@ def __init__(self, client, room_id):
NOTE: This should ideally be called from within the Client.
NOTE: This does not verify the room with the Home Server.
"""
if not room_id.startswith("!"):
raise ValueError("RoomIDs start with !")

if ":" not in room_id:
raise ValueError("RoomIDs must have a domain component, seperated by a :")
check_room_id(room_id)

self.room_id = room_id
self.client = client
Expand Down
9 changes: 4 additions & 5 deletions matrix_client/user.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
from .checks import check_user_id


class User(object):
""" The User class can be used to call user specific functions.
"""
def __init__(self, api, user_id, displayname=None):
if not user_id.startswith("@"):
raise ValueError("UserIDs start with @")

if ":" not in user_id:
raise ValueError("UserIDs must have a domain component, seperated by a :")
check_user_id(user_id)

self.user_id = user_id
self.displayname = displayname
Expand Down