• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python util.isdigits函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中stdnum.util.isdigits函数的典型用法代码示例。如果您正苦于以下问题:Python isdigits函数的具体用法?Python isdigits怎么用?Python isdigits使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了isdigits函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
开发者ID:arthurdejong,项目名称:python-stdnum,代码行数:25,代码来源:nif.py


示例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
开发者ID:arthurdejong,项目名称:python-stdnum,代码行数:30,代码来源:tva.py


示例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
开发者ID:arthurdejong,项目名称:python-stdnum,代码行数:12,代码来源:casrn.py


示例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
开发者ID:arthurdejong,项目名称:python-stdnum,代码行数:13,代码来源:nir.py


示例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
开发者ID:arthurdejong,项目名称:python-stdnum,代码行数:15,代码来源:ncf.py


示例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
开发者ID:arthurdejong,项目名称:python-stdnum,代码行数:15,代码来源:sedol.py


示例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
开发者ID:arthurdejong,项目名称:python-stdnum,代码行数:15,代码来源:bn.py


示例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
开发者ID:arthurdejong,项目名称:python-stdnum,代码行数:29,代码来源:meid.py


示例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
开发者ID:arthurdejong,项目名称:python-stdnum,代码行数:16,代码来源:figi.py


示例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
开发者ID:arthurdejong,项目名称:python-stdnum,代码行数:30,代码来源:ruc.py


示例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
开发者ID:arthurdejong,项目名称:python-stdnum,代码行数:8,代码来源:vat.py


示例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
开发者ID:arthurdejong,项目名称:python-stdnum,代码行数:8,代码来源:dni.py


示例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)
开发者ID:arthurdejong,项目名称:python-stdnum,代码行数:9,代码来源:sin.py


示例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
开发者ID:arthurdejong,项目名称:python-stdnum,代码行数:10,代码来源:ccc.py


示例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
开发者ID:arthurdejong,项目名称:python-stdnum,代码行数:10,代码来源:cuit.py


示例16: validate

def validate(number):
    """Check if the number is a valid identity number."""
    number = compact(number)
    if len(number) not in (10, 12):
        raise InvalidLength()
    if not isdigits(number):
        raise InvalidFormat()
    get_birth_date(number)
    luhn.validate(number[-10:])
    return number
开发者ID:arthurdejong,项目名称:python-stdnum,代码行数:10,代码来源:personnummer.py


示例17: validate

def validate(number):
    """Check if the number provided is a valid cedula."""
    number = compact(number)
    if not isdigits(number):
        raise InvalidFormat()
    if number in whitelist:
        return number
    if len(number) != 11:
        raise InvalidLength()
    return luhn.validate(number)
开发者ID:arthurdejong,项目名称:python-stdnum,代码行数:10,代码来源:cedula.py


示例18: validate

def validate(number):
    """Check if the number is a valid NI. This checks the length, formatting
    and check digit."""
    number = compact(number)
    if len(number) != 11:
        raise InvalidLength()
    if not isdigits(number):
        raise InvalidFormat()
    get_birth_date(number)
    return number
开发者ID:arthurdejong,项目名称:python-stdnum,代码行数:10,代码来源:ni.py


示例19: calc_check_digit

def calc_check_digit(number):
    """Calculate the check digit for the number. The number should not
    already have a check digit."""
    # both the 18-digit decimal format and the 14-digit hex format
    # containing only decimal digits should use the decimal Luhn check
    from stdnum import luhn
    if isdigits(number):
        return luhn.calc_check_digit(number)
    else:
        return luhn.calc_check_digit(number, alphabet=_hex_alphabet)
开发者ID:arthurdejong,项目名称:python-stdnum,代码行数:10,代码来源:meid.py


示例20: validate

def validate(number):
    """Check if the number is a valid OIB number. This checks the length,
    formatting and check digit."""
    number = compact(number)
    if not isdigits(number):
        raise InvalidFormat()
    if len(number) != 11:
        raise InvalidLength()
    mod_11_10.validate(number)
    return number
开发者ID:arthurdejong,项目名称:python-stdnum,代码行数:10,代码来源:oib.py



注:本文中的stdnum.util.isdigits函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python stdout.green函数代码示例发布时间:2022-05-27
下一篇:
Python util.clean函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap