22from  urllib  import  urlencode 
33import  json 
44
5+ 
56class  Client (object ):
67    def  __init__ (self , url ):
78        """ 
89        Initialises a new Client object 
910
10-         url: str  
11-               This is where the BrowserMob Proxy lives 
11+         :Args:  
12+         :param url:  This is where the BrowserMob Proxy lives 
1213        """ 
1314        self .host  =  "http://"  +  url 
1415        resp  =  requests .post ('%s/proxy'  %  self .host , urlencode ('' ))
@@ -47,6 +48,9 @@ def add_to_capabilities(self, capabilities):
4748        """ 
4849        Adds an 'proxy' entry to a desired capabilities dictionary with the 
4950        BrowserMob proxy information 
51+ 
52+         :Args: 
53+         :param capabilities: The Desired capabilities object from Selenium WebDriver 
5054        """ 
5155        capabilities ['proxy' ] =  {'proxyType' : "MANUAL" ,
5256                                 'httpProxy' : self .proxy }
@@ -68,10 +72,9 @@ def new_har(self, ref=None, options={}):
6872        """ 
6973        This sets a new HAR to be recorded 
7074
71-         - ref: unicode 
72-                A reference for the HAR. Defaults to None 
73-         - options: dict 
74-                    A dictionary that will be passed to BrowserMob Proxy \  
75+         :Args: 
76+         :param ref: A reference for the HAR. Defaults to None 
77+         :param options: A dictionary that will be passed to BrowserMob Proxy \  
7578                    with specific keywords. Keywords are: \ 
7679                    captureHeaders - Boolean, capture headers \ 
7780                    captureContent - Boolean, capture content bodies \ 
@@ -94,8 +97,8 @@ def new_page(self, ref=None):
9497        """ 
9598        This sets a new page to be recorded 
9699
97-         - ref: unicode  
98-                 A reference for the new page. Defaults to None 
100+         :Args:  
101+         :param ref:  A reference for the new page. Defaults to None 
99102        """ 
100103        if  ref :
101104            payload  =  {"pageRef" : ref }
@@ -109,10 +112,9 @@ def blacklist(self, regexp, status_code):
109112        """ 
110113        Sets a list of URL patterns to blacklist 
111114
112-         - regex: unicode 
113-                  a comma separated list of regular expressions 
114-         - status_code: unicode 
115-                        the HTTP status code to return for URLs that do not \  
115+         :Args: 
116+         :param regex: a comma separated list of regular expressions 
117+         :param status_code: the HTTP status code to return for URLs that do not \  
116118                        match the blacklist
117119
118120        """ 
@@ -124,10 +126,9 @@ def whitelist(self, regexp, status_code):
124126        """ 
125127        Sets a list of URL patterns to whitelist 
126128
127-         - regex: unicode 
128-                  a comma separated list of regular expressions 
129-         - status_code: unicode 
130-                        the HTTP status code to return for URLs that do not \  
129+         :Args: 
130+         :param regex: a comma separated list of regular expressions 
131+         :param status_code: the HTTP status code to return for URLs that do not \  
131132                        match the whitelist
132133        """ 
133134        r  =  requests .put ('%s/proxy/%s/whitelist'  %  (self .host , self .port ),
@@ -138,12 +139,10 @@ def basic_authentication(self, domain, username, password):
138139        """ 
139140        This add automatic basic authentication 
140141
141-         - domain: unicode 
142-                   domain to set authentication credentials for 
143-         - username: unicode 
144-                     valid username to use when authenticating 
145-         - password: unicode 
146-                     valid password to use when authenticating 
142+         :Args: 
143+         :param domain: domain to set authentication credentials for 
144+         :param username: valid username to use when authenticating 
145+         :param  password: valid password to use when authenticating 
147146        """ 
148147        r  =  requests .post (url = '%s/proxy/%s/auth/basic/%s'  %  (self .host , self .port , domain ),
149148                          data = json .dumps ({'username' : username , 'password' : password }),
@@ -154,8 +153,8 @@ def headers(self, headers):
154153        """ 
155154        This sets the headers that will set by the proxy on all requests 
156155
157-         - headers: dict  
158-                     this is a dictionary of the headers to be set 
156+         :Args:  
157+         :param headers:  this is a dictionary of the headers to be set 
159158        """ 
160159        if  not  isinstance (headers , dict ):
161160            raise  TypeError ("headers needs to be dictionary" )
@@ -169,8 +168,8 @@ def response_interceptor(self, js):
169168        """ 
170169        Executes the javascript against each response 
171170
172-         - js: unicode  
173-                the javascript to execute 
171+         :Args:  
172+         :param js:  the javascript to execute 
174173        """ 
175174        r  =  requests .post (url = '%s/proxy/%s/interceptor/response'  %  (self .host , self .port ),
176175                  data = js ,
@@ -181,8 +180,8 @@ def request_interceptor(self, js):
181180        """ 
182181        Executes the javascript against each request 
183182
184-         - js: unicode  
185-                the javascript to execute 
183+         :Args:  
184+         :param js:  the javascript to execute 
186185        """ 
187186        r  =  requests .post (url = '%s/proxy/%s/interceptor/request'  %  (self .host , self .port ),
188187                  data = js ,
@@ -199,8 +198,8 @@ def limits(self, options):
199198        """ 
200199        Limit the bandwidth through the proxy. 
201200
202-         - options: dict  
203-                     A dictionary with all the details you want to set. \  
201+         :Args:  
202+         :param options:  A dictionary with all the details you want to set. \  
204203                         downstreamKbps - Sets the downstream kbps \ 
205204                         upstreamKbps - Sets the upstream kbps \ 
206205                         latency - Add the given latency to each HTTP request
@@ -231,8 +230,8 @@ def timeouts(self, options):
231230        """ 
232231        Configure various timeouts in the proxy 
233232
234-         - options: dict  
235-                     A dictionary with all the details you want to set. \  
233+         :Args:  
234+         :param options:  A dictionary with all the details you want to set. \  
236235                         request - request timeout (in seconds) \ 
237236                         read - read timeout (in seconds) \ 
238237                         connection - connection timeout (in seconds) \ 
@@ -257,10 +256,9 @@ def remap_hosts(self, address, ip_address):
257256        """ 
258257        Remap the hosts for a specific URL 
259258
260-         - address: unicode 
261-                    url that you wish to remap 
262-         - ip_address: unicode 
263-                       IP Address that will handle all traffic for the address passed in 
259+         :Args: 
260+         :param address: url that you wish to remap 
261+         :param ip_address: IP Address that will handle all traffic for the address passed in 
264262        """ 
265263        assert  address  is  not   None  and  ip_address  is  not   None 
266264        r  =  requests .post ('%s/proxy/%s/hosts'  %  (self .host , self .port ),
@@ -271,11 +269,10 @@ def remap_hosts(self, address, ip_address):
271269    def  wait_for_traffic_to_stop (self , quiet_period , timeout ):
272270        """ 
273271        Waits for the network to be quiet 
274-          
275-         - quiet_period: int 
276-                         number of seconds the network needs to be quiet for 
277-         - timeout: int 
278-                    max number of seconds to wait 
272+ 
273+         :Args: 
274+         :param quiet_period: number of seconds the network needs to be quiet for 
275+         :param timeout: max number of seconds to wait 
279276        """ 
280277        r  =  requests .put ('%s/proxy/%s/wait'  %  (self .host , self .port ),
281278                 {'quietPeriodInMs' : quiet_period , 'timeoutInMs' : timeout })
@@ -292,9 +289,9 @@ def rewrite_url(self, match, replace):
292289        """ 
293290        Rewrites the requested url. 
294291
295-         - match: unicode  
296-                   a regex to match requests with 
297-         -  replace: unicode 
292+         :Args:  
293+         :param match:  a regex to match requests with 
294+         :param  replace: unicode  \  
298295                    a string to replace the matches with
299296        """ 
300297        params  =  {
@@ -309,8 +306,8 @@ def retry(self, retry_count):
309306        """ 
310307        Retries. No idea what its used for, but its in the API... 
311308
312-         - retry_count: int  
313-                         the number of retries 
309+         :Args:  
310+         :param retry_count:  the number of retries 
314311        """ 
315312        r  =  requests .put ('%s/proxy/%s/retry'  %  (self .host , self .port ),
316313                 {'retrycount' : retry_count })
0 commit comments