def __init__(self, mc_api=None, mc_user='python-mailchimp', access_token=None, enabled=True, timeout=None,
                 request_hooks=None, request_headers=None):
        """
        Initialize the class with your optional user_id and required api_key.

        If `enabled` is not True, these methods become no-ops. This is
        particularly useful for testing or disabling with configuration.

        :param mc_api: Mailchimp API key
        :type mc_api: :py:class:`str`
        :param mc_user: Mailchimp user id
        :type mc_user: :py:class:`str`
        :param access_token: The OAuth access token
        :type access_token: :py:class:`str`
        :param enabled: Whether the API should execute any requests
        :type enabled: :py:class:`bool`
        :param timeout: (optional) How long to wait for the server to send
            data before giving up, as a float, or a :ref:`(connect timeout,
            read timeout) <timeouts>` tuple.
        :type timeout: float or tuple
        :param request_hooks: (optional) Hooks for :py:func:`requests.requests`.
        :type request_hooks: :py:class:`dict`
        :param request_headers: (optional) Headers for
            :py:func:`requests.requests`.
        :type request_headers: :py:class:`dict`
        """
        super(MailChimpClient, self).__init__()
        self.enabled = enabled
        self.timeout = timeout
        if access_token:
            self.auth = MailChimpOAuth(access_token)
            self.base_url = self.auth.get_base_url() + '/3.0/'
        elif mc_api:
            if not re.match(r"^[0-9a-f]{32}$", mc_api.split('-')[0]):
                raise ValueError('The API key that you have entered is not valid, did you enter a username by mistake?\n'
                                 'The order of arguments for API key and username has reversed in 2.1.0')
            self.auth = HTTPBasicAuth(mc_user, mc_api)
            datacenter = mc_api.split('-').pop()
            self.base_url = 'https://{0}.api.mailchimp.com/3.0/'.format(datacenter)
        else:
            raise Exception('You must provide an OAuth access token or API key')
        self.request_headers = request_headers or requests.utils.default_headers()
        self.request_hooks = request_hooks or requests.hooks.default_hooks()
def __init__ ( self , mc_api = None , mc_user = 'python-mailchimp' , access_token = None , enabled = True , timeout = None , request_hooks = None , request_headers = None ) : super ( MailChimpClient , self ) . __init__ ( ) self . enabled = enabled self . timeout = timeout if access_token : self . auth = MailChimpOAuth ( access_token ) self . base_url = self . auth . get_base_url ( ) + '/3.0/' elif mc_api : if not re . match ( r"^[0-9a-f]{32}$" , mc_api . split ( '-' ) [ 0 ] ) : raise ValueError ( 'The API key that you have entered is not valid, did you enter a username by mistake?\n' 'The order of arguments for API key and username has reversed in 2.1.0' ) self . auth = HTTPBasicAuth ( mc_user , mc_api ) datacenter = mc_api . split ( '-' ) . pop ( ) self . base_url = 'https://{0}.api.mailchimp.com/3.0/' . format ( datacenter ) else : raise Exception ( 'You must provide an OAuth access token or API key' ) self . request_headers = request_headers or requests . utils . default_headers ( ) self . request_hooks = request_hooks or requests . hooks . default_hooks ( )
Initialize the class with your optional user_id and required api_key.

        If `enabled` is not True, these methods become no-ops. This is
        particularly useful for testing or disabling with configuration.

        :param mc_api: Mailchimp API key
        :type mc_api: :py:class:`str`
        :param mc_user: Mailchimp user id
        :type mc_user: :py:class:`str`
        :param access_token: The OAuth access token
        :type access_token: :py:class:`str`
        :param enabled: Whether the API should execute any requests
        :type enabled: :py:class:`bool`
        :param timeout: (optional) How long to wait for the server to send
            data before giving up, as a float, or a :ref:`(connect timeout,
            read timeout) <timeouts>` tuple.
        :type timeout: float or tuple
        :param request_hooks: (optional) Hooks for :py:func:`requests.requests`.
        :type request_hooks: :py:class:`dict`
        :param request_headers: (optional) Headers for
            :py:func:`requests.requests`.
        :type request_headers: :py:class:`dict`