FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
validators/src/validators/encoding.py at 0.35.0 · python-validators/validators · GitHub
python-validators
validators
Repository navigation
Code
Issues
Pull requests
4
(4)
Discussions
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
validators
/
src
/
validators
/
encoding.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
95 lines (73 loc) · 2.33 KB
Breadcrumbs
validators
/
src
/
validators
/
encoding.py
Copy path
File metadata and controls
95 lines (73 loc) · 2.33 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
"""Encoding."""
# standard
import
re
# local
from
.
utils
import
validator
@
validator
def
base16
(
value
:
str
,
/
):
"""Return whether or not given value is a valid base16 encoding.
Examples:
>>> base16('a3f4b2')
True
>>> base16('a3f4Z1')
ValidationError(func=base16, args={'value': 'a3f4Z1'})
Args:
value:
base16 string to validate.
Returns:
(Literal[True]): If `value` is a valid base16 encoding.
(ValidationError): If `value` is an invalid base16 encoding.
"""
return
re
.
match
(
r"^[0-9A-Fa-f]+$"
,
value
)
if
value
else
False
@
validator
def
base32
(
value
:
str
,
/
):
"""Return whether or not given value is a valid base32 encoding.
Examples:
>>> base32('MFZWIZLTOQ======')
True
>>> base32('MfZW3zLT9Q======')
ValidationError(func=base32, args={'value': 'MfZW3zLT9Q======'})
Args:
value:
base32 string to validate.
Returns:
(Literal[True]): If `value` is a valid base32 encoding.
(ValidationError): If `value` is an invalid base32 encoding.
"""
return
re
.
match
(
r"^[A-Z2-7]+=*$"
,
value
)
if
value
else
False
@
validator
def
base58
(
value
:
str
,
/
):
"""Return whether or not given value is a valid base58 encoding.
Examples:
>>> base58('14pq6y9H2DLGahPsM4s7ugsNSD2uxpHsJx')
True
>>> base58('cUSECm5YzcXJwP')
True
Args:
value:
base58 string to validate.
Returns:
(Literal[True]): If `value` is a valid base58 encoding.
(ValidationError): If `value` is an invalid base58 encoding.
"""
return
re
.
match
(
r"^[1-9A-HJ-NP-Za-km-z]+$"
,
value
)
if
value
else
False
@
validator
def
base64
(
value
:
str
,
/
):
"""Return whether or not given value is a valid base64 encoding.
Examples:
>>> base64('Y2hhcmFjdGVyIHNldA==')
True
>>> base64('cUSECm5YzcXJwP')
ValidationError(func=base64, args={'value': 'cUSECm5YzcXJwP'})
Args:
value:
base64 string to validate.
Returns:
(Literal[True]): If `value` is a valid base64 encoding.
(ValidationError): If `value` is an invalid base64 encoding.
"""
return
(
re
.
match
(
r"^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$"
,
value
)
if
value
else
False
)
Back
|
FazBrowse Home
|
New Git URL