99
1010from urllib3 import Retry
1111
12- from upwork import ca_certs_locater
1312from upwork .oauth import OAuth
1413from upwork .http import raise_http_error
1514from upwork .utils import decimal_default
1615from upwork .exceptions import IncorrectJsonResponseError
1716
18-
1917__all__ = ["Client" ]
2018
21-
2219logger = logging .getLogger ('python-upwork' )
2320
2421if os .environ .get ("PYTHON_UPWORK_DEBUG" , False ):
2522 if os .environ .get ("PYTHON_UPWORK_DEBUG_FILE" , False ):
2623 fh = logging .FileHandler (filename = os .environ ["PYTHON_UPWORK_DEBUG_FILE" ]
27- )
24+ )
2825 fh .setLevel (logging .DEBUG )
2926 logger .addHandler (fh )
3027 else :
@@ -92,13 +89,17 @@ class Client(object):
9289
9390 :timeout: (optional, default ``8 secs``)
9491 Socket operations timeout.
92+
93+ :poolmanager: (optional, default ``None``)
94+ http connection pool manager
95+ from :py:mod:`urllib3.poolmanager`
9596 """
9697
9798 def __init__ (self , public_key , secret_key ,
9899 oauth_access_token = None , oauth_access_token_secret = None ,
99100 fmt = 'json' , finreport = True , hr = True , messages = True ,
100101 offers = True , provider = True , task = True , team = True ,
101- timereport = True , job = True , timeout = 8 ):
102+ timereport = True , job = True , timeout = 8 , poolmanager = None ):
102103
103104 self .public_key = public_key
104105 self .secret_key = secret_key
@@ -114,17 +115,20 @@ def __init__(self, public_key, secret_key,
114115 # """
115116 # The warning will appear only in logs
116117 logging .captureWarnings (True )
117- self .http = urllib3 .PoolManager (
118- cert_reqs = 'CERT_REQUIRED' ,
119- ca_certs = ca_certs_locater .get (),
120- timeout = urllib3 .Timeout (connect = 0.5 , read = float (timeout )),
121- retries = False
122- )
118+ if poolmanager is None :
119+ from upwork import ca_certs_locater
120+ poolmanager = urllib3 .PoolManager (
121+ cert_reqs = 'CERT_REQUIRED' ,
122+ ca_certs = ca_certs_locater .get (),
123+ timeout = urllib3 .Timeout (connect = 0.5 , read = float (timeout )),
124+ retries = False
125+ )
126+ self .http = poolmanager
123127
124128 self .oauth_access_token = oauth_access_token
125129 self .oauth_access_token_secret = oauth_access_token_secret
126130
127- #Namespaces
131+ # Namespaces
128132 self .auth = OAuth (self )
129133
130134 if finreport :
@@ -168,7 +172,7 @@ def __init__(self, public_key, secret_key,
168172 from upwork .routers .job import Job
169173 self .job = Job (self )
170174
171- #Shortcuts for HTTP methods
175+ # Shortcuts for HTTP methods
172176 def get (self , url , data = None ):
173177 return self .read (url , data , method = 'GET' , fmt = self .fmt )
174178
@@ -231,7 +235,7 @@ def urlopen(self, url, data=None, method='GET', headers=None):
231235 return self .http .urlopen (
232236 method , url , body = post_data ,
233237 headers = {'Content-Type' :
234- 'application/x-www-form-urlencoded;charset=UTF-8' })
238+ 'application/x-www-form-urlencoded;charset=UTF-8' })
235239 elif method in ('PUT' , 'DELETE' ):
236240 url = '{0}?{1}' .format (url , post_data )
237241 headers ['Content-Type' ] = 'application/json'
@@ -307,4 +311,5 @@ def read(self, url, data=None, method='GET', fmt='json'):
307311
308312if __name__ == "__main__" :
309313 import doctest
314+
310315 doctest .testmod ()
0 commit comments