Skip to content

Commit 64e83eb

Browse files
committed
Apply more linting fixes to the files
1 parent c80e833 commit 64e83eb

File tree

13 files changed

+62
-47
lines changed

13 files changed

+62
-47
lines changed

zirc/caps.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ def __init__(self, *args):
1111
self.stringcaps.append(cap.name)
1212
else:
1313
self.stringcaps.append(cap)
14-
15-
def handler(self,event):
14+
15+
def handler(self, event):
1616
if event.arguments[0] == "LS":
1717
servcaps = event.arguments[1].split(' ')
1818
for c in servcaps:
@@ -21,16 +21,15 @@ def handler(self,event):
2121
if not self.availablecaps:
2222
self.bot.send("CAP END")
2323
else:
24-
self.bot.send("CAP REQ :"+" ".join(self.availablecaps))
24+
self.bot.send("CAP REQ :" + " ".join(self.availablecaps))
2525
elif event.arguments[0] == "ACK":
2626
for cap in self.caps:
2727
if hasattr(cap, "run"):
2828
cap.run(self.bot)
2929

3030
def run(self, bot):
3131
self.bot = bot
32-
self.bot.listen(self.handler,"cap")
32+
self.bot.listen(self.handler, "cap")
3333
self.bot.send("CAP LS")
34-
3534

36-
__call__ = run
35+
__call__ = run

zirc/client.py

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,74 +8,79 @@
88

99
class Client(object):
1010
listeners = []
11-
def connect(self, config_class = None):
11+
12+
def connect(self, config_class=None):
1213

1314
self.fp = floodProtect()
1415
if not hasattr(self, "connection"):
1516
raise NoSocket("{0} has no attribute 'connection'".format(self))
1617
if config_class is None:
1718
raise NoConfig("config_class not a argument when calling connect")
18-
19+
1920
self._config = config_class
2021
self.socket = self.connection((self._config["host"], self._config["port"]))
2122

2223
self._config["caps"](self)
2324

2425
if self._config.get("password"):
2526
self.send("PASS {0}".format(self._config["password"]))
26-
27+
2728
self.send("NICK {0}".format(self._config["nickname"]))
2829
self.send("USER {0} * * :{1}".format(self._config["ident"], self._config["realname"]))
29-
30+
3031
self._channels = self._config["channels"]
3132
self.loop = EventLoop(self.recv)
33+
3234
def recv(self):
33-
self.buffer= ""
35+
self.buffer = ""
3436
while not self.buffer.endswith("\r\n"):
3537
self.buffer += self.socket.recv(2048).decode("utf-8", errors="replace")
3638
self.buffer = self.buffer.strip().split("\r\n")
3739
return self.buffer
40+
3841
def send(self, data):
3942
if hasattr(self, "on_send"):
4043
self.on_send(data)
4144
self.fp.queue_add(self.socket, "{0}\r\n".format(data).encode("UTF-8"))
45+
4246
def start(self):
4347
self.loop.create_job("main", self.main_job)
4448
self.loop.run()
49+
4550
def main_job(self, event):
4651
"""loop job to provide a event based system for clients."""
4752
args = {"event": event, "bot": self, "irc": connection_wrapper(self), "args": " ".join(event.arguments).split(" ")[1:]}
48-
49-
#add arguments from event, for easier access
53+
54+
# add arguments from event, for easier access
5055
args.update({k: getattr(event, k) for k in dir(event) if not k.startswith("__") and not k.endswith("__")})
51-
56+
5257
if event.type == "001":
5358
for channel in self._channels:
5459
self.send("JOIN {0}".format(channel))
5560

5661
to_call = []
57-
62+
5863
if hasattr(self, "on_all"):
5964
to_call.append(self.on_all)
60-
61-
if hasattr(self, "on_"+event.type.lower()):
62-
to_call.append(getattr(self, "on_"+event.type.lower()))
63-
65+
66+
if hasattr(self, "on_" + event.type.lower()):
67+
to_call.append(getattr(self, "on_" + event.type.lower()))
68+
6469
if event.type != event.text_type:
65-
if hasattr(self, "on_"+event.text_type.lower()):
66-
to_call.append(getattr(self, "on_"+event.text_type.lower()))
70+
if hasattr(self, "on_" + event.text_type.lower()):
71+
to_call.append(getattr(self, "on_" + event.text_type.lower()))
6772

6873
for event_name, func in self.listeners:
6974
if event_name == event.text_type.lower() or event_name == event.type.lower():
7075
to_call.append(func)
71-
#Call the functions here
76+
# Call the functions here
7277
for call_func in to_call:
7378
util.function_argument_call(call_func, args)()
74-
79+
7580
if event.type == "PING":
7681
self.send("PONG :{0}".format(" ".join(event.arguments)))
77-
78-
#CTCP Replies
82+
83+
# CTCP Replies
7984
if event.type == "PRIVMSG" and " ".join(event.arguments).startswith("\x01") and hasattr(self, "ctcp"):
8085
ctcp_message = " ".join(event.arguments).replace("\x01", "").upper()
8186
if ctcp_message in self.ctcp.keys():
@@ -84,16 +89,19 @@ def main_job(self, event):
8489
else:
8590
result = self.ctcp[ctcp_message]
8691
self.send("NOTICE {0} :{1} {2}".format(event.source.nick, ctcp_message, result))
87-
#Basic client use
92+
93+
# Basic client use
8894
def privmsg(self, channel, message):
8995
MSGLEN = 400 - len("PRIVMSG {} :\r\n".format(channel).encode())
90-
strings = [message[i:i+MSGLEN] for i in range(0, len(message), MSGLEN)]
96+
strings = [message[i:i + MSGLEN] for i in range(0, len(message), MSGLEN)]
9197
for message in strings:
9298
self.send("PRIVMSG {0} :{1}".format(channel, message))
99+
93100
def reply(self, event, message):
94101
if event.target == self._config['nickname']:
95102
self.privmsg(event.source.nick, message)
96103
else:
97104
self.privmsg(event.target, message)
105+
98106
def listen(self, func, event_name):
99107
self.listeners.append((event_name.lower(), func))

zirc/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
class IRCConfig(object):
44
"""
55
Class for holding zIRC config infomation.
6-
6+
77
>>> self.config = zirc.IRCConfig(nickname="IRCConfigTest")
88
>>> self.connect(self.config)
99
"""
@@ -15,7 +15,7 @@ def __init__(self, **c):
1515
"realname": "zIRC Bot",
1616
"channels": ["#zirc"],
1717
"caps": Caps()
18-
}
18+
}
1919
self.dict.update(c)
2020

2121
def sterilise(self, method):

zirc/connection.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
class Socket(object):
66
"""
77
A class for creating socket connections.
8-
8+
99
Creating a connection:
1010
address = ("irc.stuxnet.xyz", 6697)
1111
Socket(wrapper=ssl.wrap_socket, family=socket.AF_INET6)(address)
@@ -17,11 +17,12 @@ def __init__(self, wrapper=same, family=socket.AF_INET, socket_class=None, bind_
1717
self.sock = socket.socket(family, socket.SOCK_STREAM)
1818
self.bind_address = bind_address
1919
self.wrapper = wrapper
20+
2021
def connect(self, socket_address):
2122
self.sock = self.wrapper(self.sock)
2223
if self.bind_address:
2324
self.sock.bind(self.bind_address)
2425
self.sock.connect(socket_address)
25-
26+
2627
return self.sock
2728
__call__ = connect

zirc/errors.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import sys as _sys
2-
if _sys.version_info > (2,7):
2+
if _sys.version_info > (2, 7):
33
class ConnectionError(OSError):
44
pass
55

@@ -16,9 +16,9 @@ class NoConfig(IRCError):
1616
pass
1717

1818

19-
#test.py
19+
# test.py
2020
class TestError(Exception):
2121
pass
2222

2323
class InvalidLine(TestError):
24-
pass
24+
pass

zirc/event.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def __init__(self, raw):
1919
self.type, args = raw.split(" ", 1)
2020
self.source = self.target = None
2121
if self.target:
22-
if self.target.startswith(":"): # n!u@h NICK :nuh
22+
if self.target.startswith(":"): # n!u@h NICK :nuh
2323
self.target = self.target.replace(":", "", 1)
2424
self.arguments = []
2525
if args.startswith(":"):
@@ -31,7 +31,7 @@ def __init__(self, raw):
3131
self.arguments.append(arg)
3232
if len(args) > 1:
3333
self.arguments.append(args[1])
34-
34+
3535
self.text_type = irc_events.get(self.type, self.type).upper()
3636

3737
def __str__(self):

zirc/ext/fifo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def fifo_while(send_function, name):
88
line = f.readline()[:-1]
99
if len(line) > 0:
1010
send_function(line)
11-
11+
1212
def Fifo(send_function, name="fifo"):
1313
thread = threading.Thread(target=fifo_while, args=(send_function, name))
1414
thread.daemon = True

zirc/ext/proxy.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ def __init__(self, host="localhost", port=1080, protocol=socks.SOCKS5):
88
self.host = host
99
self.port = port
1010
self.protocol = protocol
11+
1112
def __repr__(self):
1213
return "Proxy({0}, {1})".format(self.host, self.protocol)
14+
1315
def __call__(self, family=socket.AF_INET, type=socket.SOCK_STREAM):
1416
socks.socksocket.__init__(self, family, type)
1517
self.set_proxy(self.protocol, self.host, self.port)

zirc/ext/sasl.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,29 @@
55

66
class Sasl(object):
77
name = "sasl"
8+
89
def __init__(self, username, password, method="plain"):
910
self.username = username
1011
self.password = password
1112
self.method = method
13+
1214
def run(self, bot):
1315
self.bot = bot
14-
bot.listen(self.on_authenticate,"authenticate")
15-
bot.listen(self.on_saslfailed,"saslfailed")
16-
bot.listen(self.on_saslsuccess,"saslsuccess")
16+
bot.listen(self.on_authenticate, "authenticate")
17+
bot.listen(self.on_saslfailed, "saslfailed")
18+
bot.listen(self.on_saslsuccess, "saslsuccess")
1719
if self.method == "plain":
1820
bot.send("AUTHENTICATE PLAIN")
1921
else:
2022
raise SASLError("not implemented yet")
21-
22-
def on_authenticate(self,event):
23+
24+
def on_authenticate(self, event):
2325
if event.arguments[0] == "+":
2426
password = base64.b64encode("{0}\x00{0}\x00{1}".format(self.username, self.password).encode("UTF-8")).decode("UTF-8")
2527
self.bot.send("AUTHENTICATE {0}".format(password))
2628

2729
def on_saslfailed(self, event):
28-
raise SASLError("SASL authentication failed!") # do something else later, like try another method
30+
raise SASLError("SASL authentication failed!") # do something else later, like try another method
2931

3032
def on_saslsuccess(self, event):
3133
self.bot.send("CAP END")

zirc/flood.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def queue_add(self, connection, raw):
2828
self.queuet.start()
2929

3030
def queue_add_first(self, connection, raw):
31-
self.irc_queue=[[connection,raw]]+self.irc_queue
31+
self.irc_queue = [[connection, raw]] + self.irc_queue
3232
if not self.irc_queue_running:
3333
self.irc_queue_running = True
3434
self.queuet = Thread(target=self.queue_thread)

0 commit comments

Comments
 (0)