diff options
Diffstat (limited to 'module/plugins/internal')
| -rw-r--r-- | module/plugins/internal/Captcha.py | 6 | ||||
| -rw-r--r-- | module/plugins/internal/Container.py | 10 | ||||
| -rw-r--r-- | module/plugins/internal/Hoster.py | 18 | ||||
| -rw-r--r-- | module/plugins/internal/OCR.py | 7 | ||||
| -rw-r--r-- | module/plugins/internal/Plugin.py | 31 | 
5 files changed, 56 insertions, 16 deletions
| diff --git a/module/plugins/internal/Captcha.py b/module/plugins/internal/Captcha.py index 1d23eb16e..1345f1784 100644 --- a/module/plugins/internal/Captcha.py +++ b/module/plugins/internal/Captcha.py @@ -1,6 +1,7 @@  # -*- coding: utf-8 -*-  import time +import traceback  from module.plugins.internal.Plugin import Plugin @@ -110,8 +111,9 @@ class Captcha(Plugin):          if not self.pyload.debug:              try:                  os.remove(tmp_img.name) -            except Exception: -                pass +            except OSError, e: +                self.log_warning(_("Error removing: %s") % tmp_img.name, e) +                traceback.print_exc()          return result diff --git a/module/plugins/internal/Container.py b/module/plugins/internal/Container.py index 8dfa1031d..ce9426b0d 100644 --- a/module/plugins/internal/Container.py +++ b/module/plugins/internal/Container.py @@ -4,6 +4,7 @@ from __future__ import with_statement  import os  import re +import traceback  from module.plugins.internal.Crypter import Crypter  from module.utils import save_join as fs_join @@ -63,5 +64,12 @@ class Container(Crypter):      def delete_tmp(self): -        if self.pyfile.name.startswith("tmp_"): +        if not self.pyfile.name.startswith("tmp_"): +            return + +        try:              os.remove(self.pyfile.url) +        except OSError, e: +            self.log_warning(_("Error removing: %s") % self.pyfile.url, e) +            if self.pyload.debug: +                traceback.print_exc() diff --git a/module/plugins/internal/Hoster.py b/module/plugins/internal/Hoster.py index ffd7c4ecc..d26592718 100644 --- a/module/plugins/internal/Hoster.py +++ b/module/plugins/internal/Hoster.py @@ -6,6 +6,7 @@ import inspect  import os  import random  import time +import traceback  import urlparse  if os.name != "nt": @@ -14,7 +15,7 @@ if os.name != "nt":  from module.plugins.internal import Captcha  from module.plugins.internal.Plugin import (Plugin, Abort, Fail, Reconnect, Retry, Skip -                                            chunks, fixurl as _fixurl, replace_patterns, seconds_to_midnight, +                                            chunks, encode, fixurl as _fixurl, replace_patterns, seconds_to_midnight,                                              set_cookies, parse_html_form, parse_html_tag_attr_value,                                              timestamp)  from module.utils import fs_decode, fs_encode, save_join as fs_join @@ -279,7 +280,7 @@ class Hoster(Plugin):          """          Skip and give reason          """ -        raise Skip(fs_encode(reason)) +        raise Skip(encode(reason))      def abort(self, reason=""): @@ -287,7 +288,7 @@ class Hoster(Plugin):          Abort and give reason          """          if reason: -            self.pyfile.error = fs_encode(reason) +            self.pyfile.error = encode(reason)          raise Abort @@ -296,7 +297,7 @@ class Hoster(Plugin):          Fail and indicate file is offline          """          if reason: -            self.pyfile.error = fs_encode(reason) +            self.pyfile.error = encode(reason)          raise Fail("offline") @@ -305,7 +306,7 @@ class Hoster(Plugin):          Fail and indicates file ist temporary offline, the core may take consequences          """          if reason: -            self.pyfile.error = fs_encode(reason) +            self.pyfile.error = encode(reason)          raise Fail("temp. offline") @@ -489,7 +490,12 @@ class Hoster(Plugin):                          return name          finally:              if delete and do_delete: -                os.remove(lastDownload) +                try: +                    os.remove(lastDownload) +                except OSError, e: +                    self.log_warning(_("Error removing: %s") % lastDownload, e) +                    if self.pyload.debug: +                        traceback.print_exc()      def direct_link(self, url, follow_location=None): diff --git a/module/plugins/internal/OCR.py b/module/plugins/internal/OCR.py index 15d3fc305..13089c9c0 100644 --- a/module/plugins/internal/OCR.py +++ b/module/plugins/internal/OCR.py @@ -12,6 +12,7 @@ import logging  import os  import subprocess  # import tempfile +import traceback  from module.plugins.internal.Plugin import Plugin  from module.utils import save_join as fs_join @@ -129,8 +130,10 @@ class OCR(Plugin):              os.remove(tmpTxt.name)              if subset and (digits or lowercase or uppercase):                  os.remove(tmpSub.name) -        except Exception: -            pass +        except OSError, e: +            self.log_warning(e) +            if self.pyload.debug: +                traceback.print_exc()      def recognize(self, name): diff --git a/module/plugins/internal/Plugin.py b/module/plugins/internal/Plugin.py index 35541f903..01cc1ce8a 100644 --- a/module/plugins/internal/Plugin.py +++ b/module/plugins/internal/Plugin.py @@ -12,6 +12,24 @@ from module.utils import fs_encode, fs_decode, html_unescape, save_join as fs_jo  #@TODO: Move to utils in 0.4.10 +def decode(string, encoding='utf8'): +    """ Decode string to unicode with utf8 """ +    if type(string) is str: +        return string.decode(encoding, "replace") +    else: +        return string + + +#@TODO: Move to utils in 0.4.10 +def encode(string, encoding='utf8'): +    """ Decode string to utf8 """ +    if type(string) is unicode: +        return string.encode(encoding, "replace") +    else: +        return string + + +#@TODO: Move to utils in 0.4.10  def fixurl(url):      return html_unescape(urllib.unquote(url.decode('unicode-escape'))).strip() @@ -136,7 +154,7 @@ class Plugin(object):      def _log(self, level, args):          log = getattr(self.pyload.log, level) -        msg = fs_encode(" | ".join((a if isinstance(a, basestring) else str(a)).strip() for a in args if a))  #@NOTE: `fs_encode` -> `encode` in 0.4.10 +        msg = encode(" | ".join((a if isinstance(a, basestring) else str(a)).strip() for a in args if a))  #@NOTE: `fs_encode` -> `encode` in 0.4.10          log("%(plugin)s%(id)s: %(msg)s" % {'plugin': self.__name__,                                             'id'    : ("[%s]" % self.pyfile.id) if hasattr(self, 'pyfile') else "",                                             'msg'   : msg or _(level.upper() + " MARK")}) @@ -214,7 +232,7 @@ class Plugin(object):          """          Fail and give reason          """ -        raise Fail(fs_encode(reason)) +        raise Fail(encode(reason))  #: Move to manager in 0.4.10      def error(self, reason="", type=_("Parse")): @@ -260,8 +278,11 @@ class Plugin(object):          res = req.load(url, get, post, ref, cookies, just_header, multipart, decode is True) -        if decode: -            res = html_unescape(res).decode(decode if isinstance(decode, basestring) else 'utf8') +        if decode:   #@TODO: Move to network in 0.4.10 +            res = html_unescape(res) + +        if isinstance(decode, basestring):  #@TODO: Move to network in 0.4.10 +            res = decode(res, decode)          if self.pyload.debug:              frame = inspect.currentframe() @@ -272,7 +293,7 @@ class Plugin(object):                  with open(framefile, "wb") as f:                      del frame  #: Delete the frame or it wont be cleaned -                    f.write(res.encode('utf8')) +                    f.write(encode(res))              except IOError, e:                  self.log_error(e) | 
