From b8e23365241337ebb8a42a0d93cbc67afbbee480 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sun, 18 Oct 2015 19:08:02 +0200 Subject: [Plugin] Minimize code + spare fixes --- module/plugins/internal/Plugin.py | 312 +++----------------------------------- 1 file changed, 24 insertions(+), 288 deletions(-) (limited to 'module/plugins/internal/Plugin.py') diff --git a/module/plugins/internal/Plugin.py b/module/plugins/internal/Plugin.py index f5db49d8b..0b5561df8 100644 --- a/module/plugins/internal/Plugin.py +++ b/module/plugins/internal/Plugin.py @@ -2,284 +2,19 @@ from __future__ import with_statement -import datetime import inspect import os -import re -import sys -import time -import traceback -import urllib -import urlparse - -import pycurl if os.name is not "nt": import grp import pwd -from module.common.json_layer import json_dumps, json_loads -from module.plugins.Plugin import Abort, Fail, Reconnect, Retry, SkipDownload as Skip #@TODO: Remove in 0.4.10 -from module.utils import (fs_encode, fs_decode, get_console_encoding, html_unescape, - parseFileSize as parse_size, save_join as fs_join) - - -#@TODO: Move to utils in 0.4.10 -def isiterable(obj): - return hasattr(obj, "__iter__") - - -#@TODO: Move to utils in 0.4.10 -def decode(string, encoding=None): - """Encoded string (default to UTF-8) -> unicode string""" - if type(string) is str: - try: - res = unicode(string, encoding or "utf-8") - - except UnicodeDecodeError, e: - if encoding: - raise UnicodeDecodeError(e) - - encoding = get_console_encoding(sys.stdout.encoding) - res = unicode(string, encoding) - - elif type(string) is unicode: - res = string - - else: - res = unicode(string) - - return res - - -#@TODO: Remove in 0.4.10 -def _decode(*args, **kwargs): - return decode(*args, **kwargs) - - -#@TODO: Move to utils in 0.4.10 -def encode(string, encoding=None, decoding=None): - """Unicode or decoded string -> encoded string (default to UTF-8)""" - if type(string) is unicode: - res = string.encode(encoding or "utf-8") - - elif type(string) is str: - res = encode(decode(string, decoding), encoding) - - else: - res = str(string) - - return res - - -#@TODO: Move to utils in 0.4.10 -def exists(path): - if os.path.exists(path): - if os.name is "nt": - dir, name = os.path.split(path.rstrip(os.sep)) - return name in os.listdir(dir) - else: - return True - else: - return False - - -def fixurl(url, unquote=None): - old = url - url = urllib.unquote(url) - - if unquote is None: - unquote = url is old - - url = html_unescape(decode(url).decode('unicode-escape')) - url = re.sub(r'(?\s\"'][^>\s]*)\1" % attr_name, tag, re.I) - return m.group(2) if m else None - - -def parse_html_form(attr_str, html, input_names={}): - for form in re.finditer(r"(?P]*%s[^>]*>)(?P.*?)]*>" % attr_str, - html, re.I | re.S): - inputs = {} - action = parse_html_tag_attr_value("action", form.group('TAG')) - - for inputtag in re.finditer(r'(<(input|textarea)[^>]*>)([^<]*(?=