gooderp18绿色标准版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
2.5KB

  1. # ruff: noqa: PLC0415
  2. _soap_clients = {}
  3. def new_get_soap_client(wsdlurl, timeout=30):
  4. # stdnum library does not set the timeout for the zeep Transport class correctly
  5. # (timeout is to fetch the wsdl and operation_timeout is to perform the call),
  6. # requiring us to monkey patch the get_soap_client function.
  7. # Can be removed when https://github.com/arthurdejong/python-stdnum/issues/444 is
  8. # resolved and the version of the dependency is updated.
  9. # The code is a copy of the original apart for the line related to the Transport class.
  10. # This was done to keep the code as similar to the original and to reduce the possibility
  11. # of introducing import errors, even though some imports are not in the requirements.
  12. # See https://github.com/odoo/odoo/pull/173359 for a more thorough explanation.
  13. if (wsdlurl, timeout) not in _soap_clients:
  14. try:
  15. from zeep.transports import Transport
  16. transport = Transport(operation_timeout=timeout, timeout=timeout) # operational_timeout added here
  17. from zeep import CachingClient
  18. client = CachingClient(wsdlurl, transport=transport).service
  19. except ImportError:
  20. # fall back to non-caching zeep client
  21. try:
  22. from zeep import Client
  23. client = Client(wsdlurl, transport=transport).service
  24. except ImportError:
  25. # other implementations require passing the proxy config
  26. try:
  27. from urllib import getproxies
  28. except ImportError:
  29. from urllib.request import getproxies
  30. # fall back to suds
  31. try:
  32. from suds.client import Client
  33. client = Client(
  34. wsdlurl, proxy=getproxies(), timeout=timeout).service
  35. except ImportError:
  36. # use pysimplesoap as last resort
  37. try:
  38. from pysimplesoap.client import SoapClient
  39. client = SoapClient(
  40. wsdl=wsdlurl, proxy=getproxies(), timeout=timeout)
  41. except ImportError:
  42. raise ImportError(
  43. 'No SOAP library (such as zeep) found')
  44. _soap_clients[(wsdlurl, timeout)] = client
  45. return _soap_clients[(wsdlurl, timeout)]
  46. def patch_stdnum():
  47. try:
  48. from stdnum import util
  49. except ImportError:
  50. return # nothing to patch
  51. util.get_soap_client = new_get_soap_client
上海开阖软件有限公司 沪ICP备12045867号-1