summaryrefslogtreecommitdiffstats
path: root/venv/lib/python3.9/site-packages/validators/iban.py
diff options
context:
space:
mode:
authornoptuno <repollo.marrero@gmail.com>2023-04-28 02:29:30 +0200
committernoptuno <repollo.marrero@gmail.com>2023-04-28 02:29:30 +0200
commit355dee533bb34a571b9367820a63cccb668cf866 (patch)
tree838af886b4fec07320aeb10f0d1e74ba79e79b5c /venv/lib/python3.9/site-packages/validators/iban.py
parentadded pyproject.toml file (diff)
downloadgpt4free-355dee533bb34a571b9367820a63cccb668cf866.tar
gpt4free-355dee533bb34a571b9367820a63cccb668cf866.tar.gz
gpt4free-355dee533bb34a571b9367820a63cccb668cf866.tar.bz2
gpt4free-355dee533bb34a571b9367820a63cccb668cf866.tar.lz
gpt4free-355dee533bb34a571b9367820a63cccb668cf866.tar.xz
gpt4free-355dee533bb34a571b9367820a63cccb668cf866.tar.zst
gpt4free-355dee533bb34a571b9367820a63cccb668cf866.zip
Diffstat (limited to 'venv/lib/python3.9/site-packages/validators/iban.py')
-rw-r--r--venv/lib/python3.9/site-packages/validators/iban.py52
1 files changed, 52 insertions, 0 deletions
diff --git a/venv/lib/python3.9/site-packages/validators/iban.py b/venv/lib/python3.9/site-packages/validators/iban.py
new file mode 100644
index 00000000..7413d127
--- /dev/null
+++ b/venv/lib/python3.9/site-packages/validators/iban.py
@@ -0,0 +1,52 @@
+import re
+
+from .utils import validator
+
+regex = (
+ r'^[A-Z]{2}[0-9]{2}[A-Z0-9]{11,30}$'
+)
+pattern = re.compile(regex)
+
+
+def char_value(char):
+ """A=10, B=11, ..., Z=35
+ """
+ if char.isdigit():
+ return int(char)
+ else:
+ return 10 + ord(char) - ord('A')
+
+
+def modcheck(value):
+ """Check if the value string passes the mod97-test.
+ """
+ # move country code and check numbers to end
+ rearranged = value[4:] + value[:4]
+ # convert letters to numbers
+ converted = [char_value(char) for char in rearranged]
+ # interpret as integer
+ integerized = int(''.join([str(i) for i in converted]))
+ return (integerized % 97 == 1)
+
+
+@validator
+def iban(value):
+ """
+ Return whether or not given value is a valid IBAN code.
+
+ If the value is a valid IBAN this function returns ``True``, otherwise
+ :class:`~validators.utils.ValidationFailure`.
+
+ Examples::
+
+ >>> iban('DE29100500001061045672')
+ True
+
+ >>> iban('123456')
+ ValidationFailure(func=iban, ...)
+
+ .. versionadded:: 0.8
+
+ :param value: IBAN string to validate
+ """
+ return pattern.match(value) and modcheck(value)