Coverage for adhoc-cicd-odoo-odoo / odoo / _monkeypatches / stdnum.py: 17%

34 statements  

« prev     ^ index     » next       coverage.py v7.13.4, created at 2026-03-09 18:15 +0000

1# ruff: noqa: PLC0415 

2 

3_soap_clients = {} 

4 

5 

6def new_get_soap_client(wsdlurl, timeout=30): 

7 # stdnum library does not set the timeout for the zeep Transport class correctly 

8 # (timeout is to fetch the wsdl and operation_timeout is to perform the call), 

9 # requiring us to monkey patch the get_soap_client function. 

10 # Can be removed when https://github.com/arthurdejong/python-stdnum/issues/444 is 

11 # resolved and the version of the dependency is updated. 

12 # The code is a copy of the original apart for the line related to the Transport class. 

13 # This was done to keep the code as similar to the original and to reduce the possibility 

14 # of introducing import errors, even though some imports are not in the requirements. 

15 # See https://github.com/odoo/odoo/pull/173359 for a more thorough explanation. 

16 if (wsdlurl, timeout) not in _soap_clients: 

17 try: 

18 from zeep.transports import Transport 

19 transport = Transport(operation_timeout=timeout, timeout=timeout) # operational_timeout added here 

20 from zeep import CachingClient 

21 client = CachingClient(wsdlurl, transport=transport).service 

22 except ImportError: 

23 # fall back to non-caching zeep client 

24 try: 

25 from zeep import Client 

26 client = Client(wsdlurl, transport=transport).service 

27 except ImportError: 

28 # other implementations require passing the proxy config 

29 try: 

30 from urllib import getproxies 

31 except ImportError: 

32 from urllib.request import getproxies 

33 # fall back to suds 

34 try: 

35 from suds.client import Client 

36 client = Client( 

37 wsdlurl, proxy=getproxies(), timeout=timeout).service 

38 except ImportError: 

39 # use pysimplesoap as last resort 

40 try: 

41 from pysimplesoap.client import SoapClient 

42 client = SoapClient( 

43 wsdl=wsdlurl, proxy=getproxies(), timeout=timeout) 

44 except ImportError: 

45 raise ImportError( 

46 'No SOAP library (such as zeep) found') 

47 _soap_clients[(wsdlurl, timeout)] = client 

48 return _soap_clients[(wsdlurl, timeout)] 

49 

50 

51def patch_module(): 

52 try: 

53 from stdnum import util 

54 except ImportError: 

55 return # nothing to patch 

56 

57 util.get_soap_client = new_get_soap_client