summaryrefslogtreecommitdiffstats
path: root/module/network
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2009-06-04 13:46:44 +0200
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2009-06-04 13:46:44 +0200
commit618c03fc5c5b57c154772b1fd373004e186ae0f8 (patch)
treefc6e14b69785a86e2b69d257685e182d23a434b3 /module/network
parentremoved test files (diff)
downloadpyload-618c03fc5c5b57c154772b1fd373004e186ae0f8.tar.xz
remove links from txt + several improvments
Diffstat (limited to 'module/network')
-rwxr-xr-xmodule/network/Request.py92
1 files changed, 46 insertions, 46 deletions
diff --git a/module/network/Request.py b/module/network/Request.py
index ce6dc6c8c..8725d0607 100755
--- a/module/network/Request.py
+++ b/module/network/Request.py
@@ -3,15 +3,15 @@
"""
authored by: RaNaN
"""
-import urllib
-import urllib2
-import cookielib
import base64
+import cookielib
import time
+import urllib
+import urllib2
+from gzip import GzipFile
from Keepalive import HTTPHandler
from cStringIO import StringIO
-from gzip import GzipFile
"""
handles all outgoing HTTP-Requests of the Server
@@ -31,64 +31,64 @@ class Request:
self.dl_arrived = 0
self.dl = False
- self.lastURL = None
- self.cj = cookielib.CookieJar()
+ self.lastURL = None
+ self.cj = cookielib.CookieJar()
handler = HTTPHandler()
- self.opener = urllib2.build_opener(handler, urllib2.HTTPCookieProcessor(self.cj))
- self.downloader = urllib2.build_opener()
- #self.opener.add_handler()
+ self.opener = urllib2.build_opener(handler, urllib2.HTTPCookieProcessor(self.cj))
+ self.downloader = urllib2.build_opener()
+ #self.opener.add_handler()
- self.opener.addheaders = [
- ("User-Agent","Mozilla/5.0 (Windows; U; Windows NT 5.1; en; rv:1.9.0.8) Gecko/2009032609 Firefox/3.0.10"),
- ("Accept-Encoding","gzip,deflate"),
- ("Accept","text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"),
- ("Accept-Charset","ISO-8859-1,utf-8;q=0.7,*;q=0.7"),
- ("Connection","keep-alive"),
- ("Keep-Alive","300")]
+ self.opener.addheaders = [
+ ("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 5.1; en; rv:1.9.0.8) Gecko/2009032609 Firefox/3.0.10"),
+ ("Accept-Encoding", "gzip,deflate"),
+ ("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"),
+ ("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7"),
+ ("Connection", "keep-alive"),
+ ("Keep-Alive", "300")]
- self.downloader.addheaders = [
- ("User-Agent","Mozilla/5.0 (Windows; U; Windows NT 5.1; en; rv:1.9.0.8) Gecko/2009032609 Firefox/3.0.10"),
- ("Accept-Encoding","gzip,deflate"),
- ("Accept","text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"),
- ("Accept-Charset","ISO-8859-1,utf-8;q=0.7,*;q=0.7")]
+ self.downloader.addheaders = [
+ ("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 5.1; en; rv:1.9.0.8) Gecko/2009032609 Firefox/3.0.10"),
+ ("Accept-Encoding", "gzip,deflate"),
+ ("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"),
+ ("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7")]
- def load(self, url, get = {}, post = {}, ref = True):
+ def load(self, url, get={}, post={}, ref=True):
- if post:
- post = urllib.urlencode(post)
- else:
- post = None
+ if post:
+ post = urllib.urlencode(post)
+ else:
+ post = None
- if get:
- get = urllib.urlencode(get)
- else:
- get = ""
+ if get:
+ get = urllib.urlencode(get)
+ else:
+ get = ""
- url = url + get
- req = urllib2.Request(url, data = post)
-
- if ref and self.lastURL is not None:
- req.add_header("Referer",self.lastURL)
+ url = url + get
+ req = urllib2.Request(url, data=post)
+
+ if ref and self.lastURL is not None:
+ req.add_header("Referer", self.lastURL)
- rep = self.opener.open(req)
+ rep = self.opener.open(req)
- output = rep.read()
+ output = rep.read()
- if rep.headers.has_key("content-encoding") :
- if rep.headers["content-encoding"] == "gzip" :
- output = GzipFile('','r',0,StringIO(output)).read()
+ if rep.headers.has_key("content-encoding"):
+ if rep.headers["content-encoding"] == "gzip":
+ output = GzipFile('', 'r', 0, StringIO(output)).read()
- self.lastURL = url
+ self.lastURL = url
- return output
+ return output
def add_auth(self, user, pw):
- self.downloader.addheaders.append(['Authorization','Basic ' + base64.encodestring(user + ':' + pw)[:-1]])
+ self.downloader.addheaders.append(['Authorization', 'Basic ' + base64.encodestring(user + ':' + pw)[:-1]])
#def download(url, filename, reporthook = None, data = None): #default von urlretrieve auch None?
- # return self.downloader.urlretrieve(url, filename, reporthook, data)
+ # return self.downloader.urlretrieve(url, filename, reporthook, data)
def download(self, url, filename, post={}):
@@ -115,7 +115,7 @@ class Request:
def get_speed(self):
try:
- return (self.dl_arrived / ((time.time() if self.dl else self.dl_finished) - self.dl_time )) / 1024
+ return (self.dl_arrived / ((time.time() if self.dl else self.dl_finished) - self.dl_time)) / 1024
except:
return 0
@@ -128,6 +128,6 @@ class Request:
def kB_left(self):
return (self.dl_size - self.dl_arrived) / 1024
-if __name__ == "__main__" :
+if __name__ == "__main__":
import doctest
doctest.testmod()