Formating issues cleanup.

This commit is contained in:
poljar (Damir Jelić) 2018-01-07 16:04:17 +01:00
parent 402b9e9463
commit ea28711ce4

View file

@ -101,7 +101,12 @@ class WeechatWrapper(object):
# first, we want to disable the prefix, which is done by specifying a space. # first, we want to disable the prefix, which is done by specifying a space.
def prnt_date_tags(self, buffer, date, tags, message): def prnt_date_tags(self, buffer, date, tags, message):
message = message.replace("\n", "\n \t") message = message.replace("\n", "\n \t")
return self.wrap_for_utf8(self.wrapped_class.prnt_date_tags)(buffer, date, tags, message) return self.wrap_for_utf8(self.wrapped_class.prnt_date_tags)(
buffer,
date,
tags,
message
)
@unique @unique
@ -140,9 +145,14 @@ class RequestBuilder:
if data: if data:
json_data = json.dumps(data, separators=(',', ':')) json_data = json.dumps(data, separators=(',', ':'))
post = 'POST {location} HTTP/1.1'.format(location=location) post = 'POST {location} HTTP/1.1'.format(
location=location
)
type_header = 'Content-Type: application/x-www-form-urlencoded' type_header = 'Content-Type: application/x-www-form-urlencoded'
length_header = 'Content-Length: {length}'.format(length=len(json_data)) length_header = 'Content-Length: {length}'.format(
length=len(json_data)
)
request_list = [post, self.host_header, request_list = [post, self.host_header,
self.user_agent, accept_header, self.user_agent, accept_header,
@ -301,7 +311,10 @@ class MatrixServer:
options = [ options = [
option( option(
'autoconnect', 'boolean', '', 0, 0, 'off', 'autoconnect', 'boolean', '', 0, 0, 'off',
"Automatically connect to the matrix server when Weechat is starting" (
"Automatically connect to the matrix server when Weechat "
"is starting"
)
), ),
option( option(
'address', 'string', '', 0, 0, '', 'address', 'string', '', 0, 0, '',
@ -522,11 +535,11 @@ def handle_room_info(server, room_info):
handle_text_message(room_id, event) handle_text_message(room_id, event)
# TODO handle different content types here # TODO handle different content types here
else: else:
server_buffer_prnt( message = (
server, "Handling of content type {type} not implemented"
"Handling of content type {type} not implemented".format( ).format(type=event['content']['type'])
type=event['content']['type'])
) server_buffer_prnt(server, message)
def handle_matrix_message(server, message_type, response): def handle_matrix_message(server, message_type, response):
@ -725,11 +738,10 @@ def create_server_buffer(server):
# socket creation # socket creation
@utf8_decode @utf8_decode
def connect_cb(data, status, gnutls_rc, sock, error, ip_address): def connect_cb(data, status, gnutls_rc, sock, error, ip_address):
# pylint: disable=too-many-arguments # pylint: disable=too-many-arguments,too-many-branches
status_value = int(status) # type: long status_value = int(status) # type: long
server = SERVERS[data] server = SERVERS[data]
# pylint: disable=too-many-branches
if status_value == W.WEECHAT_HOOK_CONNECT_OK: if status_value == W.WEECHAT_HOOK_CONNECT_OK:
file_descriptor = int(sock) # type: int file_descriptor = int(sock) # type: int
sock = wrap_socket(server, file_descriptor) sock = wrap_socket(server, file_descriptor)
@ -902,7 +914,8 @@ def matrix_timer_cb(server_name, remaining_calls):
"Handling message: {message}".format(message=message)) "Handling message: {message}".format(message=message))
# TODO don't send this out here, if a SYNC fails for some reason (504 try # TODO don't send this out here, if a SYNC fails for some reason (504 try
# again!) we'll hammer the server unnecessarily # again!) we'll hammer the server unnecessarily, send it out after a
# successful sync or after a 504 sync with a proper timeout
if server.next_batch: if server.next_batch:
message = generate_matrix_request(server, MessageType.SYNC) message = generate_matrix_request(server, MessageType.SYNC)
server.send_queue.append(message) server.send_queue.append(message)
@ -994,7 +1007,6 @@ def read_matrix_config():
return False return False
elif return_code == weechat.WEECHAT_CONFIG_READ_FILE_NOT_FOUND: elif return_code == weechat.WEECHAT_CONFIG_READ_FILE_NOT_FOUND:
return True return True
else:
return False return False
@ -1011,12 +1023,11 @@ def matrix_unload_cb():
def check_server_existence(server_name, servers): def check_server_existence(server_name, servers):
if not server_name in servers: if server_name not in servers:
message = "{prefix}matrix: No such server: {server} found".format( message = "{prefix}matrix: No such server: {server} found".format(
prefix=W.prefix("error"), server=server_name) prefix=W.prefix("error"), server=server_name)
W.prnt("", message) W.prnt("", message)
return False return False
else:
return True return True
@ -1039,7 +1050,7 @@ def matrix_server_command_cb(data, buffer, args):
def list_servers(): def list_servers():
if SERVERS: if SERVERS:
W.prnt("", "\nAll matrix servers:") W.prnt("", "\nAll matrix servers:")
for server in SERVERS.keys(): for server in SERVERS:
W.prnt("", " {color}{server}".format( W.prnt("", " {color}{server}".format(
color=W.color("yellow"), color=W.color("yellow"),
server=server server=server
@ -1122,7 +1133,7 @@ def matrix_server_command_cb(data, buffer, args):
def add_servers_to_completion(completion): def add_servers_to_completion(completion):
for server_name in SERVERS.keys(): for server_name in SERVERS:
W.hook_completion_list_add( W.hook_completion_list_add(
completion, completion,
server_name, server_name,
@ -1159,7 +1170,7 @@ def server_command_completion_cb(data, completion_item, buffer, completion):
elif len(args) == 3: elif len(args) == 3:
if args[1] == 'delete' or args[1] == 'listfull': if args[1] == 'delete' or args[1] == 'listfull':
if args[2] not in SERVERS.keys(): if args[2] not in SERVERS:
add_servers_to_completion(completion) add_servers_to_completion(completion)
return W.WEECHAT_RC_OK return W.WEECHAT_RC_OK
@ -1181,34 +1192,46 @@ def create_default_server(config_file):
def init_hooks(): def init_hooks():
W.hook_completion( W.hook_completion(
"matrix_server_commands", "Matrix server completion", "matrix_server_commands",
"server_command_completion_cb", "") "Matrix server completion",
"server_command_completion_cb",
""
)
W.hook_completion( W.hook_completion(
"matrix_servers", "Matrix server completion", "matrix_servers",
"matrix_server_completion_cb", "") "Matrix server completion",
"matrix_server_completion_cb",
""
)
W.hook_command( W.hook_command(
# Command name and short description # Command name and short description
'matrix', 'Matrix chat protocol command', 'matrix', 'Matrix chat protocol command',
# Synopsis # Synopsis
'server add <server-name> <hostname>[:<port>] ||' + (
'server delete|list|listfull <server-name> ||' + 'server add <server-name> <hostname>[:<port>] ||'
'server rename <server-name> <new-name> ||' + 'server delete|list|listfull <server-name> ||'
'connect <server-name> ||' + 'server rename <server-name> <new-name> ||'
'disconnect <server-name> ||' + 'connect <server-name> ||'
'reconnect <server-name>', 'disconnect <server-name> ||'
'reconnect <server-name>'
),
# Description # Description
' server: list, add, remove, or rename Matrix servers' + '\n' + (
' connect: connect to Matrix servers' + '\n' + ' server: list, add, remove, or rename Matrix servers\n'
'disconnect: disconnect from one or all Matrix servers' + '\n' + ' connect: connect to Matrix servers\n'
' reconnect: reconnect to server(s)' + '\n' + 'disconnect: disconnect from one or all Matrix servers\n'
'\nUse /matrix help [command] to find out more\n', ' reconnect: reconnect to server(s)\n\n'
'Use /matrix help [command] to find out more\n'
),
# Completions # Completions
'server %(matrix_server_commands)|%* ||' + (
'connect %(matrix_servers) ||' + 'server %(matrix_server_commands)|%* ||'
'disconnect %(matrix_servers) ||' + 'connect %(matrix_servers) ||'
'reconnect %(matrix_servers)', 'disconnect %(matrix_servers) ||'
'reconnect %(matrix_servers)'
),
# Function name # Function name
'matrix_server_command_cb', '') 'matrix_server_command_cb', '')