corrade-nucleus-nucleons – Blame information for rev 2

Subversion Repositories:
Rev:
Rev Author Line No. Line
2 office 1 #
2 # Trivial bookmarklet/escaped script detector for the javascript beautifier
3 # written by Einar Lielmanis <einar@jsbeautifier.org>
4 # rewritten in Python by Stefano Sanfilippo <a.little.coder@gmail.com>
5 #
6 # Will always return valid javascript: if `detect()` is false, `code` is
7 # returned, unmodified.
8 #
9 # usage:
10 #
11 # some_string = urlencode.unpack(some_string)
12 #
13  
14 """Bookmarklet/escaped script unpacker."""
15  
16 # Python 2 retrocompatibility
17 # pylint: disable=F0401
18 # pylint: disable=E0611
19 try:
20 from urllib import unquote_plus
21 except ImportError:
22 from urllib.parse import unquote_plus
23  
24 PRIORITY = 0
25  
26 def detect(code):
27 """Detects if a scriptlet is urlencoded."""
28 # the fact that script doesn't contain any space, but has %20 instead
29 # should be sufficient check for now.
30 return ' ' not in code and ('%20' in code or code.count('%') > 3)
31  
32 def unpack(code):
33 """URL decode `code` source string."""
34 return unquote_plus(code) if detect(code) else code