diff options
author | RaNaN <Mast3rRaNaN@hotmail.de> | 2011-01-30 16:20:37 +0100 |
---|---|---|
committer | RaNaN <Mast3rRaNaN@hotmail.de> | 2011-01-30 16:20:37 +0100 |
commit | f96a5a1cf8800edc2f6a6d73316f7d7c67f32e29 (patch) | |
tree | 3081be7874ac1594e1ab4b9c58f2de503acac0b5 | |
parent | fixed ssl xmlrpc backend (diff) | |
download | pyload-f96a5a1cf8800edc2f6a6d73316f7d7c67f32e29.tar.xz |
cleanup code
-rw-r--r-- | module/lib/BeautifulSoup.py | 2 | ||||
-rw-r--r-- | module/lib/feedparser.py | 6 | ||||
-rw-r--r-- | module/network/FtpRequest.py | 261 | ||||
-rwxr-xr-x | module/network/OldRequest.py | 435 | ||||
-rwxr-xr-x | module/network/Request.py | 187 | ||||
-rw-r--r-- | module/network/XDCCBase.py | 2 | ||||
-rw-r--r-- | module/network/XdccRequest.py | 245 | ||||
-rw-r--r-- | module/plugins/crypter/SecuredIn.py | 6 | ||||
-rw-r--r-- | module/plugins/hoster/Xdcc.py | 2 | ||||
-rw-r--r-- | module/plugins/hoster/YourfilesTo.py | 8 | ||||
-rw-r--r-- | module/web/media/default/js/status.js | 10 | ||||
-rw-r--r-- | module/web/pyload/views.py | 6 | ||||
-rw-r--r-- | module/web/templates/default/settings.html | 2 |
13 files changed, 22 insertions, 1150 deletions
diff --git a/module/lib/BeautifulSoup.py b/module/lib/BeautifulSoup.py index 748e6fe4b..55567f588 100644 --- a/module/lib/BeautifulSoup.py +++ b/module/lib/BeautifulSoup.py @@ -1295,7 +1295,7 @@ class BeautifulStoneSoup(Tag, SGMLParser): """ nestingResetTriggers = self.NESTABLE_TAGS.get(name) - isNestable = nestingResetTriggers != None + isNestable = nestingResetTriggers is not None isResetNesting = self.RESET_NESTING_TAGS.has_key(name) popTo = None inclusive = True diff --git a/module/lib/feedparser.py b/module/lib/feedparser.py index 1fd5cfc3e..a746ed8f5 100644 --- a/module/lib/feedparser.py +++ b/module/lib/feedparser.py @@ -1685,7 +1685,7 @@ class _FeedParserMixin: def _end_media_thumbnail(self): url = self.pop('url') context = self._getContext() - if url != None and len(url.strip()) != 0: + if url is not None and len(url.strip()) != 0: if not context['media_thumbnail'][-1].has_key('url'): context['media_thumbnail'][-1]['url'] = url @@ -1736,7 +1736,7 @@ if _XML_AVAILABLE: else: givenprefix = None prefix = self._matchnamespaces.get(lowernamespace, givenprefix) - if givenprefix and (prefix == None or (prefix == '' and lowernamespace == '')) and not self.namespacesInUse.has_key(givenprefix): + if givenprefix and (prefix is None or (prefix == '' and lowernamespace == '')) and not self.namespacesInUse.has_key(givenprefix): raise UndeclaredNamespace, "'%s' is not associated with a namespace" % givenprefix localname = str(localname).lower() @@ -2806,7 +2806,7 @@ class _FeedURLHandler(urllib2.HTTPDigestAuthHandler, urllib2.HTTPRedirectHandler host = urlparse.urlparse(req.get_full_url())[1] try: assert sys.version.split()[0] >= '2.3.3' - assert base64 != None + assert base64 is not None user, passw = _base64decode(req.headers['Authorization'].split(' ')[1]).split(':') realm = re.findall('realm="([^"]*)"', headers['WWW-Authenticate'])[0] self.add_password(realm, host, user, passw) diff --git a/module/network/FtpRequest.py b/module/network/FtpRequest.py deleted file mode 100644 index a0986a9ed..000000000 --- a/module/network/FtpRequest.py +++ /dev/null @@ -1,261 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -""" - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, see <http://www.gnu.org/licenses/>. - - @author: spoob - @author: RaNaN - @author: mkaay - @author: jeix - @version: v0.4.0 -""" - -import time -from os import rename -from os.path import exists -from cStringIO import StringIO -import pycurl - -from module.plugins.Plugin import Abort - -class FtpRequest: - def __init__(self, interface=None): - - self.dl_time = 0 - self.dl_finished = 0 - self.dl_size = 0 - self.dl_arrived = 0 - self.dl = False - - self.abort = False - - self.timeout = 5 - self.auth = False - - bufferBase = 1024 - bufferMulti = 4 - self.bufferSize = bufferBase*bufferMulti - self.canContinue = False - self.offset = 0 - - self.dl_speed = 0.0 - self.averageSpeed = 0.0 - self.averageSpeeds = [] - self.averageSpeedTime = 0.0 - self.averageSpeedCount = 0.0 - self.progressNotify = None - - self.speedLimitActive = False - self.maxSpeed = 0 - self.isSlow = False - self.interface = interface - - # change this for connection information - self.debug = False - - self.init_curl() - - def set_timeout(self, timeout): - self.timeout = int(timeout) - - def init_curl(self): - self.rep = StringIO() - self.header = "" - - self.pycurl = pycurl.Curl() - self.pycurl.setopt(pycurl.FOLLOWLOCATION, 1) - self.pycurl.setopt(pycurl.MAXREDIRS, 5) - self.pycurl.setopt(pycurl.TIMEOUT, (self.timeout*3600)) - self.pycurl.setopt(pycurl.CONNECTTIMEOUT, 30) - self.pycurl.setopt(pycurl.NOSIGNAL, 1) - self.pycurl.setopt(pycurl.NOPROGRESS, 0) - self.pycurl.setopt(pycurl.PROGRESSFUNCTION, self.progress) - self.pycurl.setopt(pycurl.AUTOREFERER, 1) - self.pycurl.setopt(pycurl.BUFFERSIZE, self.bufferSize) - self.pycurl.setopt(pycurl.SSL_VERIFYPEER, 0) - if self.debug: - self.pycurl.setopt(pycurl.VERBOSE, 1) - if self.interface: - self.pycurl.setopt(pycurl.INTERFACE, self.interface) - - - def add_auth(self, user, pw): - self.auth = True - self.pycurl.setopt(pycurl.USERNAME, user) - self.pycurl.setopt(pycurl.PASSWORD, pw) - - def add_proxy(self, protocol, adress): - # @TODO: pycurl proxy protocoll selection - self.pycurl.setopt(pycurl.PROXY, adress.split(":")[0]) - self.pycurl.setopt(pycurl.PROXYPORT, adress.split(":")[1]) - - def download(self, url, file_name): - file_temp = self.get_free_name(file_name) + ".part" - self.fp = open(file_temp, 'wb') - - self.init_curl() - self.pycurl.setopt(pycurl.URL, url) - - self.dl_arrived = self.offset - - if self.auth: - self.add_auth(self.user, self.pw) - - self.dl_time = time.time() - self.dl = True - - self.chunkSize = 0 - self.chunkRead = 0 - self.subStartTime = 0 - self.maxChunkSize = 0 - - def restLimit(): - subTime = time.time() - self.subStartTime - if subTime <= 1: - if self.speedLimitActive: - return self.maxChunkSize - else: - return -1 - else: - self.updateCurrentSpeed(float(self.chunkRead/1024) / subTime) - - self.subStartTime = time.time() - self.chunkRead = 0 - if self.maxSpeed > 0: - self.maxChunkSize = self.maxSpeed - else: - self.maxChunkSize = 0 - return 0 - - def writefunc(buf): - if self.abort: - return False - chunkSize = len(buf) - while chunkSize > restLimit() > -1: - time.sleep(0.05) - self.maxChunkSize -= chunkSize - self.fp.write(buf) - self.chunkRead += chunkSize - self.dl_arrived += chunkSize - - self.pycurl.setopt(pycurl.WRITEFUNCTION, writefunc) - - try: - self.pycurl.perform() - except Exception, e: - code, msg = e - if not code == 23: - raise Exception, e - - self.fp.close() - - if self.abort: - raise Abort - - free_name = self.get_free_name(file_name) - rename(file_temp, free_name) - - self.dl = False - self.dl_finished = time.time() - - return free_name - - def updateCurrentSpeed(self, speed): - self.dl_speed = speed - if self.averageSpeedTime + 10 < time.time(): - self.averageSpeeds = [] - self.averageSpeeds.append(self.averageSpeed) - self.averageSpeeds.append(speed) - self.averageSpeed = (speed + self.averageSpeed)/2 - self.averageSpeedTime = time.time() - self.averageSpeedCount = 2 - else: - self.averageSpeeds.append(speed) - self.averageSpeedCount += 1 - allspeed = 0.0 - for s in self.averageSpeeds: - allspeed += s - self.averageSpeed = allspeed / self.averageSpeedCount - - def write_header(self, string): - self.header += string - - def get_rep(self): - value = self.rep.getvalue() - self.rep.close() - self.rep = StringIO() - return value - - def get_header(self): - h = self.header - self.header = "" - return h - - def get_speed(self): - try: - return self.dl_speed - except: - return 0 - - def get_ETA(self): - try: - return (self.dl_size - self.dl_arrived) / (self.dl_arrived / (time.time() - self.dl_time)) - except: - return 0 - - def kB_left(self): - return (self.dl_size - self.dl_arrived) / 1024 - - def progress(self, dl_t, dl_d, up_t, up_d): - if self.abort: - return False - self.dl_arrived = int(dl_d)+self.offset - self.dl_size = int(dl_t)+self.offset - - if self.progressNotify: - try: - progress = int(float(self.dl_arrived)/self.dl_size*100) - self.progressNotify(progress) - except: - pass - - def get_free_name(self, file_name): - file_count = 0 - while exists(file_name): - file_count += 1 - if "." in file_name: - file_split = file_name.split(".") - temp_name = "%s-%i.%s" % (".".join(file_split[:-1]), file_count, file_split[-1]) - else: - temp_name = "%s-%i" % (file_name, file_count) - if not exists(temp_name): - file_name = temp_name - return file_name - - def __del__(self): - self.clean() - - def clean(self): - try: - self.pycurl.close() - except: - pass - - def clearCookies(self): - # workaround </3 - pass - -if __name__ == "__main__": - import doctest - doctest.testmod() diff --git a/module/network/OldRequest.py b/module/network/OldRequest.py deleted file mode 100755 index 5314f97ab..000000000 --- a/module/network/OldRequest.py +++ /dev/null @@ -1,435 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -""" - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, see <http://www.gnu.org/licenses/>. - - @author: spoob - @author: RaNaN - @author: mkaay -""" - -import base64 -import time -from os.path import exists, join -from shutil import move -import urllib -from cStringIO import StringIO -import pycurl - -from module.plugins.Plugin import Abort - -class Request: - def __init__(self, interface=None): - - self.dl_time = 0 - self.dl_finished = 0 - self.dl_size = 0 - self.dl_arrived = 0 - self.dl = False - - self.abort = False - - self.lastEffectiveURL = None - self.lastURL = None - self.auth = False - - self.timeout = 5 - - bufferBase = 1024 - bufferMulti = 4 - self.bufferSize = bufferBase*bufferMulti - self.canContinue = False - self.offset = 0 - - self.dl_speed = 0.0 - self.averageSpeed = 0.0 - self.averageSpeeds = [] - self.averageSpeedTime = 0.0 - self.averageSpeedCount = 0.0 - - self.speedLimitActive = False - self.maxSpeed = 0 - self.isSlow = False - self.cookieJar = None - self.interface = interface - self.progressNotify = None - - # change this for connection information - self.debug = False - - self.init_curl() - - def set_timeout(self, timeout): - self.timeout = int(timeout) - - def init_curl(self): - self.rep = StringIO() - self.header = "" - - self.pycurl = pycurl.Curl() - self.pycurl.setopt(pycurl.FOLLOWLOCATION, 1) - self.pycurl.setopt(pycurl.MAXREDIRS, 5) - self.pycurl.setopt(pycurl.TIMEOUT, (self.timeout*3600)) - self.pycurl.setopt(pycurl.CONNECTTIMEOUT, 30) - self.pycurl.setopt(pycurl.NOSIGNAL, 1) - self.pycurl.setopt(pycurl.NOPROGRESS, 0) - self.pycurl.setopt(pycurl.PROGRESSFUNCTION, self.progress) - if hasattr(pycurl, "AUTOREFERER"): - self.pycurl.setopt(pycurl.AUTOREFERER, 1) - self.pycurl.setopt(pycurl.HEADERFUNCTION, self.write_header) - #self.pycurl.setopt(pycurl.BUFFERSIZE, self.bufferSize) - self.pycurl.setopt(pycurl.SSL_VERIFYPEER, 0) - self.pycurl.setopt(pycurl.LOW_SPEED_TIME, 30) - self.pycurl.setopt(pycurl.LOW_SPEED_LIMIT, 20) - - if self.debug: - self.pycurl.setopt(pycurl.VERBOSE, 1) - if self.interface and self.interface.lower() != "none": - self.pycurl.setopt(pycurl.INTERFACE, self.interface) - - - self.pycurl.setopt(pycurl.USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en; rv:1.9.2.10) Gecko/20100916 Firefox/3.6.10") - if pycurl.version_info()[7]: - self.pycurl.setopt(pycurl.ENCODING, "gzip, deflate") - self.pycurl.setopt(pycurl.HTTPHEADER, ["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"]) - - def setCookieJar(self, j): - self.cookieJar = j - - def addCookies(self): - if self.cookieJar: - self.cookieJar.addCookies(self.pycurl.getinfo(pycurl.INFO_COOKIELIST)) - return - - def getCookies(self): - if self.cookieJar: - for c in self.cookieJar.getCookies(): - self.pycurl.setopt(pycurl.COOKIELIST, c) - return - - def getCookie(self, name): - if self.cookieJar: - return self.cookieJar.getCookie(name) - return None - - def load(self, url, get={}, post={}, ref=True, cookies=True, just_header=False, no_post_encode=False, raw_cookies={}): - - self.pycurl.setopt(pycurl.NOPROGRESS, 1) - - url = self.__myquote(str(url)) - - if post: - if not no_post_encode: - post = urllib.urlencode(post) - else: - post = None - - if get: - get = urllib.urlencode(get) - url = "%s?%s" % (url, get) - else: - get = "" - - self.pycurl.setopt(pycurl.URL, url) - self.pycurl.setopt(pycurl.WRITEFUNCTION, self.write_rep) - - if cookies: - self.curl_enable_cookies() - self.getCookies() - if raw_cookies: - self.pycurl.setopt(pycurl.COOKIELIST, "Set-Cookie: %s;"% "; ".join(["%s=%s"%(x,y) for x,y in raw_cookies.items()])) - - if post: - self.pycurl.setopt(pycurl.POSTFIELDS, post) - - if ref and self.lastURL is not None: - self.pycurl.setopt(pycurl.REFERER, self.lastURL) - - if just_header: - self.pycurl.setopt(pycurl.NOBODY, 1) - self.pycurl.perform() - self.lastEffectiveURL = self.pycurl.getinfo(pycurl.EFFECTIVE_URL) - self.pycurl.setopt(pycurl.NOPROGRESS, 0) - self.pycurl.setopt(pycurl.NOBODY, 0) - return self.header - - self.pycurl.perform() - - self.lastEffectiveURL = self.pycurl.getinfo(pycurl.EFFECTIVE_URL) - self.addCookies() - - #reset progress - - self.dl_time = 0 - self.dl_finished = 0 - self.dl_size = 0 - self.dl_arrived = 0 - - self.lastURL = url - header = self.get_header() - - return self.get_rep() - - def curl_enable_cookies(self): - self.pycurl.setopt(pycurl.COOKIEFILE, "") - self.pycurl.setopt(pycurl.COOKIEJAR, "") - - def add_auth(self, user, pw): - - self.auth = True - self.user = user - self.pw = pw - - upwstr = str("%s:%s" % (user,pw)) - self.pycurl.setopt(pycurl.HTTPHEADER, ['Authorization: Basic ' + base64.encodestring(upwstr)[:-1]]) - self.pycurl.setopt(pycurl.USERPWD, upwstr) - self.pycurl.setopt(pycurl.HTTPAUTH, pycurl.HTTPAUTH_ANY) - - def clearCookies(self): - self.pycurl.setopt(pycurl.COOKIELIST, "") - - def add_proxy(self, protocol, adress): - # @TODO: pycurl proxy protocol selection - self.pycurl.setopt(pycurl.PROXY, adress.split(":")[0]) - self.pycurl.setopt(pycurl.PROXYPORT, adress.split(":")[1]) - - def download(self, url, file_name, folder, get={}, post={}, ref=True, cookies=True, no_post_encode=False): - - url = self.__myquote(str(url)) - - self.pycurl.setopt(pycurl.NOPROGRESS, 0) - - if post: - if not no_post_encode: - post = urllib.urlencode(post) - else: - post = None - - if get: - get = urllib.urlencode(get) - url = "%s?%s" % (url, get) - else: - get = "" - - file_temp = self.get_free_name(folder,file_name) + ".part" - - self.fp = open(file_temp, 'wb' if not self.canContinue else 'ab') - - partSize = self.fp.tell() - - self.init_curl() - - self.pycurl.setopt(pycurl.URL, url) - - if self.canContinue: - self.offset = partSize - self.pycurl.setopt(pycurl.RESUME_FROM, self.offset) - - self.dl_arrived = self.offset - - if cookies: - self.curl_enable_cookies() - self.getCookies() - - if post: - self.pycurl.setopt(pycurl.POSTFIELDS, post) - - if self.auth: - self.add_auth(self.user, self.pw) - - if ref and self.lastURL is not None: - self.pycurl.setopt(pycurl.REFERER, self.lastURL) - - self.dl_time = time.time() - self.dl = True - - self.chunkSize = 0 - self.chunkRead = 0 - self.subStartTime = 0 - self.maxChunkSize = 0 - - def restLimit(): - subTime = time.time() - self.subStartTime - if subTime <= 1: - if self.speedLimitActive: - return self.maxChunkSize - else: - return -1 - else: - self.updateCurrentSpeed(float(self.chunkRead/1024) / subTime) - - self.subStartTime += subTime # time.time() - self.chunkRead = 0 - if self.maxSpeed > 0: - self.maxChunkSize = self.maxSpeed - else: - self.maxChunkSize = 0 - return 0 - - def writefunc(buf): - if self.abort: - return False - chunkSize = len(buf) - while chunkSize > restLimit() > -1: - time.sleep(0.05) - self.maxChunkSize -= chunkSize - self.fp.write(buf) - self.chunkRead += chunkSize - self.dl_arrived += chunkSize - - self.pycurl.setopt(pycurl.WRITEFUNCTION, writefunc) - #self.pycurl.setopt(pycurl.WRITEDATA, self.fp) - - try: - self.pycurl.perform() - except Exception, e: - code, msg = e - if not code == 23: - raise Exception, e - finally: - self.dl = False - self.dl_finished = time.time() - - self.addCookies() - self.fp.close() - - if self.abort: raise Abort - - free_name = self.get_free_name(folder, file_name) - move(file_temp, free_name) - - #@TODO content disposition - - return free_name - - def updateCurrentSpeed(self, speed): - self.dl_speed = speed - if self.averageSpeedTime + 10 < time.time(): - self.averageSpeeds = [] - self.averageSpeeds.append(self.averageSpeed) - self.averageSpeeds.append(speed) - self.averageSpeed = (speed + self.averageSpeed)/2 - self.averageSpeedTime = time.time() - self.averageSpeedCount = 2 - else: - self.averageSpeeds.append(speed) - self.averageSpeedCount += 1 - allspeed = 0.0 - for s in self.averageSpeeds: - allspeed += s - self.averageSpeed = allspeed / self.averageSpeedCount - - def write_header(self, string): - self.header += string - - def write_rep(self, buf): - if self.rep.tell() > 400000 or self.abort: - rep = self.get_rep() - if self.abort: raise Abort - f = open("response.dump", "wb") - f.write(rep) - f.close() - raise Exception("Loaded Url exceeded limit") - - self.rep.write(buf) - - def get_rep(self): - value = self.rep.getvalue() - self.rep.close() - self.rep = StringIO() - return value - - def get_header(self): - h = self.header - self.header = "" - return h - - def get_speed(self): - try: - return self.dl_speed - #return (self.dl_arrived / (time.time()- self.dl_time)) / 1024 - except: - return 0 - - def get_ETA(self): - try: - return (self.dl_size - self.dl_arrived) / (self.dl_arrived / (time.time() - self.dl_time)) - except: - return 0 - - def bytes_left(self): - return (self.dl_size - self.dl_arrived) - - def progress(self, dl_t, dl_d, up_t, up_d): - if self.abort: - return False - self.dl_arrived = int(dl_d)+self.offset - self.dl_size = int(dl_t)+self.offset - - if self.progressNotify: - try: - progress = int(float(self.dl_arrived)/self.dl_size*100) - self.progressNotify(progress) - except: - pass - - def get_free_name(self, folder, file_name): - file_count = 0 - file_name = join(folder, file_name) - while exists(file_name): - file_count += 1 - if "." in file_name: - file_split = file_name.split(".") - temp_name = "%s-%i.%s" % (".".join(file_split[:-1]), file_count, file_split[-1]) - else: - temp_name = "%s-%i" % (file_name, file_count) - if not exists(temp_name): - file_name = temp_name - return file_name - - def __del__(self): - self.clean() - if hasattr(self, "pycurl"): - del self.pycurl - if hasattr(self, "cookieJar"): - del self.cookieJar - - def clean(self): - """ clean Reqest, its unusable after this """ - try: - self.pycurl.close() - if hasattr(self, "cookieJar"): - del self.cookieJar - except: - pass - - def __myquote(self, url): - return urllib.quote(url, safe="%/:=&?~#+!$,;'@()*[]") - - -def getURL(url, get={}, post={}): - """ - currently used for update check - """ - req = Request() - c = req.load(url, get, post) - req.pycurl.close() - return c - -if __name__ == "__main__": - import doctest - doctest.testmod() diff --git a/module/network/Request.py b/module/network/Request.py deleted file mode 100755 index b0a8063ef..000000000 --- a/module/network/Request.py +++ /dev/null @@ -1,187 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -""" - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, see <http://www.gnu.org/licenses/>. - - @author: spoob - @author: RaNaN - @author: mkaay -""" - -import time -from os.path import exists, join -from shutil import move -import urllib - -from module.plugins.Plugin import Abort - -from module.network.Browser import Browser -from module.network.helper import waitFor - -class Request(object): - def __init__(self, interface=None): - self.browser = Browser(interface=interface) - self.d = None - - self.dl_time = 0 - self.dl_finished = 0 - self.dl_size = 0 - self.dl_arrived = 0 - self.dl = False - - self.abort = False - - self.lastEffectiveURL = self.lastURL = property(lambda: self.browser.lastUrl) - self.auth = False - - self.canContinue = False - - self.dl_speed = 0.0 - - self.cookieJar = None - self.interface = interface - self.progressNotify = None - - # change this for connection information - self.debug = False - - def set_timeout(self, timeout): - self.timeout = int(timeout) - - def setCookieJar(self, j): - #self.cookieJar = j - pass - - def addCookies(self): - #@TODO - pass - - def getCookies(self): - #@TODO - pass - - def getCookie(self, name): - #@TODO - pass - - def load(self, url, get={}, post={}, ref=True, cookies=True, just_header=False, no_post_encode=False, raw_cookies={}): - url = self.__myquote(str(url)) - - #@TODO: cookies - #@TODO: auth - - if not ref: - self.browser.clearReferer() - - return self.browser.getPage(url, get=get, post=post, cookies=cookies) - - def add_auth(self, user, pw): - #@TODO - pass - - def clearCookies(self): - #@TODO - pass - - def add_proxy(self, protocol, adress): - #@TODO - pass - - def download(self, url, file_name, folder, get={}, post={}, ref=True, cookies=True, no_post_encode=False): - url = self.__myquote(str(url)) - - file_temp = self.get_free_name(folder,file_name) - - #@TODO: cookies - #@TODO: auth - - if not ref: - self.browser.clearReferer() - - self.d = self.browser.httpDownload(url, file_temp, get=get, post=post, cookies=cookies, chunks=1, resume=self.canContinue) - - waitFor(self.d) - - if self.abort: raise Abort - - free_name = self.get_free_name(folder, file_name) - move(file_temp, free_name) - - self.dl_time = 0 - self.dl_finished = 0 - self.dl_size = 0 - self.dl_arrived = 0 - self.dl = False - self.dl_speed = 0.0 - - return free_name - - dl_time = property(lambda self: self.d.startTime) - dl_finished = property(lambda self: self.d.endTime) - dl_speed = property(lambda self: self.d.speed) - dl_size = property(lambda self: self.d.size) - dl = property(lambda self: True if self.d.startTime and not self.d.endTime else False) - abort = property(lambda self: self.d.getAbort, lambda self, value: self.d.setAbort(value)) - - def get_speed(self): - try: - return self.dl_speed - except: - return 0 - - def get_ETA(self): - try: - return (self.dl_size - self.dl_arrived) / (self.dl_arrived / (time.time() - self.dl_time)) - except: - return 0 - - def bytes_left(self): - return (self.dl_size - self.dl_arrived) - - def progress(self): - if self.progressNotify: - try: - progress = int(float(self.dl_arrived)/self.dl_size*100) - self.progressNotify(progress) - except: - pass - - def get_free_name(self, folder, file_name): - file_count = 0 - file_name = join(folder, file_name) - while exists(file_name): - file_count += 1 - if "." in file_name: - file_split = file_name.split(".") - temp_name = "%s-%i.%s" % (".".join(file_split[:-1]), file_count, file_split[-1]) - else: - temp_name = "%s-%i" % (file_name, file_count) - if not exists(temp_name): - file_name = temp_name - return file_name - - def __myquote(self, url): - return urllib.quote(url, safe="%/:=&?~#+!$,;'@()*[]") - - -def getURL(url, get={}, post={}): - """ - currently used for update check - """ - b = Browser() - return b.getPage(url, get=get, post=post) - -if __name__ == "__main__": - import doctest - doctest.testmod() diff --git a/module/network/XDCCBase.py b/module/network/XDCCBase.py index d36d6e897..1b9da1a23 100644 --- a/module/network/XDCCBase.py +++ b/module/network/XDCCBase.py @@ -247,7 +247,7 @@ class XDCCDownload(): raise XDCCError("Wrong channel") m = re.match('\x01DCC SEND (.*?) (\d+) (\d+)(?: (\d+))?\x01', msg["text"]) - if m != None: + if m is not None: done = True # get connection data diff --git a/module/network/XdccRequest.py b/module/network/XdccRequest.py deleted file mode 100644 index 18378cc6f..000000000 --- a/module/network/XdccRequest.py +++ /dev/null @@ -1,245 +0,0 @@ -#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-"""
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License,
- or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, see <http://www.gnu.org/licenses/>.
-
- @author: spoob
- @author: RaNaN
- @author: mkaay
- @author: jeix
- @version: v0.4.0
-"""
-
-import time
-import socket
-import re
-from os import rename
-from os.path import exists
-import struct
-
-from module.plugins.Plugin import Abort
-
-class IRCError(Exception):
- def __init__(self, value):
- self.value = value
- def __str__(self):
- return repr(self.value)
-
-class XDCCError(Exception):
- def __init__(self, value):
- self.value = value
- def __str__(self):
- return repr(self.value)
-
-class XdccRequest:
- def __init__(self):
-
- self.dl_time = 0
- self.dl_finished = 0
- self.dl_size = 0
- self.dl_arrived = 0
- self.dl = False
-
- self.abort = False
-
- self.timeout = 20
-
- bufferBase = 1024
- bufferMulti = 4
- self.bufferSize = bufferBase*bufferMulti
- self.canContinue = False
- self.offset = 0
-
- self.dl_speed = 0.0
- self.averageSpeed = 0.0
- self.averageSpeeds = []
- self.averageSpeedTime = 0.0
- self.averageSpeedCount = 0.0
-
- self.speedLimitActive = False
- self.maxSpeed = 0
- self.isSlow = False
- self.progressNotify = None
-
- # change this for connection information
- self.debug = False
-
- def set_timeout(self, timeout):
- self.timeout = int(timeout)
-
- def add_proxy(self, protocol, adress):
- # @TODO: pycurl proxy protocoll selection
- raise NotImplementedError
-
-
- def download(self, ip, port, location, name):
- self.dl_time = time.time()
- self.dl = True
-
- self.chunkSize = 0
- self.chunkRead = 0
- self.subStartTime = 0
- self.maxChunkSize = 0
-
- def restLimit():
- subTime = time.time() - self.subStartTime
- if subTime <= 1:
- if self.speedLimitActive:
- return self.maxChunkSize
- else:
- return -1
- else:
- self.updateCurrentSpeed(float(self.chunkRead/1024) / subTime)
-
- self.subStartTime = time.time()
- self.chunkRead = 0
- if self.maxSpeed > 0:
- self.maxChunkSize = self.maxSpeed
- else:
- self.maxChunkSize = 0
- return 0
-
- def writefunc(in_chunkSize):
- chunkSize = in_chunkSize
- while chunkSize > restLimit() > -1:
- time.sleep(0.05)
- self.maxChunkSize -= chunkSize
- self.chunkRead += chunkSize
- self.dl_arrived += chunkSize
-
-
- # connect to XDCC Bot
- dcc = socket.socket()
- dcc.connect((ip, port))
- dcc_packname = self.get_free_name(location + '\\' + name)
- dcc_fpointer = open(dcc_packname + ".part", "wb")
- dcc_total = 0
-
- # recv loop for dcc socket
- while True:
- if self.abort:
- dcc.close()
- dcc_fpointer.close()
- raise Abort
-
- # recv something
- recvbytes = dcc.recv(4096)
-
- # connection closed and everything received -> reset variables
- if len(recvbytes) == 0:
- dcc.close()
- dcc_fpointer.close()
- break
-
- # status updates, speedmanaging, etc.
- writefunc(len(recvbytes))
-
- # add response to file
- dcc_fpointer.write(recvbytes)
- dcc_total += len(recvbytes)
-
- # acknowledge data by sending number of recceived bytes
- dcc.send(struct.pack('!I', dcc_total))
- ########################
-
- free_name = self.get_free_name(dcc_packname)
- rename(dcc_packname + ".part", free_name)
-
- self.dl = False
- self.dl_finished = time.time()
-
- return free_name
-
- def updateCurrentSpeed(self, speed):
- self.dl_speed = speed
- if self.averageSpeedTime + 10 < time.time():
- self.averageSpeeds = []
- self.averageSpeeds.append(self.averageSpeed)
- self.averageSpeeds.append(speed)
- self.averageSpeed = (speed + self.averageSpeed)/2
- self.averageSpeedTime = time.time()
- self.averageSpeedCount = 2
- else:
- self.averageSpeeds.append(speed)
- self.averageSpeedCount += 1
- allspeed = 0.0
- for s in self.averageSpeeds:
- allspeed += s
- self.averageSpeed = allspeed / self.averageSpeedCount
-
- def write_header(self, string):
- self.header += string
-
- def get_rep(self):
- value = self.rep.getvalue()
- self.rep.close()
- self.rep = StringIO()
- return value
-
- def get_header(self):
- h = self.header
- self.header = ""
- return h
-
- def get_speed(self):
- try:
- return self.dl_speed
- except:
- return 0
-
- def get_ETA(self):
- try:
- return (self.dl_size - self.dl_arrived) / (self.dl_arrived / (time.time() - self.dl_time))
- except:
- return 0
-
- def kB_left(self):
- return (self.dl_size - self.dl_arrived) / 1024
-
- def progress(self, dl_t, dl_d, up_t, up_d):
- if self.abort:
- return False
- self.dl_arrived = int(dl_d)
- self.dl_size = int(dl_t)
-
- def get_free_name(self, file_name):
- file_count = 0
- while exists(file_name):
- file_count += 1
- if "." in file_name:
- file_split = file_name.split(".")
- temp_name = "%s-%i.%s" % (".".join(file_split[:-1]), file_count, file_split[-1])
- else:
- temp_name = "%s-%i" % (file_name, file_count)
- if not exists(temp_name):
- file_name = temp_name
- return file_name
-
- def __del__(self):
- self.clean()
-
- def clean(self):
- try:
- pass
- # self.pycurl.close()
- except:
- pass
-
- def clearCookies(self):
- # workaround </3
- pass
-
-if __name__ == "__main__":
- import doctest
- doctest.testmod()
diff --git a/module/plugins/crypter/SecuredIn.py b/module/plugins/crypter/SecuredIn.py index 0985d663b..e41896c5f 100644 --- a/module/plugins/crypter/SecuredIn.py +++ b/module/plugins/crypter/SecuredIn.py @@ -228,11 +228,11 @@ class SecuredIn(Crypter): yploemju = -1 for i in range(0, len(yoiumqpy)): yploamzu = ord(yoiumqpy[i]) - if ord('A') <= yploamzu and yploamzu <= ord('Z'): + if ord('A') <= yploamzu <= ord('Z'): xoliuzem = ord(yoiumqpy[i]) - 65 - elif ord('a') <= yploamzu and yploamzu <= ord('z'): + elif ord('a') <= yploamzu <= ord('z'): xoliuzem = ord(yoiumqpy[i]) - 97 + 26 - elif ord('0') <= yploamzu and yploamzu <= ord('9'): + elif ord('0') <= yploamzu <= ord('9'): xoliuzem = ord(yoiumqpy[i]) - 48 + 52 elif yploamzu == ord('+'): xoliuzem = 62 diff --git a/module/plugins/hoster/Xdcc.py b/module/plugins/hoster/Xdcc.py index fe194abe1..bc35cf6ea 100644 --- a/module/plugins/hoster/Xdcc.py +++ b/module/plugins/hoster/Xdcc.py @@ -189,7 +189,7 @@ class Xdcc(Hoster): self.fail("Wrong channel")
m = re.match('\x01DCC SEND (.*?) (\d+) (\d+)(?: (\d+))?\x01', msg["text"])
- if m != None:
+ if m is not None:
done = True
# get connection data
diff --git a/module/plugins/hoster/YourfilesTo.py b/module/plugins/hoster/YourfilesTo.py index 90c261d02..18f2d3edf 100644 --- a/module/plugins/hoster/YourfilesTo.py +++ b/module/plugins/hoster/YourfilesTo.py @@ -36,7 +36,7 @@ class YourfilesTo(Hoster): self.wait()
def get_waiting_time(self):
- if self.html == None:
+ if self.html is None:
self.download_html()
#var zzipitime = 15;
@@ -60,7 +60,7 @@ class YourfilesTo(Hoster): return url;
def get_file_name(self):
- if self.html == None:
+ if self.html is None:
self.download_html()
return re.search("<title>(.*)</title>", self.html).group(1)
@@ -68,10 +68,10 @@ class YourfilesTo(Hoster): def file_exists(self):
""" returns True or False
"""
- if self.html == None:
+ if self.html is None:
self.download_html()
- if re.search(r"HTTP Status 404", self.html) != None:
+ if re.search(r"HTTP Status 404", self.html) is not None:
return False
else:
return True
diff --git a/module/web/media/default/js/status.js b/module/web/media/default/js/status.js index 3923e80ca..d4ac97528 100644 --- a/module/web/media/default/js/status.js +++ b/module/web/media/default/js/status.js @@ -46,7 +46,7 @@ window.addEvent('domready', function(){ }).send('links='+document.id('linkarea').value+"&name="+document.id('pname').value) - }) + }); $$('.statusbutton').each(function(item){ @@ -56,7 +56,7 @@ window.addEvent('domready', function(){ this.tween('opacity',0.01) } ) - }) + }); fx_reveal = new Fx.Reveal($('addlinks')); //fx_reveal.dissolve() @@ -74,8 +74,8 @@ window.addEvent('domready', function(){ $$('.statusbutton')[2].addEvent('click',function(e){ - $('addlinks').setStyle('top', e.page.y + 5) - $('addlinks').setStyle('left', e.page.x + 5) + $('addlinks').setStyle('top', e.page.y + 5); + $('addlinks').setStyle('left', e.page.x + 5); fx_reveal.reveal() @@ -87,7 +87,7 @@ window.addEvent('domready', function(){ 'url' : '/json/play', 'method' : 'get' }).send() - }) + }); $$('.statusbutton')[1].addEvent('click', function(e){ diff --git a/module/web/pyload/views.py b/module/web/pyload/views.py index 76f991921..8e72402a4 100644 --- a/module/web/pyload/views.py +++ b/module/web/pyload/views.py @@ -265,10 +265,10 @@ def logs(request, item=-1): item = counter #found our datetime if item >= 0: data.append({'line': counter, 'date': date+" "+time, 'level':level, 'message': message}) - perpagecheck = perpagecheck +1 + perpagecheck += 1 if fro is None and dtime is not None: #if fro not set set it to first showed line fro = dtime - if perpagecheck >= perpage and perpage > 0: + if perpagecheck >= perpage > 0: break if fro is None: #still not set, empty log? @@ -295,7 +295,7 @@ def collector(request): def config(request): conf = settings.PYLOAD.get_config() plugin = settings.PYLOAD.get_plugin_config() - accs = settings.PYLOAD.get_accounts() + accs = settings.PYLOAD.get_accounts(False, False) messages = [] for section in chain(conf.itervalues(), plugin.itervalues()): diff --git a/module/web/templates/default/settings.html b/module/web/templates/default/settings.html index af87d632c..0ef9ce9f4 100644 --- a/module/web/templates/default/settings.html +++ b/module/web/templates/default/settings.html @@ -34,7 +34,7 @@ }); $$('#toptabs a')[0].set('class', 'selected'); - $$('#tabs span')[0].set('class', 'selected') + $$('#tabs span')[0].set('class', 'selected'); var firstsel = $$('#tabs span.selected a')[0]; firstsel.fireEvent('click', {target: firstsel}); |