regex are now stored in a specific file

This commit is contained in:
Faraphel 2023-03-07 11:17:52 +01:00
parent cc5a90405c
commit 15b522cb7b
3 changed files with 30 additions and 16 deletions

12
source/gui/regex.py Normal file
View file

@ -0,0 +1,12 @@
from math import inf
def number(min_length: int = 0, max_length: int = inf) -> str:
return r"\d{%s,%s}" % (min_length, max_length if max_length < inf else "")
ipv4_check, ipv4_type = r"\d{1,3}(\.\d{1,3}){3}", r"[\d\.]{0,15}"
port_check, port_type = number(min_length=1, max_length=5), number(min_length=0, max_length=5)
username_check, username_type = r".{1,16}", r".{0,16}"

View file

@ -1,6 +1,6 @@
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
from source.gui import widget, texture from source.gui import widget, texture, regex
from source.gui.scene import RoomHost from source.gui.scene import RoomHost
from source.gui.scene.abc import Scene from source.gui.scene.abc import Scene
from source.network.packet import PacketSettings from source.network.packet import PacketSettings
@ -44,8 +44,8 @@ class RoomCreate(Scene):
style=texture.Input.Style1, style=texture.Input.Style1,
type_regex=r"\d{0,5}", type_regex=regex.port_type,
check_regex=r"\d{1,5}", check_regex=regex.port_check,
label_text="52321" label_text="52321"
) )
@ -67,7 +67,8 @@ class RoomCreate(Scene):
x=0.2, y=0.45, width=0.15, height=0.1, x=0.2, y=0.45, width=0.15, height=0.1,
type_regex=r".{0,16}", type_regex=regex.username_type,
check_regex=regex.username_check,
style=texture.Input.Style1, style=texture.Input.Style1,
@ -89,8 +90,8 @@ class RoomCreate(Scene):
x=0.2, y=0.86, width=0.1, height=0.08, x=0.2, y=0.86, width=0.1, height=0.08,
type_regex=r"\d{0,4}", type_regex=regex.number(min_length=0, max_length=4),
check_regex=r"\d+", check_regex=regex.number(min_length=1, max_length=4),
style=texture.Input.Style1, style=texture.Input.Style1,
@ -110,8 +111,8 @@ class RoomCreate(Scene):
x=0.2, y=0.76, width=0.1, height=0.08, x=0.2, y=0.76, width=0.1, height=0.08,
type_regex=r"\d{0,4}", type_regex=regex.number(min_length=0, max_length=4),
check_regex=r"\d+", check_regex=regex.number(min_length=1, max_length=4),
style=texture.Input.Style1, style=texture.Input.Style1,
@ -201,8 +202,8 @@ class RoomCreate(Scene):
x=0.7, y=0.68, width=0.2, height=0.08, x=0.7, y=0.68, width=0.2, height=0.08,
type_regex=r"\d{0,4}", type_regex=regex.number(min_length=0, max_length=4),
check_regex=r"\d+", check_regex=regex.number(min_length=1, max_length=4),
style=texture.Input.Style1, style=texture.Input.Style1,

View file

@ -2,7 +2,7 @@ from typing import TYPE_CHECKING, Optional
from source import network from source import network
from source.gui.scene.abc import Scene from source.gui.scene.abc import Scene
from source.gui import widget, texture from source.gui import widget, texture, regex
if TYPE_CHECKING: if TYPE_CHECKING:
from source.gui.window import Window from source.gui.window import Window
@ -29,7 +29,8 @@ class RoomJoin(Scene):
widget.Input, widget.Input,
x=0.4, y=0.55, width=0.2, height=0.1, x=0.4, y=0.55, width=0.2, height=0.1,
type_regex=r".{0,16}", type_regex=regex.username_type,
check_regex=regex.username_check,
style=texture.Input.Style1, style=texture.Input.Style1,
@ -42,8 +43,8 @@ class RoomJoin(Scene):
widget.Input, widget.Input,
x=0.4, y=0.45, width=0.13, height=0.1, x=0.4, y=0.45, width=0.13, height=0.1,
type_regex=r"[\d\.]{0,15}", type_regex=regex.ipv4_type,
check_regex=r"\d{1,3}(\.\d{1,3}){3}", check_regex=regex.ipv4_check,
style=texture.Input.Style1, style=texture.Input.Style1,
@ -54,8 +55,8 @@ class RoomJoin(Scene):
widget.Input, widget.Input,
x=0.53, y=0.45, width=0.07, height=0.1, x=0.53, y=0.45, width=0.07, height=0.1,
type_regex=r"\d{0,5}", type_regex=regex.port_type,
check_regex=r"\d{1,5}", check_regex=regex.port_check,
label_text="52321", label_text="52321",