updated on Sun Jan 15 16:02:00 UTC 2012
[aur-mirror.git] / torrent-leecher / HttpClient.py
blob20d133dcfd5bd363dc4733ad73a0fe988dfb071a
1 #! /usr/bin/env python
2 # -*- coding: utf-8 -*-
4 #Librarys
5 ###################################################################################
6 from http.client import HTTPConnection, HTTPSConnection
8 #Classes
9 ###################################################################################
10 class HttpClient:
11 def __init__(self, Parent):
12 self.Parent = Parent
13 def open(self, data):
14 if data["scheme"] == "https":
15 conn = HTTPSConnection(data["netloc"], timeout=self.Parent.Configs.timeout)
16 else:
17 conn = HTTPConnection(data["netloc"], timeout=self.Parent.Configs.timeout)
18 try:
19 conn.request("GET", data["path"], "", data["headers"])
20 except:
21 return False
22 try:
23 response = conn.getresponse()
24 output = {"status":response.status, "reason":response.reason, "data":response.read(), "headers":response.getheaders()}
25 except:
26 output = False
27 conn.close()
28 return output