summaryrefslogtreecommitdiffstats
path: root/module/network/Browser.py
diff options
context:
space:
mode:
authorGravatar mkaay <mkaay@mkaay.de> 2010-12-19 14:12:03 +0100
committerGravatar mkaay <mkaay@mkaay.de> 2010-12-19 14:12:03 +0100
commit5120d1a26cac79ab283f38db8d7f18c9c010e786 (patch)
tree219f8874869ac6f9c1656fea9df8db17b55ce034 /module/network/Browser.py
parentacc manager fix (diff)
downloadpyload-5120d1a26cac79ab283f38db8d7f18c9c010e786.tar.xz
new experimental backend, new gui status (unfinished)
Diffstat (limited to 'module/network/Browser.py')
-rw-r--r--module/network/Browser.py80
1 files changed, 80 insertions, 0 deletions
diff --git a/module/network/Browser.py b/module/network/Browser.py
new file mode 100644
index 000000000..65aefbae8
--- /dev/null
+++ b/module/network/Browser.py
@@ -0,0 +1,80 @@
+from HTTPBase import HTTPBase
+from HTTPDownload import HTTPDownload
+
+from os.path import exists
+
+import zlib
+from cookielib import CookieJar
+from FTPBase import FTPDownload
+
+class Browser():
+ def __init__(self, interface=None, cookieJar=CookieJar(), bucket=None, proxies={}):
+ self.lastURL = None
+ self.interface = interface
+ self.cookieJar = cookieJar
+ self.bucket = bucket
+
+ self.http = HTTPBase(interface=interface, proxies=proxies)
+ self.http.cookieJar = cookieJar
+ self.proxies = proxies
+
+ def clearReferer(self):
+ self.lastURL = None
+
+ def getPage(self, url, get={}, post={}, referer=None, cookies=True, customHeaders={}):
+ if not referer:
+ referer = self.lastURL
+ self.http.followRedirect = True
+ resp = self.http.getResponse(url, get=get, post=post, referer=referer, cookies=cookies, customHeaders=customHeaders)
+ data = resp.read()
+ try:
+ if resp.info()["Content-Encoding"] == "gzip":
+ data = zlib.decompress(data, 16+zlib.MAX_WBITS)
+ elif resp.info()["Content-Encoding"] == "deflate":
+ data = zlib.decompress(data, -zlib.MAX_WBITS)
+ except:
+ pass
+ self.lastURL = resp.geturl()
+ return data
+
+ def getRedirectLocation(self, url, get={}, post={}, referer=None, cookies=True, customHeaders={}):
+ if not referer:
+ referer = self.lastURL
+ self.http.followRedirect = False
+ resp = self.http.getResponse(url, get=get, post=post, referer=referer, cookies=cookies, customHeaders=customHeaders)
+ resp.close()
+ self.lastURL = resp.geturl()
+ location = None
+ try:
+ location = resp.info()["Location"]
+ except:
+ pass
+ return location
+
+ def httpDownload(self, url, filename, get={}, post={}, referer=None, cookies=True, customHeaders={}, chunks=1, resume=False):
+ if not referer:
+ referer = self.lastURL
+
+ dwnld = HTTPDownload(url, filename, get=get, post=post, referer=referer, cookies=cookies, customHeaders=customHeaders, bucket=self.bucket, interface=self.interface, proxies=self.proxies)
+ dwnld.cookieJar = self.cookieJar
+
+ d = dwnld.download(chunks=chunks, resume=resume)
+ return d
+
+ def ftpDownload(self, url, filename, resume=False):
+ dwnld = FTPDownload(url, filename, bucket=self.bucket, interface=self.interface, proxies=self.proxies)
+
+ d = dwnld.download(resume=resume)
+ return d
+
+if __name__ == "__main__":
+ browser = Browser(proxies={"socks5": "localhost:5000"})
+ ip = "http://www.whatismyip.com/automation/n09230945.asp"
+ #browser.getPage("http://google.com/search?q=bar")
+ #browser.getPage("https://encrypted.google.com/")
+ print browser.getPage(ip)
+ #print browser.getRedirectLocation("http://google.com/")
+ #browser.getPage("https://encrypted.google.com/")
+ #browser.getPage("http://google.com/search?q=bar")
+
+ #browser.downloadFile("https://bitbucket.org/spoob/pyload/downloads/Logo_neu.png", "logo.png")