Package linspector :: Package lib :: Package services :: Module http
[hide private]
[frames] | no frames]

Source Code for Module linspector.lib.services.http

 1  """ 
 2  The http service. 
 3   
 4  This is for checking the availability and output of HTTP services. Basic HTTP 
 5  content could be fetched and compared.HTTPS is not validating the server certificate! 
 6   
 7  This should just return 0 on success and NOT 0 on error. Just to make internals generic 
 8  to just report this code and not use a parser. 
 9  """ 
10   
11  import urllib 
12  from service import Service 
13   
14   
15 -class HttpService(Service):
16 - def __init__(self, **kwargs):
17 super(HttpService, self).__init__(**kwargs) 18 19 args = self.get_arguments() 20 21 self.method = "get" 22 if "method" in args: 23 self.method = args["method"] 24 25 self.params = None 26 if "params" in args: 27 self.params = kwargs["params"] 28 29 self.path = "/" 30 if "path" in args: 31 self.path = kwargs["path"] 32 33 self.port = "80" 34 if "port" in args: 35 self.port = kwargs["port"] 36 37 self.protocol = "http" 38 if "protocol" in args: 39 self.protocol = kwargs["protocol"]
40
41 - def needs_arguments(self):
42 return True
43
44 - def execute(self):
45 params = urllib.urlencode(self.params) 46 if self.method is "get": 47 f = urllib.urlopen(self.protocol + "://" + self._host + ":" + self.port + self.path + "?%s" % params) 48 elif self.method is "post": 49 f = urllib.urlopen(self.protocol + "://" + self._host + ":" + self.port + self.path, params)
50 51 #print f.read() 52 53
54 -def create(**kwargs):
55 return HttpService(**kwargs)
56