55class  Client (object ):
66
77    def  __init__ (self , url ):
8+         """ 
9+         Initialises a new Client object 
10+         :Args: 
11+          - url: This is where the BrowserMob Proxy lives 
12+         """ 
813        self .host  =  url  
914        h  =  Http ()
1015        resp , content  =  h .request ('%s/proxy'  %  self .host , 'POST' , urlencode ('' ))
@@ -14,11 +19,21 @@ def __init__(self, url):
1419        self .proxy  =  url_parts [0 ] +  ":"  +  url_parts [1 ] +  ":"  +   str (self .port )
1520
1621    def  new_har (self , ref = None ):
22+         """ 
23+         This sets a new HAR to be recorded 
24+         :Args: 
25+          - ref: A reference for the HAR. Defaults to None 
26+         """ 
1727        h  =  Http ()
1828        resp , content  =  h .request ('%s/proxy/%s/har'  %  (self .host , self .port ), 
1929                                    'PUT' , ref  or  '' )
2030
2131    def  new_page (self , ref ):
32+         """ 
33+         This sets a new page to be recorded 
34+         :Args: 
35+          - ref: A reference for the new page. Defaults to None 
36+         """ 
2237        h  =  Http ()
2338        resp , content  =  h .request ('%s/proxy/%s/har/pageRef'  %  (self .host , self .port ), 
2439                                    'PUT' , ref  or  '' )
@@ -27,23 +42,44 @@ def new_page(self, ref):
2742
2843    @property  
2944    def  har (self ):
45+         """ 
46+         Gets the HAR that has been recorded 
47+         """ 
3048        h  =  Http ()
3149        resp , content  =  h .request ('%s/proxy/%s/har'  %  (self .host , self .port ), 
3250                                    'GET' )
3351        return  json .loads (content )
3452
3553    def  selenium_proxy (self ):
54+         """ 
55+         Returns a Selenium WebDriver Proxy class with details of the HTTP Proxy 
56+         """ 
3657        from  selenium  import  webdriver 
3758        return  webdriver .Proxy ({"httpProxy" :self .proxy })
3859
3960    def  whitelist (self , regexp , status_code ):
61+         """ 
62+         Sets a list of URL patterns to whitelist 
63+         :Args: 
64+          - regex: a comma separated list of regular expressions 
65+          - status_code: the HTTP status code to return for URLs that do not match the whitelist  
66+ 
67+         """ 
4068        h  =  Http ()
4169        resp , content  =  h .request ('%s/proxy/%s/whitelist'  %  (self .host , self .port ), 
4270                                    'PUT' , urlencode ({ 'regex' : regexp , 'status' : status_code 
4371                                    }))
4472
4573
4674    def  blacklist (self , regexp , status_code ):
75+         """ 
76+         Sets a list of URL patterns to blacklist  
77+         :Args: 
78+          - regex: a comma separated list of regular expressions 
79+          - status_code: the HTTP status code to return for URLs that do not match the blacklist  
80+ 
81+         """ 
82+ 
4783        h  =  Http ()
4884        resp , content  =  h .request ('%s/proxy/%s/blacklist'  %  (self .host , self .port ), 
4985                                    'PUT' , urlencode ({ 'regex' : regexp , 'status' : status_code 
@@ -57,6 +93,14 @@ def blacklist(self, regexp, status_code):
5793
5894
5995    def  limits (self , options ):
96+         """ 
97+         Limit the bandwidth through the proxy. 
98+         :Args: 
99+          - options: A dictionary with all the details you want to set. 
100+                         downstreamKbps - Sets the downstream kbps 
101+                         upstreamKbps - Sets the upstream kbps 
102+                         latency - Add the given latency to each HTTP request 
103+         """ 
60104        params  =  {}
61105
62106        for  (k , v ) in  options .items ():
@@ -73,6 +117,9 @@ def limits(self, options):
73117                                    'PUT' , urlencode (params ))
74118
75119    def  close (self ):
120+         """ 
121+         shuts down the proxy and closes the port 
122+         """ 
76123        h  =  Http ()
77124        resp , content  =  h .request ('%s/proxy/%s'  %  (self .host , self .port ), 
78125                                    'DELETE'  )
0 commit comments