@@ -178,14 +178,20 @@ class Client:
178
178
testing purposes.
179
179
:param trust_env: Get proxies information from HTTP_PROXY/HTTPS_PROXY
180
180
environment variables if the parameter is True (False by default).
181
+ :param timeout: A int that determines the number of seconds to wait for
182
+ a request to timeout (300 by default).
183
+ :param proxy: A string indicating the proxy to use for requests
184
+ made by the client (None by default).
181
185
:type apikey: str
182
186
:type agent: str
183
187
:type host: str
184
188
:type trust_env: bool
189
+ :type timeout: int
190
+ :type proxy: str
185
191
"""
186
192
187
193
def __init__ (self , apikey , agent = "unknown" , host = None , trust_env = False ,
188
- timeout = 300 ):
194
+ timeout = 300 , proxy = None ):
189
195
"""Initialize the client with the provided API key."""
190
196
191
197
if not isinstance (apikey , str ):
@@ -200,6 +206,7 @@ def __init__(self, apikey, agent="unknown", host=None, trust_env=False,
200
206
self ._session = None
201
207
self ._trust_env = trust_env
202
208
self ._timeout = timeout
209
+ self ._proxy = proxy
203
210
204
211
def _full_url (self , path , * args ):
205
212
try :
@@ -281,7 +288,8 @@ def delete(self, path, *path_args):
281
288
async def delete_async (self , path , * path_args ):
282
289
"""Like :func:`delete` but returns a coroutine."""
283
290
return ClientResponse (
284
- await self ._get_session ().delete (self ._full_url (path , * path_args )))
291
+ await self ._get_session ().delete (
292
+ self ._full_url (path , * path_args ), proxy = self ._proxy ))
285
293
286
294
def download_file (self , hash , file ):
287
295
"""Downloads a file given its hash (SHA-256, SHA-1 or MD5).
@@ -347,7 +355,7 @@ async def get_async(self, path, *path_args, params=None):
347
355
return ClientResponse (
348
356
await self ._get_session ().get (
349
357
self ._full_url (path , * path_args ),
350
- params = params ))
358
+ params = params , proxy = self . _proxy ))
351
359
352
360
def get_data (self , path , * path_args , params = None ):
353
361
"""Sends a GET request to a given API endpoint and returns response's data.
@@ -467,7 +475,7 @@ async def patch_async(self, path, *path_args, data=None):
467
475
return ClientResponse (
468
476
await self ._get_session ().patch (
469
477
self ._full_url (path , * path_args ),
470
- data = data ))
478
+ data = data , proxy = self . _proxy ))
471
479
472
480
def patch_object (self , path , * path_args , obj ):
473
481
"""Sends a PATCH request for modifying an object.
@@ -514,7 +522,7 @@ async def post_async(self, path, *path_args, data=None):
514
522
return ClientResponse (
515
523
await self ._get_session ().post (
516
524
self ._full_url (path , * path_args ),
517
- data = data ))
525
+ data = data , proxy = self . _proxy ))
518
526
519
527
def post_object (self , path , * path_args , obj ):
520
528
"""Sends a POST request for creating an object.
@@ -610,7 +618,8 @@ async def scan_file_async(self, file, wait_for_completion=False):
610
618
611
619
upload_url = await self .get_data_async ('/files/upload_url' )
612
620
response = ClientResponse (
613
- await self ._get_session ().post (upload_url , data = form_data ))
621
+ await self ._get_session ().post (
622
+ upload_url , data = form_data , proxy = self ._proxy ))
614
623
615
624
analysis = await self ._response_to_object (response )
616
625
@@ -638,7 +647,8 @@ async def scan_url_async(self, url, wait_for_completion=False):
638
647
form_data .add_field ('url' , url )
639
648
640
649
response = ClientResponse (
641
- await self ._get_session ().post (self ._full_url ('/urls' ), data = form_data ))
650
+ await self ._get_session ().post (
651
+ self ._full_url ('/urls' ), data = form_data , proxy = self ._proxy ))
642
652
643
653
analysis = await self ._response_to_object (response )
644
654
0 commit comments