-
Notifications
You must be signed in to change notification settings - Fork 2
/
url_encode.py
48 lines (36 loc) · 1.2 KB
/
url_encode.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
__kupfer_name__ = _("URL Encode")
__version__ = "0.1.1"
__author__ = "Hugo Sena Ribeiro <[email protected]>"
__description__ = _("""Decode and encode actions for kupfer""")
__kupfer_actions__ = ("URLEncode", "URLDecode")
import urllib
from kupfer.objects import Action, UrlLeaf, TextLeaf
class URLEncode(Action):
def __init__(self):
Action.__init__(self, name=_("URL Encode"))
def activate(self, obj):
result = ''
try:
result = urllib.quote(obj.object.encode('utf8'))
except AttributeError:
result = urllib.parse.quote(obj.object.encode('utf8'))
return TextLeaf(result)
def item_types(self):
return UrlLeaf, TextLeaf
def has_result(self):
return True
class URLDecode(Action):
def __init__(self):
Action.__init__(self, name=_("URL Decode"))
def activate(self, obj):
result = ''
try:
result = urllib.unquote(obj.object)
except AttributeError:
result = urllib.parse.unquote(obj.object)
return TextLeaf(result)
def item_types(self):
yield UrlLeaf
yield TextLeaf
def has_result(self):
return True