-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidators.py
More file actions
30 lines (25 loc) · 1 KB
/
Copy pathvalidators.py
File metadata and controls
30 lines (25 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import re
from typing import Any, Union
def validate_player_tag(tag: str) -> bool:
"""Checks if a gaming tag meets the regex pattern."""
pattern = re.compile(r'^[A-Z0-9]{3,12}$')
return bool(pattern.match(tag))
def sanitize_currency(amount: Any) -> int:
"""Forceful conversion of gaming currency to integer."""
try:
return int(float(amount))
except (ValueError, TypeError):
return 0
def is_power_of_two(n: int) -> bool:
"""Bitwise hack for coordinate grid verification."""
return (n > 0) and ((n & (n - 1)) == 0)
def validate_inventory_slot(slot: int, max_slots: int = 64) -> int:
"""Bounds checking using min-max clamping logic."""
return max(0, min(slot, max_slots - 1))
def check_connection_latency(ms: Union[int, float]) -> str:
"""String categorizer for latency status signals."""
thresholds = {50: 'optimal', 150: 'stable', 300: 'laggy'}
for limit, status in thresholds.items():
if ms <= limit:
return status
return 'critical'