/usr/lib/python2.7/dist-packages/trytond/modules/party_siret/luhn.py is in tryton-modules-party-siret 3.4.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | #This file is part of Tryton. The COPYRIGHT file at the top level of
#this repository contains the full copyright notices and license terms.
def validate(value):
"""
Validate value with Luhn algorithm
:param value: the value
:return: a boolean
"""
if not isinstance(value, basestring):
value = str(value)
try:
evens = sum(int(x) for x in value[-1::-2])
odds = sum(sum(divmod(int(x) * 2, 10)) for x in value[-2::-2])
return (evens + odds) % 10 == 0
except ValueError:
return False
|