diff options
author | Trygve Aaberge <trygveaa@gmail.com> | 2017-09-27 00:46:25 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-27 00:46:25 +0200 |
commit | 2b5ac736bd2d5be567d12ea081f9f582bf98e18a (patch) | |
tree | 7ce0e2fd148af16326110cd4da603576467cf4f9 /wee_slack.py | |
parent | 055f19717ab034ae8d96220a25df30f9f0576b48 (diff) | |
parent | 3f6339edb00fddb1001838d2c38713cc0b694c43 (diff) | |
download | wee-slack-2b5ac736bd2d5be567d12ea081f9f582bf98e18a.tar.gz |
Merge pull request #439 from trygveaa/fix/multiline-prefix-bug
Ensure that all lines printed to weechat specifies a prefix
Diffstat (limited to 'wee_slack.py')
-rw-r--r-- | wee_slack.py | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/wee_slack.py b/wee_slack.py index 09b4640..b5786bc 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -137,19 +137,31 @@ class WeechatWrapper(object): def __init__(self, wrapped_class): self.wrapped_class = wrapped_class + # Helper method used to encode/decode method calls. + def wrap_for_utf8(self, method): + def hooked(*args, **kwargs): + result = method(*encode_to_utf8(args), **encode_to_utf8(kwargs)) + # Prevent wrapped_class from becoming unwrapped + if result == self.wrapped_class: + return self + return decode_from_utf8(result) + return hooked + + # Encode and decode everything sent to/received from weechat. We use the + # unicode type internally in wee-slack, but has to send utf8 to weechat. def __getattr__(self, attr): orig_attr = self.wrapped_class.__getattribute__(attr) if callable(orig_attr): - def hooked(*args, **kwargs): - result = orig_attr(*encode_to_utf8(args), **encode_to_utf8(kwargs)) - # Prevent wrapped_class from becoming unwrapped - if result == self.wrapped_class: - return self - return decode_from_utf8(result) - return hooked + return self.wrap_for_utf8(orig_attr) else: return decode_from_utf8(orig_attr) + # Ensure all lines sent to weechat specifies a prefix. For lines after the + # first, we want to disable the prefix, which is done by specifying a space. + def prnt_date_tags(self, buffer, date, tags, message): + message = message.replace("\n", "\n \t") + return self.wrap_for_utf8(self.wrapped_class.prnt_date_tags)(buffer, date, tags, message) + ##### Helpers |