def _is_known_agency(agency): """Checks whether the specified agency is valid.""" # look it up in the db from stdnum import numdb results = numdb.get('isil').info(agency.upper() + '$') # there should be only one part and it should have properties return len(results) == 1 and bool(results[0][1])
def get_campus(number): """Determine the Campus or other location that issued the EIN.""" from stdnum import numdb number = compact(number) results = numdb.get('us/ein').info(number)[0][1] if not results: raise InvalidComponent() return results['campus']
def split(number): """Split the specified IMSI into a Mobile Country Code (MCC), a Mobile Network Code (MNC), a Mobile Station Identification Number (MSIN).""" from stdnum import numdb # clean up number number = compact(number) # split the number return tuple(numdb.get('imsi').split(number))
def get_birth_place(number): """Use the number to look up the place of birth of the person.""" from stdnum import numdb number = compact(number) results = numdb.get('cn/loc').info(number[:6])[0][1] if not results: raise InvalidComponent() return results
def info(number): """Return a dictionary of data about the supplied number. This typically returns the name of the bank and branch and a BIC if it is valid.""" number = compact(number) from stdnum import numdb info = {} for nr, found in numdb.get('nz/banks').info(number): info.update(found) return info
def _lookup(number): """Look up the manufacturer in the IEEE OUI registry.""" number = compact(number).replace(':', '').upper() info = numdb.get('oui').info(number) try: return (''.join(n[0] for n in info[:-1]), info[-2][1]['o'].replace('%', '"')) except IndexError: raise InvalidComponent()
def info(number): """Lookup information about the specified NACE. This returns a dict.""" number = compact(number) from stdnum import numdb info = dict() for _n, i in numdb.get('eu/nace').info(number): if not i: raise InvalidComponent() info.update(i) return info
def get_birth_place(number): """Use the number to look up the place of birth of the person. This can either be a state or federal territory within Malaysia or a country outside of Malaysia.""" from stdnum import numdb number = compact(number) results = numdb.get('my/bp').info(number[6:8])[0][1] if not results: raise InvalidComponent() return results
def _lookup(number): """Look up the manufacturer in the IEEE OUI registry.""" number = compact(number).replace(':', '').upper() info = numdb.get('oui').info(number) try: return ( ''.join(n[0] for n in info[:-1]), info[-2][1]['o'].replace('%', '"')) except IndexError: raise InvalidComponent()
def __init__(self, plmnid): plmnid = clean(plmnid, ' -').strip().upper() if not isdigits(plmnid): raise ValueError("Invalid PLMNID %s" % plmnid) if len(plmnid) not in (4, 5): raise ValueError("Invalid PLMNID length %s" % plmnid) if len(tuple(numdb.get('imsi').split(plmnid))) < 2: raise ValueError("Invalid PLMNID format %s" % plmnid) self.info = dict(plmnid=plmnid) mcc_info, mnc_info = numdb.get('imsi').info(plmnid) self.info['mcc'] = mcc_info[0] self.info.update(mcc_info[1]) self.info['mnc'] = mnc_info[0] self.info.update(mnc_info[1])
def __init__(self, imsi): imsi = clean(imsi, ' -').strip().upper() if not isdigits(imsi): raise ValueError("Invalid IMSI %s" % imsi) if len(imsi) not in (14, 15): raise ValueError("Invalid IMSI length %s" % imsi) if len(tuple(numdb.get('imsi').split(imsi))) < 2: raise ValueError("Invalid IMSI length %s" % imsi) self.info = dict(imsi=imsi) mcc_info, mnc_info, msin_info = numdb.get('imsi').info(imsi) self.info['mcc'] = mcc_info[0] self.info.update(mcc_info[1]) self.info['mnc'] = mnc_info[0] self.info.update(mnc_info[1]) self.info['msin'] = msin_info[0] self.info.update(msin_info[1])
def info(number): """Return a dictionary of data about the supplied number.""" from stdnum import numdb # clean up number number = compact(number) # split the number info = dict(number=number) mcc_info, mnc_info, msin_info = numdb.get('imsi').info(number) info['mcc'] = mcc_info[0] info.update(mcc_info[1]) info['mnc'] = mnc_info[0] info.update(mnc_info[1]) info['msin'] = msin_info[0] info.update(msin_info[1]) return info
def split(number, convert=False): """Split the specified ISBN into an EAN.UCC prefix, a group prefix, a registrant, an item number and a check-digit. If the number is in ISBN-10 format the returned EAN.UCC prefix is '978'. If the covert parameter is True the number is converted to ISBN-13 format first.""" from stdnum import numdb # clean up number number = compact(number, convert) # get Bookland prefix if any delprefix = False if len(number) == 10: number = '978' + number delprefix = True # split the number result = numdb.get('isbn').split(number[:-1]) itemnr = result.pop() if result else '' prefix = result.pop(0) if result else '' group = result.pop(0) if result else '' publisher = result.pop(0) if result else '' # return results return ('' if delprefix else prefix, group, publisher, itemnr, number[-1])
def info(number): """Return a dictionary of data about the supplied number. This typically returns the the tax office and region.""" number = compact(number) from stdnum import numdb return numdb.get('at/fa').info(number[:2])[0][1]
'GR1601101050000010547023795' >>> format('GR1601101050000010547023795') 'GR16 0110 1050 0000 1054 7023 795' >>> calc_check_digits('BExx435411161155') '31' """ import re from stdnum import numdb from stdnum.exceptions import * from stdnum.iso7064 import mod_97_10 from stdnum.util import clean, get_cc_module # our open copy of the IBAN database _ibandb = numdb.get('iban') # regular expression to check IBAN structure _struct_re = re.compile(r'([1-9][0-9]*)!([nac])') # cache of country codes to modules _country_modules = {} def compact(number): """Convert the iban number to the minimal representation. This strips the number of any valid separators and removes surrounding whitespace.""" return clean(number, ' -.').strip().upper() def calc_check_digits(number):
>>> compact('GR16 0110 1050 0000 1054 7023 795') 'GR1601101050000010547023795' >>> format('GR1601101050000010547023795') 'GR16 0110 1050 0000 1054 7023 795' """ import re from stdnum import numdb from stdnum.exceptions import * from stdnum.iso7064 import mod_97_10 from stdnum.util import clean # our open copy of the IBAN database _ibandb = numdb.get('iban') # the valid characters we have _alphabet = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' # regular expression to check IBAN structure _struct_re = re.compile(r'([1-9][0-9]*)!([nac])') def compact(number): """Convert the iban number to the minimal representation. This strips the number of any valid separators and removes surrounding whitespace.""" return clean(number, ' -').strip().upper() def _to_base10(number):
def info(number): """Return a dictionary of data about the supplied number. This typically returns the name of the bank and a BIC if it is valid.""" number = compact(number) from stdnum import numdb return numdb.get('be/banks').info(number[4:7])[0][1]
def info(number): """Return a dictionary of data about the supplied number. This typically returns the location.""" number = compact(number) from stdnum import numdb return numdb.get('at/postleitzahl').info(number)[0][1]
>>> info('0138425876095074') {'01': '38425876095074'} >>> validate('(17)181119(01)38425876095074(37)1') '013842587609507417181119371' """ import datetime import decimal import re from stdnum import numdb from stdnum.exceptions import * from stdnum.util import clean # our open copy of the application identifier database _gs1_aidb = numdb.get('gs1_ai') # Extra validation modules based on the application identifier _ai_validators = { '01': 'stdnum.ean', '02': 'stdnum.ean', '8007': 'stdnum.iban', } def compact(number): """Convert the GS1-128 to the minimal representation. This strips the number of any valid separators and removes surrounding whitespace. For a more consistent compact representation use :func:`validate()`.
{ "Form": "Registered", "Ownership/transfer/sales restrictions": "Free", "Payment status": "Fully paid", "Voting right": "Non-voting", "category": "Equities", "group": "Limited partnership units" } """ from stdnum import numdb from stdnum.exceptions import * from stdnum.util import clean # our open copy of the CFI database _cfidb = numdb.get('cfi') 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().upper() def info(number): """Look up information about the number.""" number = compact(number) info = _cfidb.info(number) if len(info) != 6: raise InvalidComponent() properties = {}