update shared dependencies
This commit is contained in:
parent
d4d3d82be3
commit
736cd598a8
521 changed files with 45146 additions and 22574 deletions
76
Shared/lib/python3.4/site-packages/stdnum/eu/at_02.py
Normal file
76
Shared/lib/python3.4/site-packages/stdnum/eu/at_02.py
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
# at_02.py - functions for handling AT-02 (SEPA Creditor identifier)
|
||||
#
|
||||
# Copyright (C) 2014 Sergi Almacellas Abellana
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2.1 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public
|
||||
# License along with this library; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
# 02110-1301 USA
|
||||
|
||||
""" SEPA Identifier of the Creditor (AT-02)
|
||||
|
||||
This identifier is indicated in the ISO 20022 data element `Creditor Scheme
|
||||
Identification`. The creditor can be a legal entity, or an association that
|
||||
is not a legal entity, or a person.
|
||||
Ther first two digits contain the ISO country code, the nex two are check
|
||||
digitsi for the ISO 7064 Mod 97, 10 checksum, the next tree contain the
|
||||
Creditor Bussines Code (or `ZZZ` if no bussness code used) and the remainder
|
||||
contain the country-specific identifier.
|
||||
|
||||
>>> validate('ES23ZZZ47690558N')
|
||||
'ES23ZZZ47690558N'
|
||||
>>> validate('ES2300047690558N')
|
||||
'ES2300047690558N'
|
||||
>>> compact('ES++()+23ZZZ4//7690558N')
|
||||
'ES23ZZZ47690558N'
|
||||
"""
|
||||
|
||||
from stdnum.exceptions import *
|
||||
from stdnum.iso7064 import mod_97_10
|
||||
from stdnum.util import clean
|
||||
|
||||
# the valid characters we have
|
||||
_alphabet = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
||||
|
||||
|
||||
def compact(number):
|
||||
"""Convert the AT-02 number to the minimal representation. This strips the
|
||||
number of any valid separators and removes invalid characters."""
|
||||
return clean(number, ' -/?:().m\'+"').strip().upper()
|
||||
|
||||
|
||||
def _to_base10(number):
|
||||
"""Prepare the number to its base10 representation so it can be checked
|
||||
with the ISO 7064 Mod 97, 10 algorithm. That means excluding positions
|
||||
5 to 7 and moving the first four digits to the end"""
|
||||
return ''.join(str(_alphabet.index(x)) for x in number[7:] + number[:4])
|
||||
|
||||
|
||||
def validate(number):
|
||||
"""Checks to see if the number provided is a valid AT-02."""
|
||||
number = compact(number)
|
||||
try:
|
||||
test_number = _to_base10(number)
|
||||
except Exception:
|
||||
raise InvalidFormat()
|
||||
# ensure that checksum is valid
|
||||
mod_97_10.validate(test_number)
|
||||
return number
|
||||
|
||||
|
||||
def is_valid(number):
|
||||
"""Checks to see if the number provided is a valid AT-02."""
|
||||
try:
|
||||
return bool(validate(number))
|
||||
except ValidationError:
|
||||
return False
|
||||
|
|
@ -1,7 +1,8 @@
|
|||
# vat.py - functions for handling European VAT numbers
|
||||
# coding: utf-8
|
||||
#
|
||||
# Copyright (C) 2012, 2013 Arthur de Jong
|
||||
# Copyright (C) 2012-2015 Arthur de Jong
|
||||
# Copyright (C) 2015 Lionel Elie Mamane
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
|
|
@ -39,13 +40,13 @@ that country.
|
|||
"""
|
||||
|
||||
from stdnum.exceptions import *
|
||||
from stdnum.util import clean
|
||||
from stdnum.util import clean, get_vat_module
|
||||
|
||||
|
||||
country_codes = set([
|
||||
'at', 'be', 'bg', 'cy', 'cz', 'de', 'dk', 'ee', 'es', 'fi', 'fr', 'gb',
|
||||
'gr', 'hu', 'ie', 'it', 'lt', 'lu', 'lv', 'mt', 'nl', 'pl', 'pt', 'ro',
|
||||
'se', 'si', 'sk'
|
||||
'gr', 'hr', 'hu', 'ie', 'it', 'lt', 'lu', 'lv', 'mt', 'nl', 'pl', 'pt',
|
||||
'ro', 'se', 'si', 'sk',
|
||||
])
|
||||
"""The collection of country codes that are queried. Greece is listed with
|
||||
a country code of gr while for VAT purposes el is used instead."""
|
||||
|
|
@ -68,10 +69,7 @@ def _get_cc_module(cc):
|
|||
if cc not in country_codes:
|
||||
return
|
||||
if cc not in _country_modules:
|
||||
# do `from stdnum.CC import vat` instead of `import stdnum.CC.vat`
|
||||
# to handle the case where vat is an alias
|
||||
_country_modules[cc] = __import__(
|
||||
'stdnum.%s' % cc, globals(), locals(), ['vat']).vat
|
||||
_country_modules[cc] = get_vat_module(cc)
|
||||
return _country_modules[cc]
|
||||
|
||||
|
||||
|
|
@ -114,6 +112,27 @@ def guess_country(number):
|
|||
if _get_cc_module(cc).is_valid(number)]
|
||||
|
||||
|
||||
def _get_client(): # pragma: no cover (no tests for this function)
|
||||
"""Get a SOAP client for performing VIES requests."""
|
||||
# this function isn't automatically tested because the functions using
|
||||
# it are not automatically tested
|
||||
global _vies_client
|
||||
if not _vies_client:
|
||||
try:
|
||||
from urllib import getproxies
|
||||
except ImportError:
|
||||
from urllib.request import getproxies
|
||||
# try suds first
|
||||
try:
|
||||
from suds.client import Client
|
||||
_vies_client = Client(vies_wsdl, proxy=getproxies()).service
|
||||
except ImportError:
|
||||
# fall back to using pysimplesoap
|
||||
from pysimplesoap.client import SoapClient
|
||||
_vies_client = SoapClient(wsdl=vies_wsdl, proxy=getproxies())
|
||||
return _vies_client
|
||||
|
||||
|
||||
def check_vies(number): # pragma: no cover (no tests for this function)
|
||||
"""Queries the online European Commission VAT Information Exchange
|
||||
System (VIES) for validity of the provided number. Note that the
|
||||
|
|
@ -122,9 +141,19 @@ def check_vies(number): # pragma: no cover (no tests for this function)
|
|||
# this function isn't automatically tested because it would require
|
||||
# network access for the tests and unnecessarily load the VIES website
|
||||
number = compact(number)
|
||||
global _vies_client
|
||||
if not _vies_client:
|
||||
from suds.client import Client
|
||||
from urllib import getproxies
|
||||
_vies_client = Client(vies_wsdl, proxy=getproxies())
|
||||
return _vies_client.service.checkVat(number[:2], number[2:])
|
||||
return _get_client().checkVat(number[:2], number[2:])
|
||||
|
||||
|
||||
def check_vies_approx(number, requester): # pragma: no cover
|
||||
"""Queries the online European Commission VAT Information Exchange System
|
||||
(VIES) for validity of the provided number, providing a validity
|
||||
certificate as proof. You will need to give your own VAT number for this
|
||||
to work. Note that the service has usage limitations (see the VIES
|
||||
website for details). This returns a dict-like object."""
|
||||
# this function isn't automatically tested because it would require
|
||||
# network access for the tests and unnecessarily load the VIES website
|
||||
number = compact(number)
|
||||
requester = compact(requester)
|
||||
return _get_client.checkVatApprox(
|
||||
countryCode=number[:2], vatNumber=number[2:],
|
||||
requesterCountryCode=requester[:2], requesterVatNumber=requester[2:])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue