1- # -*- encoding: utf-8 -*-
2- #
3- # Copyright (c) 2013-2018, OVH SAS.
1+ # Copyright (c) 2013-2023, OVH SAS.
42# All rights reserved.
53#
64# Redistribution and use in source and binary forms, with or without
3836import json
3937import keyword
4038import time
41-
42- try :
43- from urllib import urlencode
44- except ImportError : # pragma: no cover
45- # Python 3
46- from urllib .parse import urlencode
39+ from urllib .parse import urlencode
4740
4841from requests import Session
4942from requests .exceptions import RequestException
5043
51- from .config import config
44+ from . import config
5245from .consumer_key import ConsumerKeyRequest
5346from .exceptions import (
5447 APIError ,
8275TIMEOUT = 180
8376
8477
85- class Client ( object ) :
78+ class Client :
8679 """
8780 Low level OVH Client. It abstracts all the authentication and request
8881 signing logic along with some nice tools helping with key generation.
@@ -152,13 +145,16 @@ def __init__(
152145 :param float timeout: Same timeout for both connection and read
153146 :raises InvalidRegion: if ``endpoint`` can't be found in ``ENDPOINTS``.
154147 """
148+
149+ configuration = config .ConfigurationManager ()
150+
155151 # Load a custom config file if requested
156152 if config_file is not None :
157- config .read (config_file )
153+ configuration .read (config_file )
158154
159155 # load endpoint
160156 if endpoint is None :
161- endpoint = config .get ("default" , "endpoint" )
157+ endpoint = configuration .get ("default" , "endpoint" )
162158
163159 try :
164160 self ._endpoint = ENDPOINTS [endpoint ]
@@ -167,15 +163,15 @@ def __init__(
167163
168164 # load keys
169165 if application_key is None :
170- application_key = config .get (endpoint , "application_key" )
166+ application_key = configuration .get (endpoint , "application_key" )
171167 self ._application_key = application_key
172168
173169 if application_secret is None :
174- application_secret = config .get (endpoint , "application_secret" )
170+ application_secret = configuration .get (endpoint , "application_secret" )
175171 self ._application_secret = application_secret
176172
177173 if consumer_key is None :
178- consumer_key = config .get (endpoint , "consumer_key" )
174+ consumer_key = configuration .get (endpoint , "consumer_key" )
179175 self ._consumer_key = consumer_key
180176
181177 # lazy load time delta
@@ -510,7 +506,7 @@ def raw_call(self, method, path, data=None, need_auth=True, headers=None):
510506 # include payload
511507 if data is not None :
512508 headers ["Content-type" ] = "application/json"
513- body = json .dumps (data )
509+ body = json .dumps (data , separators = ( "," , ":" )) # Separators to prevent adding useless spaces
514510
515511 # sign request. Never sign 'time' or will recurse infinitely
516512 if need_auth :
0 commit comments