+49
src/atpasser/recordKeys/__init__.py
+49
src/atpasser/recordKeys/__init__.py
···
1
+
class RecordKey:
2
+
"""
3
+
A class representing a RecordKey.
4
+
5
+
6
+
Attributes:
7
+
recordKey (str): The RecordKey URI.
8
+
"""
9
+
10
+
def __init__(self, recordKey: str) -> None:
11
+
"""
12
+
Initalizes an RecordKey object.
13
+
14
+
Parameters:
15
+
recordKey (str): The RecordKey.
16
+
"""
17
+
18
+
if recordKey == "" or len(recordKey) > 512:
19
+
raise ValueError("null record key or record key longer than 512 chars")
20
+
21
+
if recordKey == ".." or recordKey == ".":
22
+
raise ValueError("reserved value . and ..")
23
+
24
+
if not set(recordKey).issubset(
25
+
set("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.-_:~")
26
+
):
27
+
raise ValueError("invalid char")
28
+
29
+
self.recordKey = recordKey
30
+
31
+
def __str__(self) -> str:
32
+
"""
33
+
34
+
Convert the RecordKey to a string by given the URI.
35
+
"""
36
+
return self.recordKey
37
+
38
+
def __eq__(self, value: object, /) -> bool:
39
+
"""
40
+
41
+
Check if the 2 values are exactly the same.
42
+
"""
43
+
44
+
if isinstance(value, RecordKey):
45
+
46
+
return str(self) == str(value)
47
+
else:
48
+
49
+
raise TypeError