1010 See LICENSES/GPL-3.0-only for more information.
1111"""
1212
13+ from copy import deepcopy
14+
1315from six .moves .urllib .parse import urljoin
1416
1517from . import CLIENT_ID , OAUTH_TOKEN , APP_TOKEN
@@ -122,21 +124,23 @@ def execute(self):
122124
123125class ApiQuery (JsonQuery ):
124126 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 )
126129 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 )
129132 self .add_path (path )
130133
131134
132135class HelixApiQuery (HelixJsonQuery ):
133136 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 )
135139 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 ))
137141 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 )
140144 self ._params = list ()
141145 self .add_path (path )
142146
@@ -154,37 +158,54 @@ def add_param(self, key, value, default=None):
154158
155159class HiddenApiQuery (JsonQuery ):
156160 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 )
161172 self .add_path (path )
162173
163174
164175class UsherQuery (DownloadQuery ):
165176 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 )
170188 self .add_path (path )
171189
172190
173191class OAuthQuery (JsonQuery ):
174192 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 )
176195 self .add_path (path )
177196
178197
179198class ClipsQuery (DownloadQuery ):
180199 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 )
182202 self .add_path (path )
183203
184204
185205class UploadsQuery (DownloadQuery ):
186206 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 )
188209 self .add_path (path )
189210
190211
0 commit comments