URL Decoding Macro

This forum allows you to share scripts with other Zeus users. Please do not post bug reports, feature requests or questions to this forum, but rather use it exclusively for posting scripts or for the discussion of scripts that have been posted.
Post Reply
jussij
Site Admin
Posts: 2432
Joined: Fri Aug 13, 2004 5:10 pm

URL Decoding Macro

Post by jussij » Wed Jan 16, 2019 11:05 pm

Consider the following mapping of characters to their encoded equivalent value:

Code: Select all

   !   #   $   &   '   (   )   *   +   ,   /   :   ;   =   ?   @   [   ]
   %21 %23 %24 %26 %27 %28 %29 %2A %2B %2C %2F %3A %3B %3D %3F %40 %5B %5D
As an example this macro will take this string:

Code: Select all

   %21 %23 %24 %26 %27 %28 %29 %2A %2B %2C %2F %3A %3B %3D %3F %40 %5B %5D
and produce this decoded result:

Code: Select all

   !   #   $   &   '   (   )   *   +   ,   /   :   ;   =   ?   @   [   ]
Here is the macro:

Code: Select all

#
#        Name: Unquote Marked Region of Text
#
#      Author: Jussi Jumppanen
#
#    Language: Python
#
# Description: This macro will unquote a marked region of text and add
# the results to the clipboard.
#
# Consider the following mapping for characters to their encoded equivalent
# value:
#
#    !   #   $   &   '   (   )   *   +   ,   /   :   ;   =   ?   @   [   ]
#    %21 %23 %24 %26 %27 %28 %29 %2A %2B %2C %2F %3A %3B %3D %3F %40 %5B %5D
#
# As an example this macro will take this string:
#
#    %21 %23 %24 %26 %27 %28 %29 %2A %2B %2C %2F %3A %3B %3D %3F %40 %5B %5D
#
# and produce this unquoted result:
#
#    !   #   $   &   '   (   )   *   +   ,   /   :   ;   =   ?   @   [   ]
#
import zeus
import urllib.parse

def unquoteMarkedText():

    if zeus.is_marked():
        text = zeus.macro_tag("$wex").decode('utf8')
        zeus.set_clipboard_text(urllib.parse.unquote(text))
        zeus.message("The unquoted text has been added to the clipboard.")
    else:
        zeus.message("No text is currently marked.")
        zeus.beep()

unquoteMarkedText()

Post Reply
kuchnie warszawa opinie

Who is online

Users browsing this forum: No registered users and 2 guests