本文整理汇总了Python中stdnum.util.clean函数的典型用法代码示例。如果您正苦于以下问题:Python clean函数的具体用法?Python clean怎么用?Python clean使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了clean函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: compact
def compact(number):
"""Convert the number to the minimal representation. This strips the
number of any valid separators and removes surrounding whitespace."""
number = clean(number, ' ').strip()
if number[:3].lower() == 'bc1':
number = number.lower()
return number
开发者ID:DimitriPapadopoulos,项目名称:python-stdnum,代码行数:7,代码来源:bitcoin.py
示例2: compact
def compact(number):
"""Convert the number to the minimal representation. This strips the
number of any valid separators and removes surrounding whitespace."""
number = clean(number, ' .-').strip()
if number.startswith('0000'):
number = number[4:] # strip leading 0000 postgiro bank code
return number
开发者ID:DimitriPapadopoulos,项目名称:python-stdnum,代码行数:7,代码来源:kontonr.py
示例3: compact
def compact(number):
"""Convert the number to the minimal representation. This strips the
number of any valid separators and removes surrounding whitespace."""
number = clean(number, ' -').upper().strip()
if number.startswith('MT'):
number = number[2:]
return number
开发者ID:Manexware,项目名称:python-stdnum,代码行数:7,代码来源:vat.py
示例4: validate
def validate(number):
"""Checks to see if the number provided is a valid EIN. This checks
the length, groups and formatting if it is present."""
match = _ein_re.search(clean(number, '').strip())
if not match:
raise InvalidFormat()
get_campus(number) # raises exception for unknown campus
return compact(number)
开发者ID:dchoruzy,项目名称:python-stdnum,代码行数:8,代码来源:ein.py
示例5: validate
def validate(number):
"""Checks to see if the number provided is a valid ATIN. This checks
the length and formatting if it is present."""
match = _atin_re.search(clean(number, '').strip())
if not match:
raise InvalidFormat()
# sadly, no more information on ATIN number validation was found
return compact(number)
开发者ID:FabianCollaguazo,项目名称:python-stdnum,代码行数:8,代码来源:atin.py
示例6: validate
def validate(number):
"""Checks to see if the number provided is a valid VAT number. This
performs the country-specific check for the number."""
number = clean(number, '').upper().strip()
module = _get_cc_module(number[:2])
if not module:
raise InvalidComponent()
return number[:2] + module.validate(number[2:])
开发者ID:cedk,项目名称:python-stdnum,代码行数:8,代码来源:vat.py
示例7: compact
def compact(number):
"""Convert the number to the minimal representation. This strips the
number of any valid separators and removes surrounding whitespace."""
number = clean(number, '').upper().strip()
module = _get_cc_module(number[:2])
if not module:
raise InvalidComponent()
return number[:2] + module.compact(number[2:])
开发者ID:cedk,项目名称:python-stdnum,代码行数:8,代码来源:vat.py
示例8: compact
def compact(number):
"""Convert the number to the minimal representation. This strips the
number of any valid separators and removes surrounding whitespace."""
number = clean(number, ' -./:').upper().strip()
if number.startswith('EL') or number.startswith('GR'):
number = number[2:]
if len(number) == 8:
number = '0' + number # old format had 8 digits
return number
开发者ID:FabianCollaguazo,项目名称:python-stdnum,代码行数:9,代码来源:vat.py
示例9: _split
def _split(number):
"""Split the number into a court, registry, register number and
optionally qualifier."""
number = clean(number).strip()
for fmt in _formats:
m = re.match(fmt, number, flags=re.I | re.U)
if m:
return m.group('court'), m.group('registry'), m.group('nr'), m.group('x')
raise InvalidFormat()
开发者ID:arthurdejong,项目名称:python-stdnum,代码行数:9,代码来源:handelsregisternummer.py
示例10: split
def split(number):
"""Splits the number into a root, an episode or part, a check digit a
version and another check digit. If any of the parts are missing an
empty string is returned."""
number = clean(number, ' -').strip().upper()
if len(number) == 17 or len(number) == 26:
return number[0:12], number[12:16], number[16], number[17:25], number[25:]
elif len(number) > 16:
return number[0:12], number[12:16], '', number[16:24], number[24:]
else:
return number[0:12], number[12:16], number[16:], '', ''
开发者ID:FabianCollaguazo,项目名称:python-stdnum,代码行数:11,代码来源:isan.py
示例11: compact
def compact(number, convert=False):
"""Convert the ISBN to the minimal representation. This strips the number
of any valid ISBN separators and removes surrounding whitespace. If the
covert parameter is True the number is also converted to ISBN-13
format."""
number = clean(number, ' -').strip().upper()
if len(number) == 9:
number = '0' + number
if convert:
return to_isbn13(number)
return number
开发者ID:benmao,项目名称:python-stdnum,代码行数:11,代码来源:isbn.py
示例12: validate
def validate(number):
"""Checks to see if the number provided is a valid ITIN. This checks
the length, groups and formatting if it is present."""
match = _itin_re.search(clean(number, '').strip())
if not match:
raise InvalidFormat()
area = match.group('area')
group = match.group('group')
if area[0] != '9' or group not in _allowed_groups:
raise InvalidComponent()
return compact(number)
开发者ID:FabianCollaguazo,项目名称:python-stdnum,代码行数:11,代码来源:itin.py
示例13: compact
def compact(number):
"""Convert the number to the minimal representation. This strips the
number of any valid separators and removes surrounding whitespace."""
number = clean(number).strip().replace(' ', '-').split('-')
if len(number) == 4:
# zero pad the different sections if they are found
lengths = (2, 4, 7, 3)
return ''.join(n.zfill(l) for n, l in zip(number, lengths))
else:
# otherwise zero pad the account type
number = ''.join(number)
return number[:13] + number[13:].zfill(3)
开发者ID:arthurdejong,项目名称:python-stdnum,代码行数:12,代码来源:bankaccount.py
示例14: validate
def validate(number):
"""Checks to see if the number provided is a valid SSN. This checks
the length, groups and formatting if it is present."""
match = _ssn_re.search(clean(number, "").strip())
if not match:
raise InvalidFormat()
area = match.group("area")
group = match.group("group")
serial = match.group("serial")
# check for all-0 or some unused areas
# (9xx also won't be issued which includes the advertising range)
if area == "000" or area == "666" or area[0] == "9" or group == "00" or serial == "0000":
raise InvalidComponent()
# check blacklists
if format(number) in _ssn_blacklist:
raise InvalidComponent()
return compact(number)
开发者ID:jcampanavelarde,项目名称:python-stdnum,代码行数:17,代码来源:ssn.py
示例15: to_isbn13
def to_isbn13(number):
"""Convert the number to ISBN-13 format."""
number = number.strip()
min_number = clean(number, ' -')
if len(min_number) == 13:
return number # nothing to do, already ISBN-13
if len(min_number) == 9:
number = '0' + number # convert from 9 to 10 digits
# put new check digit in place
number = number[:-1] + ean.calc_check_digit('978' + min_number[:-1])
# add prefix
if ' ' in number:
return '978 ' + number
elif '-' in number:
return '978-' + number
else:
return '978' + number
开发者ID:arthurdejong,项目名称:python-stdnum,代码行数:17,代码来源:isbn.py
示例16: validate
def validate(number):
"""Check if the number is a valid SSN. This checks the length, groups and
formatting if it is present."""
match = _ssn_re.search(clean(number, '').strip())
if not match:
raise InvalidFormat()
area = match.group('area')
group = match.group('group')
serial = match.group('serial')
# check for all-0 or some unused areas
# (9xx also won't be issued which includes the advertising range)
if area == '000' or area == '666' or area[0] == '9' or \
group == '00' or serial == '0000':
raise InvalidComponent()
# check blacklists
if format(number) in _ssn_blacklist:
raise InvalidComponent()
return compact(number)
开发者ID:DimitriPapadopoulos,项目名称:python-stdnum,代码行数:18,代码来源:ssn.py
示例17: compact
def compact(number):
"""Convert the number to the minimal representation. This strips the
number of any valid separators and removes surrounding whitespace."""
return clean(number, '-').strip()
开发者ID:FabianCollaguazo,项目名称:python-stdnum,代码行数:4,代码来源:itin.py
示例18: compact
def compact(number):
"""Convert the Veronumero to the minimal representation. This strips
surrounding whitespace and removes separators."""
return clean(number, ' ').strip()
开发者ID:DimitriPapadopoulos,项目名称:python-stdnum,代码行数:4,代码来源:veronumero.py
示例19: compact
def compact(number):
"""Convert the number to the minimal representation. This strips
surrounding whitespace and separation dash."""
return clean(number, ' ').upper().strip()
开发者ID:arthurdejong,项目名称:python-stdnum,代码行数:4,代码来源:nid.py
示例20: compact
def compact(number):
"""Convert the kennitala to the minimal representation. This
strips surrounding whitespace and separation dash, and converts it
to upper case."""
return clean(number, '-').upper().strip()
开发者ID:dchoruzy,项目名称:python-stdnum,代码行数:5,代码来源:kennitala.py
注:本文中的stdnum.util.clean函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论