lists.arthurdejong.org
RSS feed

python-stdnum branch master updated. 1.8.1-2-g5fd1ae0

[Date Prev][Date Next] [Thread Prev][Thread Next]

python-stdnum branch master updated. 1.8.1-2-g5fd1ae0



This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "python-stdnum".

The branch, master has been updated
       via  5fd1ae0437da91b4642f3bdb00c175a511fa8a05 (commit)
      from  c113613b70629a6ba92dcc0afc9dbf834f5179ee (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
https://arthurdejong.org/git/python-stdnum/commit/?id=5fd1ae0437da91b4642f3bdb00c175a511fa8a05

commit 5fd1ae0437da91b4642f3bdb00c175a511fa8a05
Author: Arthur de Jong <arthur@arthurdejong.org>
Date:   Tue Feb 6 23:04:23 2018 +0100

    Allow configuring SOAP request timeout
    
    This adds a timeout parameter to all checks that use a SOAP web service
    to reduce the blocking time. The default timeout for all checks is 30
    seconds.

diff --git a/stdnum/do/ncf.py b/stdnum/do/ncf.py
index cfdb890..c59d8b9 100644
--- a/stdnum/do/ncf.py
+++ b/stdnum/do/ncf.py
@@ -1,7 +1,7 @@
 # ncf.py - functions for handling Dominican Republic invoice numbers
 # coding: utf-8
 #
-# Copyright (C) 2017 Arthur de Jong
+# Copyright (C) 2018 Arthur de Jong
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -99,12 +99,13 @@ def _convert_result(result):  # pragma: no cover
         for key, value in json.loads(result.replace('\t', '\\t')).items())
 
 
-def check_dgii(rnc, ncf):  # pragma: no cover
+def check_dgii(rnc, ncf, timeout=30):  # pragma: no cover
     """Validate the RNC, NCF combination on using the DGII online web service.
 
     This uses the validation service run by the the Dirección General de
     Impuestos Internos, the Dominican Republic tax department to check
-    whether the combination of RNC and NCF is valid.
+    whether the combination of RNC and NCF is valid. The timeout is in
+    seconds.
 
     Returns a dict with the following structure::
 
@@ -122,7 +123,7 @@ def check_dgii(rnc, ncf):  # pragma: no cover
     from stdnum.do.rnc import dgii_wsdl
     rnc = rnc_compact(rnc)
     ncf = compact(ncf)
-    client = get_soap_client(dgii_wsdl)
+    client = get_soap_client(dgii_wsdl, timeout)
     result = client.GetNCF(
         RNC=rnc,
         NCF=ncf,
diff --git a/stdnum/do/rnc.py b/stdnum/do/rnc.py
index 140bc2d..ef6f30a 100644
--- a/stdnum/do/rnc.py
+++ b/stdnum/do/rnc.py
@@ -1,7 +1,7 @@
 # rnc.py - functions for handling Dominican Republic tax registration
 # coding: utf-8
 #
-# Copyright (C) 2015-2017 Arthur de Jong
+# Copyright (C) 2015-2018 Arthur de Jong
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -115,12 +115,12 @@ def _convert_result(result):  # pragma: no cover
         for key, value in json.loads(result.replace('\t', '\\t')).items())
 
 
-def check_dgii(number):  # pragma: no cover
+def check_dgii(number, timeout=30):  # pragma: no cover
     """Lookup the number using the DGII online web service.
 
     This uses the validation service run by the the Dirección General de
     Impuestos Internos, the Dominican Republic tax department to lookup
-    registration information for the number.
+    registration information for the number. The timeout is in seconds.
 
     Returns a dict with the following structure::
 
@@ -137,7 +137,7 @@ def check_dgii(number):  # pragma: no cover
     # this function isn't automatically tested because it would require
     # network access for the tests and unnecessarily load the online service
     number = compact(number)
-    client = get_soap_client(dgii_wsdl)
+    client = get_soap_client(dgii_wsdl, timeout)
     result = '%s' % client.GetContribuyentes(
         value=number,
         patronBusqueda=0,   # search type: 0=by number, 1=by name
@@ -149,7 +149,7 @@ def check_dgii(number):  # pragma: no cover
     return _convert_result(result)
 
 
-def search_dgii(keyword, end_at=10, start_at=1):  # pragma: no cover
+def search_dgii(keyword, end_at=10, start_at=1, timeout=30):  # pragma: no 
cover
     """Search the DGII online web service using the keyword.
 
     This uses the validation service run by the the Dirección General de
@@ -157,7 +157,7 @@ def search_dgii(keyword, end_at=10, start_at=1):  # pragma: 
no cover
     registration information using the keyword.
 
     The number of entries returned can be tuned with the `end_at` and
-    `start_at` arguments.
+    `start_at` arguments. The timeout is in seconds.
 
     Returns a list of dicts with the following structure::
 
@@ -177,7 +177,7 @@ def search_dgii(keyword, end_at=10, start_at=1):  # pragma: 
no cover
     Will return an empty list if the number is invalid or unknown."""
     # this function isn't automatically tested because it would require
     # network access for the tests and unnecessarily load the online service
-    client = get_soap_client(dgii_wsdl)
+    client = get_soap_client(dgii_wsdl, timeout)
     results = '%s' % client.GetContribuyentes(
         value=keyword,
         patronBusqueda=1,       # search type: 0=by number, 1=by name
diff --git a/stdnum/eu/vat.py b/stdnum/eu/vat.py
index 98fd850..c6d9c94 100644
--- a/stdnum/eu/vat.py
+++ b/stdnum/eu/vat.py
@@ -1,7 +1,7 @@
 # vat.py - functions for handling European VAT numbers
 # coding: utf-8
 #
-# Copyright (C) 2012-2016 Arthur de Jong
+# Copyright (C) 2012-2018 Arthur de Jong
 # Copyright (C) 2015 Lionel Elie Mamane
 #
 # This library is free software; you can redistribute it and/or
@@ -109,29 +109,30 @@ def guess_country(number):
             if _get_cc_module(cc).is_valid(number)]
 
 
-def check_vies(number):  # pragma: no cover (not part of normal test suite)
+def check_vies(number, timeout=30):  # pragma: no cover (not part of normal 
test suite)
     """Query the online European Commission VAT Information Exchange System
     (VIES) for validity of the provided number. Note that the service has
-    usage limitations (see the VIES website for details). This returns a
-    dict-like object."""
+    usage limitations (see the VIES website for details). The timeout is in
+    seconds. 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)
-    client = get_soap_client(vies_wsdl)
+    client = get_soap_client(vies_wsdl, timeout)
     return client.checkVat(number[:2], number[2:])
 
 
-def check_vies_approx(number, requester):  # pragma: no cover
+def check_vies_approx(number, requester, timeout=30):  # pragma: no cover
     """Query 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."""
+    website for details). The timeout is in seconds. 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)
-    client = get_soap_client(vies_wsdl)
+    client = get_soap_client(vies_wsdl, timeout)
     return client.checkVatApprox(
         countryCode=number[:2], vatNumber=number[2:],
         requesterCountryCode=requester[:2], requesterVatNumber=requester[2:])
diff --git a/stdnum/tr/tckimlik.py b/stdnum/tr/tckimlik.py
index dc35922..e5f84a6 100644
--- a/stdnum/tr/tckimlik.py
+++ b/stdnum/tr/tckimlik.py
@@ -1,7 +1,7 @@
 # tckimlik.py - functions for handling T.C. Kimlik No.
 # coding: utf-8
 #
-# Copyright (C) 2016-2017 Arthur de Jong
+# Copyright (C) 2016-2018 Arthur de Jong
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -89,14 +89,15 @@ def is_valid(number):
         return False
 
 
-def check_kps(number, name, surname, birth_year):  # pragma: no cover
+def check_kps(number, name, surname, birth_year, timeout):  # pragma: no cover
     """Query the online T.C. Kimlik validation service run by the Directorate
-    of Population and Citizenship Affairs. This returns a boolean but may
-    raise a SOAP exception for missing or invalid values."""
+    of Population and Citizenship Affairs. The timeout is in seconds. This
+    returns a boolean but may raise a SOAP exception for missing or invalid
+    values."""
     # this function isn't automatically tested because it would require
     # network access for the tests and unnecessarily load the online service
     number = compact(number)
-    client = get_soap_client(tckimlik_wsdl)
+    client = get_soap_client(tckimlik_wsdl, timeout)
     result = client.TCKimlikNoDogrula(
         TCKimlikNo=number, Ad=name, Soyad=surname, DogumYili=birth_year)
     if hasattr(result, 'get'):
diff --git a/stdnum/util.py b/stdnum/util.py
index 3a48729..3e04c79 100644
--- a/stdnum/util.py
+++ b/stdnum/util.py
@@ -1,7 +1,7 @@
 # util.py - common utility functions
 # coding: utf-8
 #
-# Copyright (C) 2012-2017 Arthur de Jong
+# Copyright (C) 2012-2018 Arthur de Jong
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -173,20 +173,23 @@ def get_cc_module(cc, name):
 _soap_clients = {}
 
 
-def get_soap_client(wsdlurl):  # pragma: no cover (not part of normal test 
suite)
-    """Get a SOAP client for performing requests. The client is cached."""
+def get_soap_client(wsdlurl, timeout=30):  # pragma: no cover (not part of 
normal test suite)
+    """Get a SOAP client for performing requests. The client is cached. The
+    timeout is in seconds."""
     # this function isn't automatically tested because the functions using
     # it are not automatically tested
-    if wsdlurl not in _soap_clients:
+    if (wsdlurl, timeout) not in _soap_clients:
         # try zeep first
         try:
+            from zeep.transports import Transport
+            transport = Transport(timeout=timeout)
             from zeep import CachingClient
-            client = CachingClient(wsdlurl).service
+            client = CachingClient(wsdlurl, transport=transport).service
         except ImportError:
             # fall back to non-caching zeep client
             try:
                 from zeep import Client
-                client = Client(wsdlurl).service
+                client = Client(wsdlurl, transport=transport).service
             except ImportError:
                 # other implementations require passing the proxy config
                 try:
@@ -196,10 +199,16 @@ def get_soap_client(wsdlurl):  # pragma: no cover (not 
part of normal test suite
                 # fall back to suds
                 try:
                     from suds.client import Client
-                    client = Client(wsdlurl, proxy=getproxies()).service
+                    client = Client(
+                        wsdlurl, proxy=getproxies(), timeout=timeout).service
                 except ImportError:
                     # use pysimplesoap as last resort
-                    from pysimplesoap.client import SoapClient
-                    client = SoapClient(wsdl=wsdlurl, proxy=getproxies())
-        _soap_clients[wsdlurl] = client
-    return _soap_clients[wsdlurl]
+                    try:
+                        from pysimplesoap.client import SoapClient
+                        client = SoapClient(
+                            wsdl=wsdlurl, proxy=getproxies(), timeout=timeout)
+                    except ImportError:
+                        raise ImportError(
+                            'No SOAP library (such as zeep) found')
+        _soap_clients[(wsdlurl, timeout)] = client
+    return _soap_clients[(wsdlurl, timeout)]

-----------------------------------------------------------------------

Summary of changes:
 stdnum/do/ncf.py      |  9 +++++----
 stdnum/do/rnc.py      | 14 +++++++-------
 stdnum/eu/vat.py      | 17 +++++++++--------
 stdnum/tr/tckimlik.py | 11 ++++++-----
 stdnum/util.py        | 31 ++++++++++++++++++++-----------
 5 files changed, 47 insertions(+), 35 deletions(-)


hooks/post-receive
-- 
python-stdnum
-- 
To unsubscribe send an email to
python-stdnum-commits-unsubscribe@lists.arthurdejong.org or see
https://lists.arthurdejong.org/python-stdnum-commits/