colinta / SublimeStringEncode

Converts characters from one "encoding" to another using a transformation (think HTML entities, not character encodings)
Other
150 stars 22 forks source link

Not working on windows 8.1 ST3 #11

Closed ghost closed 10 years ago

ghost commented 10 years ago

Not working on windows 8.1 ST3, installed using package control

colinta commented 10 years ago

I don't have a windows computer to test this on, so I'm afraid you're on your own on this one.

No console output? No clues? I've got nothing to go on.

ghost commented 10 years ago

I did a bit research, it's the base64encode and decode not working the console says

Traceback (most recent call last):
  File "C:\Program Files\Sublime Text 3\sublime_plugin.py", line 549, in run_
    return self.run(edit)
  File "string_encode in C:\Users\Aulphar\AppData\Roaming\Sublime Text 3\Installed Packages\StringEncode.sublime-package", line 17, in run
  File "string_encode in C:\Users\Aulphar\AppData\Roaming\Sublime Text 3\Installed Packages\StringEncode.sublime-package", line 135, in encode
  File "X/base64.py", line 58, in b64encode
TypeError: expected bytes, not str

which seems to me the plugin is written in python2 but is executed in python3, i tried to fix it as below and tested working on TS3

class Base64EncodeCommand(StringEncode):
    def encode(self, text):
        if sys.version_info[0] >= 3:
            return base64.b64encode(text.encode("utf-8")).decode("utf-8")
        else:
            return base64.b64encode(text)

class Base64DecodeCommand(StringEncode):
    def encode(self, text):
        if sys.version_info[0] >= 3:
            return base64.b64decode(text.encode("utf-8")).decode("utf-8")
        else:
            return base64.b64decode(text)