This repository has been archived by the owner on Sep 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for ST3, while keeping support for ST2.
- Loading branch information
Markus Amalthea Magnuson
committed
Jan 12, 2014
1 parent
ab26f57
commit e75bbe2
Showing
1 changed file
with
95 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,116 +1,127 @@ | ||
import sublime_plugin | ||
import hashlib | ||
import urllib | ||
try: | ||
from urllib import quote as urlquote | ||
from urllib import unquote as urlunquote | ||
except ImportError: | ||
from urllib.parse import quote as urlquote | ||
from urllib.parse import unquote as urlunquote | ||
import time | ||
import base64 | ||
import re | ||
try: | ||
from HTMLParser import HTMLParser | ||
except ImportError: | ||
from html.parser import HTMLParser | ||
try: | ||
from htmlentitydefs import codepoint2name as cp2n | ||
except ImportError: | ||
from html.entities import codepoint2name as cp2n | ||
|
||
# test | ||
|
||
class Md5Command(sublime_plugin.TextCommand): | ||
def run(self, edit): | ||
for s in self.view.sel(): | ||
if s.empty(): | ||
s = self.view.word(s) | ||
def run(self, edit): | ||
for s in self.view.sel(): | ||
if s.empty(): | ||
s = self.view.word(s) | ||
selected = self.view.substr(s).encode('utf-8') | ||
m = hashlib.md5() | ||
m.update(selected) | ||
txt = m.hexdigest() | ||
self.view.replace(edit, s, txt) | ||
|
||
selected = self.view.substr(s).encode('utf8') | ||
m = hashlib.md5() | ||
m.update(selected) | ||
txt = m.hexdigest() | ||
self.view.replace(edit, s, txt) | ||
|
||
class Sha1Command(sublime_plugin.TextCommand): | ||
def run(self, edit): | ||
for s in self.view.sel(): | ||
if s.empty(): | ||
s = self.view.word(s) | ||
def run(self, edit): | ||
for s in self.view.sel(): | ||
if s.empty(): | ||
s = self.view.word(s) | ||
selected = self.view.substr(s).encode('utf-8') | ||
m = hashlib.sha1() | ||
m.update(selected) | ||
txt = m.hexdigest() | ||
self.view.replace(edit, s, txt) | ||
|
||
selected = self.view.substr(s).encode('utf8') | ||
m = hashlib.sha1() | ||
m.update(selected) | ||
txt = m.hexdigest() | ||
self.view.replace(edit, s, txt) | ||
|
||
class Base64EncodeCommand(sublime_plugin.TextCommand): | ||
def run(self, edit): | ||
for s in self.view.sel(): | ||
if s.empty(): | ||
s = self.view.word(s) | ||
def run(self, edit): | ||
for s in self.view.sel(): | ||
if s.empty(): | ||
s = self.view.word(s) | ||
selected = self.view.substr(s).encode('utf-8') | ||
txt = base64.b64encode(selected).decode('utf-8') | ||
self.view.replace(edit, s, txt) | ||
|
||
selected = self.view.substr(s).encode('utf8') | ||
txt = base64.b64encode(selected) | ||
self.view.replace(edit, s, txt) | ||
|
||
class Base64DecodeCommand(sublime_plugin.TextCommand): | ||
def run(self, edit): | ||
for s in self.view.sel(): | ||
if s.empty(): | ||
s = self.view.word(s) | ||
def run(self, edit): | ||
for s in self.view.sel(): | ||
if s.empty(): | ||
s = self.view.word(s) | ||
selected = self.view.substr(s) | ||
|
||
selected = self.view.substr(s) | ||
# pad to 4 characters | ||
if len(selected) % 4 != 0: | ||
selected += "=" * (4 - len(selected) % 4) | ||
|
||
# pad to 4 characters | ||
if len(selected) % 4 != 0: | ||
selected += "=" * (4 - len(selected) % 4) | ||
txt = base64.b64decode(selected).decode('utf8') | ||
self.view.replace(edit, s, txt) | ||
|
||
txt = base64.b64decode(selected).decode('utf8') | ||
self.view.replace(edit, s, txt) | ||
|
||
class UriComponentEncodeCommand(sublime_plugin.TextCommand): | ||
def run(self, edit): | ||
for s in self.view.sel(): | ||
if s.empty(): | ||
s = self.view.word(s) | ||
def run(self, edit): | ||
for s in self.view.sel(): | ||
if s.empty(): | ||
s = self.view.word(s) | ||
selected = self.view.substr(s) | ||
txt = urlquote(selected.encode('utf8'), '') | ||
self.view.replace(edit, s, txt) | ||
|
||
selected = self.view.substr(s) | ||
txt = urllib.quote(selected.encode('utf8'), '') | ||
self.view.replace(edit, s, txt) | ||
|
||
class UriComponentDecodeCommand(sublime_plugin.TextCommand): | ||
def run(self, edit): | ||
for s in self.view.sel(): | ||
if s.empty(): | ||
s = self.view.word(s) | ||
def run(self, edit): | ||
for s in self.view.sel(): | ||
if s.empty(): | ||
s = self.view.word(s) | ||
selected = self.view.substr(s) | ||
try: | ||
txt = urlunquote(selected.encode('utf8')).decode('utf8') | ||
except TypeError: | ||
txt = urlunquote(selected) | ||
self.view.replace(edit, s, txt) | ||
|
||
selected = self.view.substr(s) | ||
txt = urllib.unquote(selected.encode('utf8')) | ||
txt = unicode(txt.decode('utf8')); | ||
self.view.replace(edit, s, txt); | ||
|
||
class EntityEncodeCommand(sublime_plugin.TextCommand): | ||
def run(self, edit): | ||
from htmlentitydefs import codepoint2name as cp2n | ||
for s in self.view.sel(): | ||
if s.empty(): | ||
s = self.view.word(s) | ||
buf = [] | ||
for pt in xrange(s.begin(), s.end()): | ||
ch = self.view.substr(pt) | ||
ch_ord = ord(ch) | ||
try: | ||
ch = '&%s;' % cp2n[ch_ord] | ||
except: | ||
pass | ||
buf.append(ch) | ||
self.view.replace(edit, s, ''.join(buf)); | ||
def run(self, edit): | ||
for s in self.view.sel(): | ||
if s.empty(): | ||
s = self.view.word(s) | ||
buf = [] | ||
for pt in range(s.begin(), s.end()): | ||
ch = self.view.substr(pt) | ||
ch_ord = ord(ch) | ||
try: | ||
ch = '&%s;' % cp2n[ch_ord] | ||
except: | ||
pass | ||
buf.append(ch) | ||
self.view.replace(edit, s, ''.join(buf)) | ||
|
||
|
||
class EntityDecodeCommand(sublime_plugin.TextCommand): | ||
def run(self, edit): | ||
for s in self.view.sel(): | ||
if s.empty(): | ||
s = self.view.word(s) | ||
def run(self, edit): | ||
for s in self.view.sel(): | ||
if s.empty(): | ||
s = self.view.word(s) | ||
selected = self.view.substr(s) | ||
parser = HTMLParser() | ||
selected = parser.unescape(selected) | ||
self.view.replace(edit, s, selected) | ||
|
||
selected = unicode(self.view.substr(s)) | ||
import HTMLParser | ||
HTMLParser = HTMLParser.HTMLParser() | ||
selected = HTMLParser.unescape(selected) | ||
self.view.replace(edit, s, selected); | ||
|
||
class CurrentUnixTimestamp(sublime_plugin.TextCommand): | ||
def run(self, edit): | ||
for s in self.view.sel(): | ||
|
||
txt = time.asctime(time.gmtime()) | ||
txt = time.ctime() | ||
txt = "%.0f" % round(time.time(), 3) | ||
self.view.replace(edit, s, txt) | ||
def run(self, edit): | ||
for s in self.view.sel(): | ||
txt = time.asctime(time.gmtime()) | ||
txt = time.ctime() | ||
txt = "%.0f" % round(time.time(), 3) | ||
self.view.replace(edit, s, txt) |