Script 'mail_helper' called by obssrc Hello community, here is the log from the commit of package python-validators for openSUSE:Factory checked in at 2024-07-05 19:45:07 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/python-validators (Old) and /work/SRC/openSUSE:Factory/.python-validators.new.2080 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Package is "python-validators" Fri Jul 5 19:45:07 2024 rev:25 rq:1185281 version:0.30.0 Changes: -------- --- /work/SRC/openSUSE:Factory/python-validators/python-validators.changes 2024-07-02 18:14:51.111910922 +0200 +++ /work/SRC/openSUSE:Factory/.python-validators.new.2080/python-validators.changes 2024-07-05 19:49:34.930849359 +0200 @@ -1,0 +2,8 @@ +Thu Jul 4 06:00:40 UTC 2024 - Mia Herkt <mia@0x0.st> + +- Update to 0.30.0 +Features: + * add validator for trx_addresses + gh#kvesteri/validators#384 + +------------------------------------------------------------------- Old: ---- validators-0.29.0.tar.gz New: ---- validators-0.30.0.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ python-validators.spec ++++++ --- /var/tmp/diff_new_pack.INVNB3/_old 2024-07-05 19:49:36.426904367 +0200 +++ /var/tmp/diff_new_pack.INVNB3/_new 2024-07-05 19:49:36.426904367 +0200 @@ -18,7 +18,7 @@ %{?sle15_python_module_pythons} Name: python-validators -Version: 0.29.0 +Version: 0.30.0 Release: 0 Summary: Python Data Validation License: MIT ++++++ validators-0.29.0.tar.gz -> validators-0.30.0.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/validators-0.29.0/CHANGES.md new/validators-0.30.0/CHANGES.md --- old/validators-0.29.0/CHANGES.md 2024-07-01 17:21:40.000000000 +0200 +++ new/validators-0.30.0/CHANGES.md 2024-07-04 04:34:28.000000000 +0200 @@ -9,6 +9,24 @@ --> +## 0.30.0 (2024-07-04) + +_**Breaking**_ + +> No breaking changes were introduced in this version. + +_**Features**_ + +- feat: add validator for trx addresses by @msamsami in [#384](https://github.com/python-validators/validators/pull/384) + +_**Maintenance**_ + +- maint: bump version by @msamsami in [#384](https://github.com/python-validators/validators/pull/384) + +**Full Changelog**: [`0.29.0...0.30.0`](https://github.com/python-validators/validators/compare/0.29.0...0.30.0) + +--- + ## 0.29.0 (2024-07-01) _**Breaking**_ ⚠️ @@ -25,6 +43,8 @@ **Full Changelog**: [`0.28.3...0.29.0`](https://github.com/python-validators/validators/compare/0.28.3...0.29.0) +--- + ## 0.28.3 (2024-05-25) _**Breaking**_ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/validators-0.29.0/PKG-INFO new/validators-0.30.0/PKG-INFO --- old/validators-0.29.0/PKG-INFO 2024-07-01 17:22:44.121817600 +0200 +++ new/validators-0.30.0/PKG-INFO 2024-07-04 04:35:55.351689600 +0200 @@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: validators -Version: 0.29.0 +Version: 0.30.0 Summary: Python Data Validation for Humans™ Author-email: Konsta Vesterinen <konsta@fastmonkeys.com> License: MIT diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/validators-0.29.0/docs/api/crypto_addresses.md new/validators-0.30.0/docs/api/crypto_addresses.md --- old/validators-0.29.0/docs/api/crypto_addresses.md 2024-07-01 17:21:40.000000000 +0200 +++ new/validators-0.30.0/docs/api/crypto_addresses.md 2024-07-04 04:34:28.000000000 +0200 @@ -2,3 +2,4 @@ ::: validators.crypto_addresses.btc_address ::: validators.crypto_addresses.eth_address +::: validators.crypto_addresses.trx_address diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/validators-0.29.0/docs/api/crypto_addresses.rst new/validators-0.30.0/docs/api/crypto_addresses.rst --- old/validators-0.29.0/docs/api/crypto_addresses.rst 2024-07-01 17:22:40.000000000 +0200 +++ new/validators-0.30.0/docs/api/crypto_addresses.rst 2024-07-04 04:35:51.000000000 +0200 @@ -4,3 +4,4 @@ .. module:: validators.crypto_addresses .. autofunction:: btc_address .. autofunction:: eth_address +.. autofunction:: trx_address diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/validators-0.29.0/docs/validators.1 new/validators-0.30.0/docs/validators.1 --- old/validators-0.29.0/docs/validators.1 2024-07-01 17:22:41.000000000 +0200 +++ new/validators-0.30.0/docs/validators.1 2024-07-04 04:35:52.000000000 +0200 @@ -27,7 +27,7 @@ .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]] .in \\n[rst2man-indent\\n[rst2man-indent-level]]u .. -.TH "VALIDATORS" "1" "Jul 01, 2024" "0.29.0" "validators" +.TH "VALIDATORS" "1" "Jul 04, 2024" "0.30.0" "validators" .SH NAME validators \- Python Data Validation for Humans™ .sp @@ -650,6 +650,36 @@ .TP .B Return type (Literal[True]) +.UNINDENT +.UNINDENT +.INDENT 0.0 +.TP +.B validators.crypto_addresses.trx_address(value: str, /) +Return whether or not given value is a valid tron address. +.sp +Full validation is implemented for TRC20 tron addresses. +.sp +Examples +.sp +.nf +.ft C +>>> trx_address(\(aqTLjfbTbpZYDQ4EoA4N5CLNgGjfbF8ZWz38\(aq) +# Output: True +>>> trx_address(\(aqTR2G7Rm4vFqF8EpY4U5xdLdQ7XgJ2U8Vd\(aq) +# Output: ValidationError(func=trx_address, args=...) +.ft P +.fi +.INDENT 7.0 +.TP +.B Parameters +\fBvalue\fP \-\- Tron address string to validate. +.TP +.B Returns +If \fIvalue\fP is a valid tron address. +(ValidationError): If \fIvalue\fP is an invalid tron address. +.TP +.B Return type +(Literal[True]) .UNINDENT .UNINDENT .SS domain diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/validators-0.29.0/src/validators/__init__.py new/validators-0.30.0/src/validators/__init__.py --- old/validators-0.29.0/src/validators/__init__.py 2024-07-01 17:21:40.000000000 +0200 +++ new/validators-0.30.0/src/validators/__init__.py 2024-07-04 04:34:28.000000000 +0200 @@ -5,7 +5,7 @@ from .card import amex, card_number, diners, discover, jcb, mastercard, unionpay, visa from .country import calling_code, country_code, currency from .cron import cron -from .crypto_addresses import btc_address, eth_address +from .crypto_addresses import btc_address, eth_address, trx_address from .domain import domain from .email import email from .encoding import base58, base64 @@ -39,6 +39,7 @@ # crypto_addresses "btc_address", "eth_address", + "trx_address", # cards "amex", "card_number", @@ -104,4 +105,4 @@ "validator", ) -__version__ = "0.29.0" +__version__ = "0.30.0" diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/validators-0.29.0/src/validators/crypto_addresses/__init__.py new/validators-0.30.0/src/validators/crypto_addresses/__init__.py --- old/validators-0.29.0/src/validators/crypto_addresses/__init__.py 2024-07-01 17:21:40.000000000 +0200 +++ new/validators-0.30.0/src/validators/crypto_addresses/__init__.py 2024-07-04 04:34:28.000000000 +0200 @@ -3,5 +3,6 @@ # local from .btc_address import btc_address from .eth_address import eth_address +from .trx_address import trx_address -__all__ = ("btc_address", "eth_address") +__all__ = ("btc_address", "eth_address", "trx_address") diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/validators-0.29.0/src/validators/crypto_addresses/trx_address.py new/validators-0.30.0/src/validators/crypto_addresses/trx_address.py --- old/validators-0.29.0/src/validators/crypto_addresses/trx_address.py 1970-01-01 01:00:00.000000000 +0100 +++ new/validators-0.30.0/src/validators/crypto_addresses/trx_address.py 2024-07-04 04:34:28.000000000 +0200 @@ -0,0 +1,62 @@ +"""TRX Address.""" + +# standard +import hashlib +import re + +# local +from validators.utils import validator + + +def _base58_decode(addr: str) -> bytes: + """Decode a base58 encoded address.""" + alphabet = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz" + num = 0 + for char in addr: + num = num * 58 + alphabet.index(char) + return num.to_bytes(25, byteorder="big") + + +def _validate_trx_checksum_address(addr: str) -> bool: + """Validate TRX type checksum address.""" + if len(addr) != 34: + return False + + try: + address = _base58_decode(addr) + except ValueError: + return False + + if len(address) != 25 or address[0] != 0x41: + return False + + check_sum = hashlib.sha256(hashlib.sha256(address[:-4]).digest()).digest()[:4] + return address[-4:] == check_sum + + +@validator +def trx_address(value: str, /): + """Return whether or not given value is a valid tron address. + + Full validation is implemented for TRC20 tron addresses. + + Examples: + >>> trx_address('TLjfbTbpZYDQ4EoA4N5CLNgGjfbF8ZWz38') + # Output: True + >>> trx_address('TR2G7Rm4vFqF8EpY4U5xdLdQ7XgJ2U8Vd') + # Output: ValidationError(func=trx_address, args=...) + + Args: + value: + Tron address string to validate. + + Returns: + (Literal[True]): If `value` is a valid tron address. + (ValidationError): If `value` is an invalid tron address. + """ + if not value: + return False + + return re.compile(r"^[T][a-km-zA-HJ-NP-Z1-9]{33}$").match( + value + ) and _validate_trx_checksum_address(value) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/validators-0.29.0/src/validators.egg-info/PKG-INFO new/validators-0.30.0/src/validators.egg-info/PKG-INFO --- old/validators-0.29.0/src/validators.egg-info/PKG-INFO 2024-07-01 17:22:44.000000000 +0200 +++ new/validators-0.30.0/src/validators.egg-info/PKG-INFO 2024-07-04 04:35:55.000000000 +0200 @@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: validators -Version: 0.29.0 +Version: 0.30.0 Summary: Python Data Validation for Humans™ Author-email: Konsta Vesterinen <konsta@fastmonkeys.com> License: MIT diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/validators-0.29.0/src/validators.egg-info/SOURCES.txt new/validators-0.30.0/src/validators.egg-info/SOURCES.txt --- old/validators-0.29.0/src/validators.egg-info/SOURCES.txt 2024-07-01 17:22:44.000000000 +0200 +++ new/validators-0.30.0/src/validators.egg-info/SOURCES.txt 2024-07-04 04:35:55.000000000 +0200 @@ -84,6 +84,7 @@ src/validators/crypto_addresses/__init__.py src/validators/crypto_addresses/btc_address.py src/validators/crypto_addresses/eth_address.py +src/validators/crypto_addresses/trx_address.py src/validators/i18n/__init__.py src/validators/i18n/es.py src/validators/i18n/fi.py @@ -110,6 +111,7 @@ tests/test_validation_failure.py tests/crypto_addresses/test_btc_address.py tests/crypto_addresses/test_eth_address.py +tests/crypto_addresses/test_trx_address.py tests/i18n/test_es.py tests/i18n/test_fi.py tests/i18n/test_fr.py diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/validators-0.29.0/tests/crypto_addresses/test_trx_address.py new/validators-0.30.0/tests/crypto_addresses/test_trx_address.py --- old/validators-0.29.0/tests/crypto_addresses/test_trx_address.py 1970-01-01 01:00:00.000000000 +0100 +++ new/validators-0.30.0/tests/crypto_addresses/test_trx_address.py 2024-07-04 04:34:28.000000000 +0200 @@ -0,0 +1,54 @@ +"""Test TRX address.""" + +# external +import pytest + +# local +from validators import ValidationError, trx_address + + +@pytest.mark.parametrize( + "value", + [ + "TLjfbTbpZYDQ4EoA4N5CLNgGjfbF8ZWz38", + "TDQ6C92wuNqvMWE967sMptCFaXq77uj1PF", + "TFuGbxCQGSL4oLnJzVsen844LDwFbrUY4e", + "TFAPKADDRhkSe3v27CsR8TZSjN8eJ8ycDK", + "TSJHywLNva2MNjCD5iYfn5QAKD9Rk5Ncit", + "TEi1qhi5LuTicg1u9oAstyXCSf5uibSyqo", + "TAGvx5An6VBeHTu91cQwdABNcAYMRPcP4n", + "TXbE5tXTejqT3Q47sYKCDb9NJDm3xrFpab", + "TMTxQWNuWHXvHcYXc5D1wQhFmZFJijAxcG", + "TPHgw9E8QYM3esNWih5KVnUVpUHwLTPfpA", + "TFFLtBTi9jdaGwV3hznjCmPYaJme5AeqwU", + "TC74QG8tbtixG5Raa4fEifywgjrFs45fNz", + ], +) +def test_returns_true_on_valid_trx_address(value: str): + """Test returns true on valid trx address.""" + assert trx_address(value) + + +@pytest.mark.parametrize( + "value", + [ + "T12345678901234567890123456789012345", + "ABCDEFGHIJKLMNOPQRSTUVWXYZ12345678", + "TR2G7Rm4vFqF8EpY4U5xdLdQ7XgJ2U8Vd", + "TP6ah2v5mdsj8Z3hGz1yDMvDq7BzEbK8o", + "TQmmhp6uz2Xre8yL3FsPYZyo4mhtw4vg4XX", + "TQNy2C6VHJPk4P32bsEX3QSGx2Qqm4J2k9", + "TP6ah2v5mdsj8Z3hGz1yDMvDq7BzEbK8oN", + "TSTVdfU1x4L7K3Bc3v5C28Gp2J1rPyeL3f", + "THPByuCzvU5QER9j2NC2mUQ2JPyRCam4e7", + "TW5eZqUZgdW4rxFKAKsc2ryJbfFA94WXvD", + "TR2G7Rm4vFqF8EpY4U5xdLdQ7XgJ2U8Vdd", + "tQmmhp6uz2Xre8yL3FsPYZyo4mhtw4vg4X", + "TR2G7Rm4vFqF8EpY4U5xdLdQ7Xg", + "TQmmhp6uz2Xre8yL3FsPYZyo4mhtw4vg4x", + "my-trox-address.trx", + ], +) +def test_returns_failed_validation_on_invalid_trx_address(value: str): + """Test returns failed validation on invalid trx address.""" + assert isinstance(trx_address(value), ValidationError)