barneygale / mark2

minecraft server wrapper, written in python with twisted
Other
105 stars 27 forks source link

[bug] Colors can't be set when "locale.getpreferredencoding()" is Ascii #84

Closed TheTechmage closed 11 years ago

TheTechmage commented 11 years ago

I've since set a valid local (en_US.UTF-8) in /etc/locale.conf instead of letting the system set it for me (C). Sadly, all color strings will break if the encode is set to Ascii and not UTF-8.

2013-06-08 23:18:52-0600 [MumbleProtocol (UDP)] <unicode instance at 0x298fb70 with str error:
         Traceback (most recent call last):
          File "/usr/lib/python2.7/site-packages/twisted/python/_reflectpy3.py", line 356, in _safeFormat
            return formatter(o)
        UnicodeEncodeError: 'ascii' codec can't encode character u'\xa7' in position 213: ordinal not in range(128)
        >
2013-06-08 23:18:52-0600 [MumbleProtocol (UDP)] *--- Failure #6 (pickled) ---
2013-06-08 23:18:52-0600 [MumbleProtocol (UDP)] /srv/minecraft/bin/mark2/mk2/plugins/__init__.py:243: send_format(...)
2013-06-08 23:18:52-0600 [MumbleProtocol (UDP)] /srv/minecraft/bin/mark2/mk2/plugins/__init__.py:239: send(...)
2013-06-08 23:18:52-0600 [MumbleProtocol (UDP)] /srv/minecraft/bin/mark2/mk2/events/__init__.py:238: dispatch(...)
2013-06-08 23:18:52-0600 [MumbleProtocol (UDP)] /srv/minecraft/bin/mark2/mk2/events/__init__.py:218: _next_event(...)
2013-06-08 23:18:52-0600 [MumbleProtocol (UDP)]  [Capture of Locals and Globals disabled (use captureVars=True)]
2013-06-08 23:18:52-0600 [MumbleProtocol (UDP)] --- <exception caught here> ---
2013-06-08 23:18:52-0600 [MumbleProtocol (UDP)] /usr/lib/python2.7/site-packages/twisted/internet/defer.py:137: maybeDeferred(...)
2013-06-08 23:18:52-0600 [MumbleProtocol (UDP)] /srv/minecraft/bin/mark2/mk2/services/process.py:90: server_input(...)
2013-06-08 23:18:52-0600 [MumbleProtocol (UDP)]  [Capture of Locals and Globals disabled (use captureVars=True)]
2013-06-08 23:18:52-0600 [MumbleProtocol (UDP)] exceptions.UnicodeEncodeError: 'ascii' codec can't encode character u'\xa7' in position 15: ordinal not in ra
nge(128)
2013-06-08 23:18:52-0600 [MumbleProtocol (UDP)] *--- End of Failure #6 ---
2013-06-08 23:18:52-0600 [mark2] 2013-06-08 23:18:52 # An event handler threw an exception:
2013-06-08 23:18:52-0600 [mark2] 2013-06-08 23:18:52 #   Callback: <bound method Process.server_input of <process.Process object at 0x298eed0>>
2013-06-08 23:18:52-0600 [mark2] 2013-06-08 23:18:52 #   Event:
2013-06-08 23:18:52-0600 [mark2] 2013-06-08 23:18:52 #     parse_colors: True
2013-06-08 23:18:52-0600 [mark2] 2013-06-08 23:18:52 #     class_name: ServerInput
2013-06-08 23:18:52-0600 [mark2] 2013-06-08 23:18:52 #     line: msg frostyfrog §2host: §a127.0.0.1
2013-06-08 23:18:52-0600 [mark2] 2013-06-08 23:18:52 # msg frostyfrog §2port: §a64738
2013-06-08 23:18:52-0600 [mark2] 2013-06-08 23:18:52 # msg frostyfrog §2status: §aup! users: 1/100
2013-06-08 23:18:52-0600 [mark2] 2013-06-08 23:18:52 #   Traceback (most recent call last):
2013-06-08 23:18:52-0600 [mark2] 2013-06-08 23:18:52 #     File "/srv/minecraft/bin/mark2/mk2/plugins/__init__.py", line 243, in send_format
2013-06-08 23:18:52-0600 [mark2] 2013-06-08 23:18:52 #       self.send(l.format(**kw), parseColors=parseColors)
2013-06-08 23:18:52-0600 [mark2] 2013-06-08 23:18:52 #     File "/srv/minecraft/bin/mark2/mk2/plugins/__init__.py", line 239, in send
2013-06-08 23:18:52-0600 [mark2] 2013-06-08 23:18:52 #       self.dispatch(ServerInput(line=l, parse_colors=parseColors))
2013-06-08 23:18:52-0600 [mark2] 2013-06-08 23:18:52 #     File "/srv/minecraft/bin/mark2/mk2/events/__init__.py", line 238, in dispatch
2013-06-08 23:18:52-0600 [mark2] 2013-06-08 23:18:52 #       d = self._next_event(event, event_list)
2013-06-08 23:18:52-0600 [mark2] 2013-06-08 23:18:52 #     File "/srv/minecraft/bin/mark2/mk2/events/__init__.py", line 218, in _next_event
2013-06-08 23:18:52-0600 [mark2] 2013-06-08 23:18:52 #       r = maybeDeferred(callback, event)
2013-06-08 23:18:52-0600 [mark2] 2013-06-08 23:18:52 #   --- <exception caught here> ---
2013-06-08 23:18:52-0600 [mark2] 2013-06-08 23:18:52 #     File "/usr/lib/python2.7/site-packages/twisted/internet/defer.py", line 137, in maybeDeferred
2013-06-08 23:18:52-0600 [mark2] 2013-06-08 23:18:52 #       result = f(*args, **kw)
2013-06-08 23:18:52-0600 [mark2] 2013-06-08 23:18:52 #     File "/srv/minecraft/bin/mark2/mk2/services/process.py", line 90, in server_input
2013-06-08 23:18:52-0600 [mark2] 2013-06-08 23:18:52 #       self.transport.write(l.encode(self.locale))
2013-06-08 23:18:52-0600 [mark2] 2013-06-08 23:18:52 #   exceptions.UnicodeEncodeError: 'ascii' codec can't encode character u'\xa7' in position 15: ordinal
not in range(128)
2013-06-08 23:18:52-0600 [mark2] 2013-06-08 23:18:52 #
barneygale commented 11 years ago

Not sure what you're expecting. afaik, the server's stdin accepts colour codes as U+00A7, which cannot be represented in ascii. Why are you setting your character set to ascii?

TheTechmage commented 11 years ago

As I said before, I wasn't setting the locale. My OS was doing that for me. As soon as I set my /etc/locale.conf to LANG=en_US.UTF-8, it was able to send the sectional symbol across. I think that if the preferred locale is somehow set to something like ascii, then the sectional symbol (and the following char) should be stripped so the plugin (mumble in my case) will still function. I may fork this repo and fix a few of the bugs that I find, but I'm not sure if that will get in the way of any re-factoring that may be taking place. =P

barneygale commented 11 years ago

Sorry for the late reply. I'll work on this today - I think the solution is probably to strip colour codes + unicode in general in process.py.

barneygale commented 11 years ago

Should be fixed, please confirm? Mark2 won't translate & to U+00A7 anymore, and it also shouldn't error horrible when it encounters any other character it can't encode.

TheTechmage commented 11 years ago

Just updated, then I found out that colors doesn't work no matter what now (I assume this is because of commit 8492fa2). Either way, it doesn't really seem to crash now (Although it hangs when I stuff the paragraph symbol in the config, but that'd be another ticket).

If you don't mind me asking, where did you find the info related to MC 1.6?