1
- # -*- encoding: utf-8 -*-
2
- #
3
- # Copyright (c) 2013-2018, OVH SAS.
1
+ # Copyright (c) 2013-2023, OVH SAS.
4
2
# All rights reserved.
5
3
#
6
4
# Redistribution and use in source and binary forms, with or without
38
36
import json
39
37
import keyword
40
38
import 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
47
40
48
41
from requests import Session
49
42
from requests .exceptions import RequestException
50
43
51
- from .config import config
44
+ from . import config
52
45
from .consumer_key import ConsumerKeyRequest
53
46
from .exceptions import (
54
47
APIError ,
82
75
TIMEOUT = 180
83
76
84
77
85
- class Client ( object ) :
78
+ class Client :
86
79
"""
87
80
Low level OVH Client. It abstracts all the authentication and request
88
81
signing logic along with some nice tools helping with key generation.
@@ -152,13 +145,16 @@ def __init__(
152
145
:param float timeout: Same timeout for both connection and read
153
146
:raises InvalidRegion: if ``endpoint`` can't be found in ``ENDPOINTS``.
154
147
"""
148
+
149
+ configuration = config .ConfigurationManager ()
150
+
155
151
# Load a custom config file if requested
156
152
if config_file is not None :
157
- config .read (config_file )
153
+ configuration .read (config_file )
158
154
159
155
# load endpoint
160
156
if endpoint is None :
161
- endpoint = config .get ("default" , "endpoint" )
157
+ endpoint = configuration .get ("default" , "endpoint" )
162
158
163
159
try :
164
160
self ._endpoint = ENDPOINTS [endpoint ]
@@ -167,15 +163,15 @@ def __init__(
167
163
168
164
# load keys
169
165
if application_key is None :
170
- application_key = config .get (endpoint , "application_key" )
166
+ application_key = configuration .get (endpoint , "application_key" )
171
167
self ._application_key = application_key
172
168
173
169
if application_secret is None :
174
- application_secret = config .get (endpoint , "application_secret" )
170
+ application_secret = configuration .get (endpoint , "application_secret" )
175
171
self ._application_secret = application_secret
176
172
177
173
if consumer_key is None :
178
- consumer_key = config .get (endpoint , "consumer_key" )
174
+ consumer_key = configuration .get (endpoint , "consumer_key" )
179
175
self ._consumer_key = consumer_key
180
176
181
177
# lazy load time delta
@@ -510,7 +506,7 @@ def raw_call(self, method, path, data=None, need_auth=True, headers=None):
510
506
# include payload
511
507
if data is not None :
512
508
headers ["Content-type" ] = "application/json"
513
- body = json .dumps (data )
509
+ body = json .dumps (data , separators = ( "," , ":" )) # Separators to prevent adding useless spaces
514
510
515
511
# sign request. Never sign 'time' or will recurse infinitely
516
512
if need_auth :
0 commit comments