10
10
See LICENSES/GPL-3.0-only for more information.
11
11
"""
12
12
13
+ from copy import deepcopy
14
+
13
15
from six .moves .urllib .parse import urljoin
14
16
15
17
from . import CLIENT_ID , OAUTH_TOKEN , APP_TOKEN
@@ -122,21 +124,23 @@ def execute(self):
122
124
123
125
class ApiQuery (JsonQuery ):
124
126
def __init__ (self , path , headers = {}, data = {}, use_token = True , method = methods .GET ):
125
- headers .setdefault ('Client-ID' , CLIENT_ID )
127
+ _headers = deepcopy (headers )
128
+ _headers .setdefault ('Client-ID' , CLIENT_ID )
126
129
if use_token and OAUTH_TOKEN :
127
- headers .setdefault ('Authorization' , 'OAuth {access_token}' .format (access_token = OAUTH_TOKEN ))
128
- super (ApiQuery , self ).__init__ (_kraken_baseurl , headers , data , method )
130
+ _headers .setdefault ('Authorization' , 'OAuth {access_token}' .format (access_token = OAUTH_TOKEN ))
131
+ super (ApiQuery , self ).__init__ (_kraken_baseurl , _headers , data , method )
129
132
self .add_path (path )
130
133
131
134
132
135
class HelixApiQuery (HelixJsonQuery ):
133
136
def __init__ (self , path , headers = {}, data = {}, use_app_token = False , method = methods .GET ):
134
- headers .setdefault ('Client-ID' , CLIENT_ID )
137
+ _headers = deepcopy (headers )
138
+ _headers .setdefault ('Client-ID' , CLIENT_ID )
135
139
if use_app_token and APP_TOKEN :
136
- headers .setdefault ('Authorization' , 'Bearer {access_token}' .format (access_token = APP_TOKEN ))
140
+ _headers .setdefault ('Authorization' , 'Bearer {access_token}' .format (access_token = APP_TOKEN ))
137
141
elif OAUTH_TOKEN :
138
- headers .setdefault ('Authorization' , 'Bearer {access_token}' .format (access_token = OAUTH_TOKEN ))
139
- super (HelixApiQuery , self ).__init__ (_helix_baseurl , headers , data , method )
142
+ _headers .setdefault ('Authorization' , 'Bearer {access_token}' .format (access_token = OAUTH_TOKEN ))
143
+ super (HelixApiQuery , self ).__init__ (_helix_baseurl , _headers , data , method )
140
144
self ._params = list ()
141
145
self .add_path (path )
142
146
@@ -154,37 +158,54 @@ def add_param(self, key, value, default=None):
154
158
155
159
class HiddenApiQuery (JsonQuery ):
156
160
def __init__ (self , path , headers = {}, data = {}, use_token = True , method = methods .GET ):
157
- headers .setdefault ('Client-ID' , CLIENT_ID )
158
- if use_token and OAUTH_TOKEN :
159
- headers .setdefault ('Authorization' , 'OAuth {access_token}' .format (access_token = OAUTH_TOKEN ))
160
- super (HiddenApiQuery , self ).__init__ (_hidden_baseurl , headers , data , method )
161
+ _headers = deepcopy (headers )
162
+ if 'Client-ID' not in _headers :
163
+ _headers .setdefault ('Client-ID' , CLIENT_ID )
164
+ if 'Client-ID' in _headers and not _headers .get ('Client-ID' ):
165
+ del _headers ['Client-ID' ]
166
+ if 'Authorization' not in _headers :
167
+ if use_token and OAUTH_TOKEN :
168
+ _headers .setdefault ('Authorization' , 'OAuth {access_token}' .format (access_token = OAUTH_TOKEN ))
169
+ if 'Authorization' in _headers and not _headers .get ('Authorization' ):
170
+ del _headers ['Authorization' ]
171
+ super (HiddenApiQuery , self ).__init__ (_hidden_baseurl , _headers , data , method )
161
172
self .add_path (path )
162
173
163
174
164
175
class UsherQuery (DownloadQuery ):
165
176
def __init__ (self , path , headers = {}, data = {}, method = methods .GET ):
166
- headers .setdefault ('Client-ID' , CLIENT_ID )
167
- if OAUTH_TOKEN :
168
- headers .setdefault ('Authorization' , 'OAuth {access_token}' .format (access_token = OAUTH_TOKEN ))
169
- super (UsherQuery , self ).__init__ (_usher_baseurl , headers , data , method )
177
+ _headers = deepcopy (headers )
178
+ if 'Client-ID' not in _headers :
179
+ _headers .setdefault ('Client-ID' , CLIENT_ID )
180
+ if 'Client-ID' in _headers and not _headers .get ('Client-ID' ):
181
+ del _headers ['Client-ID' ]
182
+ if 'Authorization' not in _headers :
183
+ if OAUTH_TOKEN :
184
+ _headers .setdefault ('Authorization' , 'OAuth {access_token}' .format (access_token = OAUTH_TOKEN ))
185
+ if 'Authorization' in _headers and not _headers .get ('Authorization' ):
186
+ del _headers ['Authorization' ]
187
+ super (UsherQuery , self ).__init__ (_usher_baseurl , _headers , data , method )
170
188
self .add_path (path )
171
189
172
190
173
191
class OAuthQuery (JsonQuery ):
174
192
def __init__ (self , path , headers = {}, data = {}, method = methods .GET ):
175
- super (JsonQuery , self ).__init__ (_oauth_baseurl , headers , data , method )
193
+ _headers = deepcopy (headers )
194
+ super (JsonQuery , self ).__init__ (_oauth_baseurl , _headers , data , method )
176
195
self .add_path (path )
177
196
178
197
179
198
class ClipsQuery (DownloadQuery ):
180
199
def __init__ (self , path , headers = {}, data = {}, method = methods .GET ):
181
- super (ClipsQuery , self ).__init__ (_clips_baseurl , headers , data , method )
200
+ _headers = deepcopy (headers )
201
+ super (ClipsQuery , self ).__init__ (_clips_baseurl , _headers , data , method )
182
202
self .add_path (path )
183
203
184
204
185
205
class UploadsQuery (DownloadQuery ):
186
206
def __init__ (self , path , headers = {}, data = {}, method = methods .PUT ):
187
- super (UploadsQuery , self ).__init__ (_uploads_baseurl , headers , data , method )
207
+ _headers = deepcopy (headers )
208
+ super (UploadsQuery , self ).__init__ (_uploads_baseurl , _headers , data , method )
188
209
self .add_path (path )
189
210
190
211
0 commit comments