mirror of
https://github.com/jlu5/SupyPlugins.git
synced 2025-05-02 16:31:11 -05:00
WTE: python 2 compatibility + tests
This commit is contained in:
parent
84539d50b2
commit
37a55db8bf
@ -28,6 +28,7 @@
|
||||
|
||||
###
|
||||
|
||||
from __future__ import unicode_literals
|
||||
import supybot.utils as utils
|
||||
from supybot.commands import *
|
||||
import supybot.plugins as plugins
|
||||
@ -40,6 +41,8 @@ try: # Python 3
|
||||
from urllib.parse import urlencode
|
||||
except ImportError: # Python 2
|
||||
from urllib import urlencode
|
||||
from sys import version_info
|
||||
|
||||
try:
|
||||
from supybot.i18n import PluginInternationalization
|
||||
_ = PluginInternationalization('WTE')
|
||||
@ -66,6 +69,8 @@ class WTE(callbacks.Plugin):
|
||||
'ur', 'pl', 'eo', 'yo', 'en', 'yi')
|
||||
|
||||
def getTranslation(self, irc, sourceLang, targetLang, text):
|
||||
if version_info[0] < 3:
|
||||
text = text.encode("utf-8")
|
||||
url = "http://translate.google.com/translate_a/t?"+ \
|
||||
urlencode({"client": "p",
|
||||
"sl":sourceLang, "tl":targetLang,
|
||||
|
@ -33,5 +33,10 @@ from supybot.test import *
|
||||
class WTETestCase(PluginTestCase):
|
||||
plugins = ('WTE',)
|
||||
|
||||
def testWTE(self):
|
||||
m = self.getMsg("wte The quick brown fox jumps over "
|
||||
"the lazy dog.")
|
||||
print('\nResponse: %s' % m.args[1])
|
||||
assert m, 'No response found.'
|
||||
|
||||
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
|
||||
|
Loading…
x
Reference in New Issue
Block a user