summaryrefslogtreecommitdiffstats
path: root/module/plugins/internal/misc.py
diff options
context:
space:
mode:
authorGravatar Walter Purcaro <vuolter@users.noreply.github.com> 2015-12-20 23:13:55 +0100
committerGravatar Walter Purcaro <vuolter@users.noreply.github.com> 2015-12-27 22:50:43 +0100
commit41da0b8a328e808fc2ec84a5718fd5f54098e630 (patch)
treea24c47fdcfcd0abe453e39e23168be8e7b40c128 /module/plugins/internal/misc.py
parent[Crypter] Code cosmetics (diff)
downloadpyload-41da0b8a328e808fc2ec84a5718fd5f54098e630.tar.xz
[Plugin] Improve load routine and related
Diffstat (limited to 'module/plugins/internal/misc.py')
-rw-r--r--module/plugins/internal/misc.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/module/plugins/internal/misc.py b/module/plugins/internal/misc.py
index 75f0dbef5..140e74409 100644
--- a/module/plugins/internal/misc.py
+++ b/module/plugins/internal/misc.py
@@ -400,6 +400,22 @@ def exists(path):
return False
+def remove(self, path, trash=True):
+ path = encode(path)
+
+ if not exists(path):
+ return
+
+ if trash:
+ send2trash.send2trash(path)
+
+ elif os.path.isdir(path):
+ shutil.rmtree(path, ignore_errors=True)
+
+ else:
+ os.remove(path)
+
+
def fsjoin(*args):
"""
Like os.path.join, but encoding aware
@@ -682,6 +698,23 @@ def set_cookies(cj, cookies):
set_cookie(cj, *cookie)
+def parse_html_header(self, header)
+ hdict = {}
+ regexp = r'[ ]*(?P<key>.+?)[ ]*:[ ]*(?P<value>.+?)[ ]*\r?\n'
+
+ for key, value in re.findall(regexp, header.lower()):
+ if key in hdict:
+ header_key = hdict.get(key)
+ if type(header_key) is list:
+ header_key.append(value)
+ else:
+ hdict[key] = [header_key, value]
+ else:
+ hdict[key] = value
+
+ return hdict
+
+
def parse_html_tag_attr_value(attr_name, tag):
m = re.search(r"%s\s*=\s*([\"']?)((?<=\")[^\"]+|(?<=')[^']+|[^>\s\"'][^>\s]*)\1" % attr_name, tag, re.I)
return m.group(2) if m else None