# Path: src/sii/lib/ptcl/helpers.py
# def with_retry(func, count=RETRIES_MAX, ival=RETRIES_SLEEP):
#     retries = 0
#     while retries < count:
#         try:
#             return func()
#         except Exception as exc:
#             code, msg = exc.args[0]
# 
#             if code == 503:
#                 retries += 1
#                 time.sleep(ival)
#                 continue
#             else:
#                 raise


import re
from suds.client import Client
from lxml        import etree
from .helpers import with_retry
""" SII WebService Authentication Seed.
"""



__all__ = [
    'Seed'
]


class Seed(object):

    SEED_OK         = 0
    SEED_LINE_ERR   = -1
    SEED_RETURN_ERR = -2

    def __init__(self, sii_host="https://palena.sii.cl/DTEWS/CrSeed.jws?wsdl"):
        self.sii_host = sii_host
        self.sii_soap = Client(self.sii_host)

        self._status = None
        self._seed   = None
        self._error  = None

        self._seed_xml    = self._fetch_seed()
        self._seed_etree  = self._prepare_seed_xml(self._seed_xml)
        self._seed_values = self._parse_seed_xml(self._seed_etree)

    def _fetch_seed(self):

# Path: src/sii/lib/ptcl/helpers.py
# def with_retry(func, count=RETRIES_MAX, ival=RETRIES_SLEEP):
#     retries = 0
#     while retries < count:
#         try:
#             return func()
#         except Exception as exc:
#             code, msg = exc.args[0]
# 
#             if code == 503:
#                 retries += 1
#                 time.sleep(ival)
#                 continue
#             else:
#                 raise


# Path: src/sii/lib/ptcl/Seed.py
import re
from suds.client import Client
from lxml        import etree
from .helpers import with_retry

""" SII WebService Authentication Seed.
"""



__all__ = [
    'Seed'
]


class Seed(object):

    SEED_OK         = 0
    SEED_LINE_ERR   = -1
    SEED_RETURN_ERR = -2

    def __init__(self, sii_host="https://palena.sii.cl/DTEWS/CrSeed.jws?wsdl"):
        self.sii_host = sii_host
        self.sii_soap = Client(self.sii_host)

        self._status = None
        self._seed   = None
        self._error  = None

        self._seed_xml    = self._fetch_seed()
        self._seed_etree  = self._prepare_seed_xml(self._seed_xml)
        self._seed_values = self._parse_seed_xml(self._seed_etree)

    def _fetch_seed(self):

        return with_retry(lambda: self.sii_soap.service.getSeed())