本文整理汇总了Python中stdnum.util.isdigits函数的典型用法代码示例。如果您正苦于以下问题:Python isdigits函数的具体用法?Python isdigits怎么用?Python isdigits使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了isdigits函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: validate
def validate(number):
"""Check if the number provided is a valid VAT number. This checks the
length, formatting and check digit."""
number = compact(number)
if not isdigits(number[1:-1]):
raise InvalidFormat()
if len(number) != 9:
raise InvalidLength()
if number[0] in 'KLM':
# K: Spanish younger than 14 year old
# L: Spanish living outside Spain without DNI
# M: granted the tax to foreigners who have no NIE
# these use the old checkdigit algorithm (the DNI one)
if number[-1] != dni.calc_check_digit(number[1:-1]):
raise InvalidChecksum()
elif isdigits(number[0]):
# natural resident
dni.validate(number)
elif number[0] in 'XYZ':
# foreign natural person
nie.validate(number)
else:
# otherwise it has to be a valid CIF
cif.validate(number)
return number
示例2: validate
def validate(number):
"""Check if the number is a valid VAT number. This checks the length,
formatting and check digit."""
number = compact(number)
if not all(x in _alphabet for x in number[:2]):
raise InvalidFormat()
if not isdigits(number[2:]):
raise InvalidFormat()
if len(number) != 11:
raise InvalidLength()
if number[2:5] != '000':
# numbers from Monaco are valid TVA but not SIREN
siren.validate(number[2:])
if isdigits(number):
# all-numeric digits
if int(number[:2]) != (int(number[2:] + '12') % 97):
raise InvalidChecksum()
else:
# one of the first two digits isn't a number
if isdigits(number[0]):
check = (
_alphabet.index(number[0]) * 24 +
_alphabet.index(number[1]) - 10)
else:
check = (
_alphabet.index(number[0]) * 34 +
_alphabet.index(number[1]) - 100)
if (int(number[2:]) + 1 + check // 11) % 11 != (check % 11):
raise InvalidChecksum()
return number
示例3: validate
def validate(number):
"""Check if the number provided is a valid CAS RN."""
number = compact(number)
if not 7 <= len(number) <= 12:
raise InvalidLength()
if not isdigits(number[:-5]) or not isdigits(number[-4:-2]):
raise InvalidFormat()
if number[-2] != '-' or number[-5] != '-':
raise InvalidFormat()
if number[-1] != calc_check_digit(number[:-1]):
raise InvalidChecksum()
return number
示例4: validate
def validate(number):
"""Check if the number provided is valid. This checks the length
and check digits."""
number = compact(number)
if not isdigits(number[:5]) or not isdigits(number[7:]):
raise InvalidFormat()
if not isdigits(number[5:7]) and number[5:7] not in ('2A', '2B'):
raise InvalidFormat()
if len(number) != 15:
raise InvalidLength()
if calc_check_digits(number) != number[13:]:
raise InvalidChecksum()
return number
示例5: validate
def validate(number):
"""Check if the number provided is a valid NCF."""
number = compact(number)
if len(number) == 11:
if number[0] != 'B' or not isdigits(number[1:]):
raise InvalidFormat()
elif len(number) == 19:
if number[0] not in 'AP' or not isdigits(number[1:]):
raise InvalidFormat()
else:
raise InvalidLength()
if number[-10:-8] not in (
'01', '02', '03', '04', '11', '12', '13', '14', '15'):
raise InvalidComponent()
return number
示例6: validate
def validate(number):
"""Check if the number is valid. This checks the length and check
digit."""
number = compact(number)
if not all(x in _alphabet for x in number):
raise InvalidFormat()
if len(number) != 7:
raise InvalidLength()
if isdigits(number[0]) and not isdigits(number):
# new style SEDOLs are supposed to start with a letter, old-style
# numbers should be fully numeric
raise InvalidFormat()
if calc_check_digit(number[:-1]) != number[-1]:
raise InvalidChecksum()
return number
示例7: validate
def validate(number):
"""Check if the number is a valid BN or BN15. This checks the length,
formatting and check digit."""
number = compact(number)
if len(number) not in (9, 15):
raise InvalidLength()
if not isdigits(number[:9]):
raise InvalidFormat()
luhn.validate(number[:9])
if len(number) == 15:
if number[9:11] not in ('RC', 'RM', 'RP', 'RT'):
raise InvalidComponent()
if not isdigits(number[11:]):
raise InvalidFormat()
return number
示例8: validate
def validate(number, strip_check_digit=True):
"""Check if the number is a valid MEID number. This converts the
representation format of the number (if it is decimal it is not converted
to hexadecimal)."""
from stdnum import luhn
# first parse the number
number, cd = _parse(number)
if len(number) == 18:
# decimal format can be easily determined
if cd:
luhn.validate(number + cd)
# convert to hex
manufacturer_code = int(number[0:10])
serial_num = int(number[10:18])
if _bit_length(manufacturer_code) > 32 or _bit_length(serial_num) > 24:
raise InvalidComponent()
number = '%08X%06X' % (manufacturer_code, serial_num)
cd = calc_check_digit(number)
elif isdigits(number):
# if the remaining hex format is fully decimal it is an IMEI number
from stdnum import imei
imei.validate(number + cd)
else:
# normal hex Luhn validation
if cd:
luhn.validate(number + cd, alphabet=_hex_alphabet)
if strip_check_digit:
cd = ''
return number + cd
示例9: validate
def validate(number):
"""Check if the number provided is a valid FIGI."""
number = compact(number)
if not all(x in '0123456789BCDFGHJKLMNPQRSTVWXYZ' for x in number):
raise InvalidFormat()
if len(number) != 12:
raise InvalidLength()
if isdigits(number[0]) or isdigits(number[1]):
raise InvalidFormat()
if number[:2] in ('BS', 'BM', 'GG', 'GB', 'VG'):
raise InvalidComponent()
if number[2] != 'G':
raise InvalidComponent()
if calc_check_digit(number[:-1]) != number[-1]:
raise InvalidChecksum()
return number
示例10: validate
def validate(number):
"""Check if the number provided is a valid RUC number. This checks the
length, formatting, check digit and check sum."""
number = compact(number)
if len(number) != 13:
raise InvalidLength()
if not isdigits(number):
raise InvalidFormat()
if (number[:2] < '01' or number[:2] > '24') and (number[:2] not in ('30', '50')):
raise InvalidComponent() # invalid province code
if number[2] < '6':
# 0..5 = natural RUC: CI plus establishment number
if number[-3:] == '000':
raise InvalidComponent() # establishment number wrong
ci.validate(number[:10])
elif number[2] == '6':
# 6 = public RUC
if number[-4:] == '0000':
raise InvalidComponent() # establishment number wrong
if _checksum(number[:9], (3, 2, 7, 6, 5, 4, 3, 2, 1)) != 0:
raise InvalidChecksum()
elif number[2] == '9':
# 9 = juridical RUC
if number[-3:] == '000':
raise InvalidComponent() # establishment number wrong
if _checksum(number[:10], (4, 3, 2, 7, 6, 5, 4, 3, 2, 1)) != 0:
raise InvalidChecksum()
else:
raise InvalidComponent() # third digit wrong
return number
示例11: validate
def validate(number):
"""Check if the number is a valid VAT number. This checks the length,
formatting and check digit."""
number = compact(number)
if not isdigits(number) or number[-2:] != '01':
raise InvalidFormat()
orgnr.validate(number[:-2])
return number
示例12: validate
def validate(number):
"""Check if the number is a valid DNI."""
number = compact(number)
if not isdigits(number):
raise InvalidFormat()
if len(number) not in (7, 8):
raise InvalidLength()
return number
示例13: validate
def validate(number):
"""Check if the number is a valid SIN. This checks the length, formatting
and check digit."""
number = compact(number)
if len(number) != 9:
raise InvalidLength()
if not isdigits(number):
raise InvalidFormat()
return luhn.validate(number)
示例14: validate
def validate(number):
"""Check if the number provided is a valid CCC."""
number = compact(number)
if len(number) != 20:
raise InvalidLength()
if not isdigits(number):
raise InvalidFormat()
if number[8:10] != calc_check_digits(number):
raise InvalidChecksum()
return number
示例15: validate
def validate(number):
"""Check if the number is a valid CUIT."""
number = compact(number)
if len(number) != 11:
raise InvalidLength()
if not isdigits(number):
raise InvalidFormat()
if calc_check_digit(number[:-1]) != number[-1]:
raise InvalidChecksum()
return number