akalongman / sublimetext-stringutilities

Sublime Text 2/3 plugin for string manipulations
MIT License
83 stars 24 forks source link

Support more hash commands #16

Closed ryangreenberg closed 7 years ago

ryangreenberg commented 8 years ago

String Utilities currently supports calculating the MD5 and SHA1 cryptographic hashes of the currently selected text. This change adds support for all the algorithms supported by Python's hashlib.

This also introduces an abstract class ConvertSelection to reduce boilerplate in the commands. If you like this approach we could simplify the implementation of many of the existing commands.

Thanks for making String Utilities! I look forward to your feedback on this PR.

akalongman commented 8 years ago

Thank you for your interest to StringUtilities! What about Sublime Text 2? Hashlib works on python 2.x?

ryangreenberg commented 8 years ago

Thanks for the quick response, @akalongman.

hashlib supports all the hash functions I added here as of Python 2.5, and they are supported in SublimeText 2 and 3:

SUBLIME TEXT 2

>>> import sys
>>> sys.version_info
(2, 6, 9, 'final', 0)
>>> sublime.version()
u'2221'
>>> import hashlib
>>> [x for x in dir(hashlib) if '_' not in x]
['md5', 'new', 'sha1', 'sha224', 'sha256', 'sha384', 'sha512']

SUBLIME TEXT 3

>>> import sys
>>> sys.version_info
sys.version_info(major=3, minor=3, micro=3, releaselevel='final', serial=0)
>>> sublime.version()
'3103'
>>> import hashlib
>>> [x for x in dir(hashlib) if '_' not in x]
['md5', 'new', 'sha1', 'sha224', 'sha256', 'sha384', 'sha512']

I tried to test my change in Sublime Text 2 but master as-is doesn't appear to be working in Sublime Text 2 under Python 2.6. After installing from master I get this error:

Reloading plugin /Users/ryangreenberg/Library/Application Support/Sublime Text 2/Packages/sublimetext-stringutilities/stringutilities.py
Traceback (most recent call last):
  File "./sublime_plugin.py", line 62, in reload_plugin
  File "./stringutilities.py", line 13, in <module>
    import html.entities as htmlentitydefs
ImportError: No module named html.entities
akalongman commented 8 years ago

@ryangreenberg any news?

ryangreenberg commented 8 years ago

@akalongman No, since master is broken in Sublime Text 2 I wasn't able to confirm that this change works in Sublime Text 2.

I did confirm that hashlib works under Python 2.5. If you feel like merging this change I'm confident that it won't make things more broken under v2.

thecotne commented 7 years ago

maybe discard sublime text 2 support all together ?

since ST3 is released already ?

@akalongman

akalongman commented 7 years ago

@thecotne I agree :+1:

ryangreenberg commented 7 years ago

In that case, if this branch still merges cleanly, it can be merged at any point. It last worked with Sublime Text 3 when I last checked.

thecotne commented 7 years ago

i have tested on ST3 and it works

we will later announce new major version and discard ST2 support