diff options
Diffstat (limited to 'pyload')
| -rw-r--r-- | pyload/config/Parser.py | 19 | ||||
| -rw-r--r-- | pyload/manager/CaptchaManager.py | 10 | ||||
| -rw-r--r-- | pyload/network/HTTPRequest.py | 10 | ||||
| -rw-r--r-- | pyload/plugins/Plugin.py | 18 | ||||
| -rw-r--r-- | pyload/plugins/internal/Crypter.py | 4 | ||||
| -rw-r--r-- | pyload/utils/JsEngine.py | 8 | ||||
| -rw-r--r-- | pyload/utils/__init__.py | 5 | 
7 files changed, 29 insertions, 45 deletions
| diff --git a/pyload/config/Parser.py b/pyload/config/Parser.py index 7a1709400..33f048150 100644 --- a/pyload/config/Parser.py +++ b/pyload/config/Parser.py @@ -6,7 +6,7 @@ from os.path import exists, join  from shutil import copy  from traceback import print_exc -from utils import chmod +from utils import chmod, encode, decode  CONF_VERSION = 1 @@ -227,7 +227,7 @@ class ConfigParser:                      try:                          f.write('\t%s %s : "%s" = %s' % (data["type"], option, data["desc"], value))                      except UnicodeEncodeError: -                        f.write('\t%s %s : "%s" = %s' % (data["type"], option, data["desc"], value.encode("utf8"))) +                        f.write('\t%s %s : "%s" = %s' % (data["type"], option, data["desc"], encode(value))      def cast(self, typ, value):          """cast value to given format""" @@ -243,10 +243,7 @@ class ConfigParser:              if not ":" in value: value += ":00"              return value          elif typ in ("str", "file", "folder"): -            try: -                return value.encode("utf8") -            except: -                return value +            return encode(value)          else:              return value @@ -266,10 +263,7 @@ class ConfigParser:      def get(self, section, option):          """get value"""          value = self.config[section][option]["value"] -        try: -            value = value.decode("utf-8") -        finally: -            return value +        return decode(value)      def set(self, section, option, value):          """set value""" @@ -282,10 +276,7 @@ class ConfigParser:      def getPlugin(self, plugin, option):          """gets a value for a plugin"""          value = self.plugin[plugin][option]["value"] -        try: -            value = value.decode("utf-8") -        finally: -            return str(value) +        return encode(value)      def setPlugin(self, plugin, option, value):          """sets a value for a plugin""" diff --git a/pyload/manager/CaptchaManager.py b/pyload/manager/CaptchaManager.py index 9a5a63219..b89fb3136 100644 --- a/pyload/manager/CaptchaManager.py +++ b/pyload/manager/CaptchaManager.py @@ -21,6 +21,9 @@ from time import time  from traceback import print_exc  from threading import Lock +from pyload.utils import encode + +  class CaptchaManager:      def __init__(self, core):          self.lock = Lock() @@ -109,12 +112,7 @@ class CaptchaTask:                  self.result = None      def getResult(self): -        try: -            res = self.result.encode("utf8", "replace") -        except: -            res = self.result - -        return res +        return encode(self.result)      def getStatus(self):          return self.status diff --git a/pyload/network/HTTPRequest.py b/pyload/network/HTTPRequest.py index c1727c0c5..25f5732b5 100644 --- a/pyload/network/HTTPRequest.py +++ b/pyload/network/HTTPRequest.py @@ -26,13 +26,15 @@ from cStringIO import StringIO  from pyload.plugins.Plugin import Abort, Fail +from pyload.utils import encode + +  def myquote(url): -    return quote(url.encode('utf_8') if isinstance(url, unicode) else url, safe="%/:=&?~#+!$,;'@()*[]") +    return quote(encode(url), safe="%/:=&?~#+!$,;'@()*[]")  def myurlencode(data):      data = dict(data) -    return urlencode(dict((x.encode('utf_8') if isinstance(x, unicode) else x, \ -        y.encode('utf_8') if isinstance(y, unicode) else y ) for x, y in data.iteritems())) +    return urlencode(dict(encode(x), encode(y) for x, y in data.iteritems()))  bad_headers = range(400, 404) + range(405, 418) + range(500, 506) @@ -167,7 +169,7 @@ class HTTPRequest:                  self.c.setopt(pycurl.POSTFIELDS, post)              else: -                post = [(x, y.encode('utf8') if type(y) == unicode else y) for x, y in post.iteritems()] +                post = [(x, encode(y) for x, y in post.iteritems()]                  self.c.setopt(pycurl.HTTPPOST, post)          else:              self.c.setopt(pycurl.POST, 0) diff --git a/pyload/plugins/Plugin.py b/pyload/plugins/Plugin.py index c28b3cd87..2ab638f3b 100644 --- a/pyload/plugins/Plugin.py +++ b/pyload/plugins/Plugin.py @@ -16,7 +16,7 @@ from itertools import islice  from traceback import print_exc  from urlparse import urlparse -from pyload.utils import fs_decode, fs_encode, html_unescape, safe_join +from pyload.utils import encode, fs_decode, fs_encode, html_unescape, safe_join  def chunks(iterable, size):      it = iter(iterable) @@ -57,7 +57,7 @@ class Base(object):      def _log(self, type, args): -        msg = " | ".join([str(a).strip() for a in args if a]) +        msg = " | ".join([encode(a).strip() for a in args if a])          logger = getattr(self.core.log, type)          logger("%s: %s" % (self.__name__, msg or _("%s MARK" % type.upper()))) @@ -518,10 +518,7 @@ class Plugin(Base):          if not url:              self.fail(_("No url given")) -        if type(url) == unicode:  # utf8 vs decode -> please use decode attribute in all future plugins -            url = str(url)  #: encode('utf8') - -        url = url.strip() +        url = encode(url).strip()  #@NOTE: utf8 vs decode -> please use decode attribute in all future plugins          if self.core.debug:              self.logDebug("Load url: " + url, *["%s=%s" % (key, val) for key, val in locals().iteritems() if key not in ("self", "url")]) @@ -539,9 +536,7 @@ class Plugin(Base):                  with open(framefile, "wb") as f:                      del frame  #: delete the frame or it wont be cleaned -                    if decode: -                        res = res.encode('utf-8') -                    f.write(res) +                    f.write(encode(res))              except IOError, e:                  self.logError(e) @@ -586,10 +581,7 @@ class Plugin(Base):          if not url:              self.fail(_("No url given")) -        if type(url) == unicode: -            url = str(url) - -        url = url.strip() +        url = encode(url).strip()          if self.core.debug:              self.logDebug("Download url: " + url, *["%s=%s" % (key, val) for key, val in locals().iteritems() if key not in ("self", "url")]) diff --git a/pyload/plugins/internal/Crypter.py b/pyload/plugins/internal/Crypter.py index 2bd9328c0..76880ca14 100644 --- a/pyload/plugins/internal/Crypter.py +++ b/pyload/plugins/internal/Crypter.py @@ -3,7 +3,7 @@  from urlparse import urlparse  from pyload.plugins.Plugin import Plugin -from pyload.utils import html_unescape, save_filename +from pyload.utils import decode, html_unescape, save_filename  class Crypter(Plugin): @@ -82,7 +82,7 @@ class Crypter(Plugin):                            "%d links" % len(links),                            "Saved to folder: %s" % folder if folder else "Saved to download folder") -            links = map(lambda x: x.decode("utf-8"), links) +            links = map(decode, links)              pid = self.core.api.addPackage(name, links, package_queue) diff --git a/pyload/utils/JsEngine.py b/pyload/utils/JsEngine.py index ac3a7a7a9..f6f28f457 100644 --- a/pyload/utils/JsEngine.py +++ b/pyload/utils/JsEngine.py @@ -6,7 +6,7 @@ import sys  from os import path  from urllib import quote -from pyload.utils import encode, uniqify +from pyload.utils import encode, decode, uniqify  class JsEngine: @@ -214,7 +214,11 @@ class RhinoEngine(AbstractEngine):      def eval(self, script):          script = "print(eval(unescape('%s')))" % quote(script)          args = ["java", "-cp", self.path, "org.mozilla.javascript.tools.shell.Main", "-e", script] -        return self._eval(args).decode("utf-8").encode("ISO-8859-1") +        res = decode(self._eval(args)) +        try: +            return res.encode("ISO-8859-1") +        finally: +            return res  class JscEngine(AbstractEngine): diff --git a/pyload/utils/__init__.py b/pyload/utils/__init__.py index 367aed5be..541dedbd8 100644 --- a/pyload/utils/__init__.py +++ b/pyload/utils/__init__.py @@ -84,10 +84,7 @@ def save_join(*args):  if sys.getfilesystemencoding().startswith('ANSI'):      def fs_encode(string): -        try: -            string = string.encode('utf-8') -        finally: -            return save_path(string) +        return save_path(encode(string))      fs_decode = decode #decode utf8 | 
