Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 6 additions & 20 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
if os.path.exists(activate_this):
exec(open(activate_this).read(), {'__file__': activate_this})

import logging
import socket
import ssl
import textwrap
Expand All @@ -38,11 +39,9 @@
# pylint: disable=unused-import
from typing import Any, AnyStr, Deque, Dict, List, Optional, Set, Text, Tuple

import logbook
import json
import OpenSSL.crypto as crypto
from future.utils import bytes_to_native_str as n
from logbook import Logger, StreamHandler

try:
from json.decoder import JSONDecodeError
Expand Down Expand Up @@ -114,7 +113,7 @@
# yapf: enable


logger = Logger("matrix-cli")
logger = logging.getLogger(__name__)


def print_certificate_info(buff, sock, cert):
Expand Down Expand Up @@ -532,20 +531,8 @@ def server_buffer_cb(server_name, buffer, input_data):
return W.WEECHAT_RC_OK


class WeechatHandler(StreamHandler):
def __init__(self, level=logbook.NOTSET, format_string=None, filter=None,
bubble=False):
StreamHandler.__init__(
self,
object(),
level,
format_string,
None,
filter,
bubble
)

def write(self, item):
class WeechatHandler(logging.StreamHandler):
def emit(self, record):
buf = ""

if G.CONFIG.network.debug_buffer:
Expand All @@ -555,7 +542,7 @@ def write(self, item):

buf = G.CONFIG.debug_buffer

W.prnt(buf, item)
W.prnt(buf, record)


def buffer_switch_cb(_, _signal, buffer_ptr):
Expand Down Expand Up @@ -688,8 +675,7 @@ def buffer_command_cb(data, _, command):
W.prnt("", message)

handler = WeechatHandler()
handler.format_string = "{record.channel}: {record.message}"
handler.push_application()
logger.addHandler(handler)

# TODO if this fails we should abort and unload the script.
G.CONFIG = MatrixConfig()
Expand Down
4 changes: 2 additions & 2 deletions matrix/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

from __future__ import unicode_literals

import logging
import sys
from typing import Any, Dict, Optional
from logbook import Logger
from collections import OrderedDict

from .utf import WeechatWrapper
Expand All @@ -44,5 +44,5 @@
SCRIPT_NAME = "matrix" # type: str
BUFFER_NAME_PREFIX = "{}.".format(SCRIPT_NAME) # type: str
TYPING_NOTICE_TIMEOUT = 4000 # 4 seconds typing notice lifetime
LOGGER = Logger("weechat-matrix")
LOGGER = logging.getLogger(__name__)
UPLOADS = OrderedDict() # type: Dict[str, Upload]
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ webcolors = "^1.11.1"
atomicwrites = "^1.3.0"
future = { version = "^0.18.2", python = "<3.2" }
attrs = "^19.3.0"
logbook = "^1.5.3"
pygments = "^2.6.1"
matrix-nio = { version = "^0.18.7", extras = [ "e2e" ] }
python-magic = { version = "^0.4.15", optional = true }
Expand Down