From 95a83cb953db2707429ed2ea33e66b6e02c54273 Mon Sep 17 00:00:00 2001 From: "Michael B. Klein" Date: Tue, 19 Jan 2010 18:03:22 +0000 Subject: [PATCH 1/5] Added Unicode lookup git-svn-id: svn://rc98.net/supybot-plugins@1013 231ca652-46dc-4159-9403-8d4cb240bb29 --- README.txt | 1 + __init__.py | 66 ++++++++++++++++++++++++++++++++++++++++++++++ config.py | 49 ++++++++++++++++++++++++++++++++++ local/__init__.py | 1 + plugin.py | 67 +++++++++++++++++++++++++++++++++++++++++++++++ test.py | 37 ++++++++++++++++++++++++++ 6 files changed, 221 insertions(+) create mode 100644 README.txt create mode 100644 __init__.py create mode 100644 config.py create mode 100644 local/__init__.py create mode 100644 plugin.py create mode 100644 test.py diff --git a/README.txt b/README.txt new file mode 100644 index 0000000..d60b47a --- /dev/null +++ b/README.txt @@ -0,0 +1 @@ +Insert a description of your plugin here, with any notes, etc. about using it. diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..d3cb8bc --- /dev/null +++ b/__init__.py @@ -0,0 +1,66 @@ +### +# Copyright (c) 2010, Michael B. Klein +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions, and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions, and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the author of this software nor the name of +# contributors to this software may be used to endorse or promote products +# derived from this software without specific prior written consent. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + +### + +""" +Add a description of the plugin (to be presented to the user inside the wizard) +here. This should describe *what* the plugin does. +""" + +import supybot +import supybot.world as world + +# Use this for the version of this plugin. You may wish to put a CVS keyword +# in here if you're keeping the plugin in CVS or some similar system. +__version__ = "" + +# XXX Replace this with an appropriate author or supybot.Author instance. +__author__ = supybot.authors.unknown + +# This is a dictionary mapping supybot.Author instances to lists of +# contributions. +__contributors__ = {} + +# This is a url where the most recent plugin package can be downloaded. +__url__ = '' # 'http://supybot.com/Members/yourname/Unicode/download' + +import config +import plugin +reload(plugin) # In case we're being reloaded. +# Add more reloads here if you add third-party modules and want them to be +# reloaded when this plugin is reloaded. Don't forget to import them as well! + +if world.testing: + import test + +Class = plugin.Class +configure = config.configure + + +# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: diff --git a/config.py b/config.py new file mode 100644 index 0000000..6b925bc --- /dev/null +++ b/config.py @@ -0,0 +1,49 @@ +### +# Copyright (c) 2010, Michael B. Klein +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions, and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions, and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the author of this software nor the name of +# contributors to this software may be used to endorse or promote products +# derived from this software without specific prior written consent. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + +### + +import supybot.conf as conf +import supybot.registry as registry + +def configure(advanced): + # This will be called by supybot to configure this module. advanced is + # a bool that specifies whether the user identified himself as an advanced + # user or not. You should effect your configuration by manipulating the + # registry as appropriate. + from supybot.questions import expect, anything, something, yn + conf.registerPlugin('Unicode', True) + + +Unicode = conf.registerPlugin('Unicode') +# This is where your configuration variables (if any) should go. For example: +# conf.registerGlobalValue(Unicode, 'someConfigVariableName', +# registry.Boolean(False, """Help for someConfigVariableName.""")) + + +# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: diff --git a/local/__init__.py b/local/__init__.py new file mode 100644 index 0000000..e86e97b --- /dev/null +++ b/local/__init__.py @@ -0,0 +1 @@ +# Stub so local is a module, used for third-party modules diff --git a/plugin.py b/plugin.py new file mode 100644 index 0000000..9b6a04f --- /dev/null +++ b/plugin.py @@ -0,0 +1,67 @@ +### +# Copyright (c) 2010, Michael B. Klein +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions, and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions, and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the author of this software nor the name of +# contributors to this software may be used to endorse or promote products +# derived from this software without specific prior written consent. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + +### + +import supybot.utils as utils +from supybot.commands import * +import supybot.plugins as plugins +import supybot.ircutils as ircutils +import supybot.callbacks as callbacks + +import simplejson +import supybot.utils.web as web +from urllib import urlencode, quote + +HEADERS = dict(ua = 'Zoia/1.0 (Supybot/0.83; Unicode Plugin; http://code4lib.org/irc)') + +class Unicode(callbacks.Plugin): + + def unicode(self, irc, msg, args, query): + """[query] - Look up unicode character details + """ + url = "http://unicodelookup.com/lookup?" + url = url + urlencode({'q' : query, 'o' : 0}) + doc = web.getUrl(url, headers=HEADERS) + try: + json = simplejson.loads(doc) + responses = [] + for result in json['results']: + ucode = result[2].replace('0x','U+') + responses.append('Character %s (%s): %s [HTML: %s / Decimal: %s / Hex: %s]' % (ucode, result[5], result[4], result[3], result[1], result[2])) + response = '; '.join(responses).encode('utf8','ignore') + irc.reply(response) + except ValueError: + irc.reply('No unicode characters matching /' + query + '/ found.') + + unicode = wrap(unicode, ['text']) + +Class = Unicode + + +# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: diff --git a/test.py b/test.py new file mode 100644 index 0000000..6ddabf5 --- /dev/null +++ b/test.py @@ -0,0 +1,37 @@ +### +# Copyright (c) 2010, Michael B. Klein +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions, and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions, and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the author of this software nor the name of +# contributors to this software may be used to endorse or promote products +# derived from this software without specific prior written consent. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + +### + +from supybot.test import * + +class UnicodeTestCase(PluginTestCase): + plugins = ('Unicode',) + + +# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: From 71571fd848f261583fb15af15c8e4769836ea82f Mon Sep 17 00:00:00 2001 From: "Michael B. Klein" Date: Tue, 19 Jan 2010 18:22:40 +0000 Subject: [PATCH 2/5] Removed "Character" prefix output from Unicode response git-svn-id: svn://rc98.net/supybot-plugins@1014 231ca652-46dc-4159-9403-8d4cb240bb29 --- plugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.py b/plugin.py index 9b6a04f..06d1bec 100644 --- a/plugin.py +++ b/plugin.py @@ -53,7 +53,7 @@ class Unicode(callbacks.Plugin): responses = [] for result in json['results']: ucode = result[2].replace('0x','U+') - responses.append('Character %s (%s): %s [HTML: %s / Decimal: %s / Hex: %s]' % (ucode, result[5], result[4], result[3], result[1], result[2])) + responses.append('%s (%s): %s [HTML: %s / Decimal: %s / Hex: %s]' % (ucode, result[5], result[4], result[3], result[1], result[2])) response = '; '.join(responses).encode('utf8','ignore') irc.reply(response) except ValueError: From 74b16feb159c52a6c7041a84b545cbea87f00afc Mon Sep 17 00:00:00 2001 From: Gordon Shumway <39967334+oddluck@users.noreply.github.com> Date: Tue, 19 Feb 2019 12:07:41 -0500 Subject: [PATCH 3/5] python3 fixes. get symbol name from unicodedata --- plugin.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/plugin.py b/plugin.py index 06d1bec..e64f97e 100644 --- a/plugin.py +++ b/plugin.py @@ -33,10 +33,10 @@ from supybot.commands import * import supybot.plugins as plugins import supybot.ircutils as ircutils import supybot.callbacks as callbacks - +import unicodedata import simplejson import supybot.utils.web as web -from urllib import urlencode, quote +from urllib.parse import urlencode, quote HEADERS = dict(ua = 'Zoia/1.0 (Supybot/0.83; Unicode Plugin; http://code4lib.org/irc)') @@ -53,13 +53,14 @@ class Unicode(callbacks.Plugin): responses = [] for result in json['results']: ucode = result[2].replace('0x','U+') - responses.append('%s (%s): %s [HTML: %s / Decimal: %s / Hex: %s]' % (ucode, result[5], result[4], result[3], result[1], result[2])) - response = '; '.join(responses).encode('utf8','ignore') + name = unicodedata.name('{0}'.format(query)) + responses.append('%s (%s): %s [HTML: %s / Decimal: %s / Hex: %s]' % (ucode, name, result[4], result[3], result[1], result[2])) + response = '; '.join(responses) irc.reply(response) except ValueError: irc.reply('No unicode characters matching /' + query + '/ found.') - unicode = wrap(unicode, ['text']) + unicode = unicode(unicode, ['text']) Class = Unicode From 54a6563b0662e357ddd420174aa233bbb7733a20 Mon Sep 17 00:00:00 2001 From: Gordon Shumway <39967334+oddluck@users.noreply.github.com> Date: Tue, 19 Feb 2019 12:08:13 -0500 Subject: [PATCH 4/5] python3 fixes --- __init__.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/__init__.py b/__init__.py index d3cb8bc..8a27c6a 100644 --- a/__init__.py +++ b/__init__.py @@ -35,6 +35,7 @@ here. This should describe *what* the plugin does. import supybot import supybot.world as world +import imp # Use this for the version of this plugin. You may wish to put a CVS keyword # in here if you're keeping the plugin in CVS or some similar system. @@ -50,14 +51,15 @@ __contributors__ = {} # This is a url where the most recent plugin package can be downloaded. __url__ = '' # 'http://supybot.com/Members/yourname/Unicode/download' -import config -import plugin -reload(plugin) # In case we're being reloaded. +from . import config +from . import plugin +from imp import reload +imp.reload(plugin) # In case we're being reloaded. # Add more reloads here if you add third-party modules and want them to be # reloaded when this plugin is reloaded. Don't forget to import them as well! if world.testing: - import test + from . import test Class = plugin.Class configure = config.configure From 93da96aa5ca24fcac48259cf540febf3fa957403 Mon Sep 17 00:00:00 2001 From: Gordon Shumway <39967334+oddluck@users.noreply.github.com> Date: Tue, 19 Feb 2019 12:19:52 -0500 Subject: [PATCH 5/5] Delete __init__.py --- local/__init__.py | 1 - 1 file changed, 1 deletion(-) delete mode 100644 local/__init__.py diff --git a/local/__init__.py b/local/__init__.py deleted file mode 100644 index e86e97b..0000000 --- a/local/__init__.py +++ /dev/null @@ -1 +0,0 @@ -# Stub so local is a module, used for third-party modules