Skip to content

Commit 48a3904

Browse files
committed
encoding again
1 parent 013d4ba commit 48a3904

File tree

1 file changed

+42
-38
lines changed

1 file changed

+42
-38
lines changed

main.py

+42-38
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,9 @@ def is_number(s):
480480
return False
481481

482482

483-
def check_send_server_reply(sock, t, group, id, i, host, username, password):
483+
def check_send_server_reply(
484+
sock, reply: str, group: str, id, i, host, username, password
485+
):
484486
"""
485487
Check NNTP server messages, send data for next recv.
486488
After connecting, there will be a 200 message, after each message, a
@@ -508,7 +510,7 @@ def check_send_server_reply(sock, t, group, id, i, host, username, password):
508510
"[E] check_send_server_reply(sock= "
509511
+ str(sock)
510512
+ ", t= "
511-
+ str(t)
513+
+ reply
512514
+ " ,group= "
513515
+ str(group)
514516
+ " , id= "
@@ -521,7 +523,7 @@ def check_send_server_reply(sock, t, group, id, i, host, username, password):
521523
id_used = False # is id used via HEAD / STAT request to NNTP server
522524
msg_id_used = None
523525
error = False
524-
server_reply = str(t[:3]) # only first 3 chars are relevant
526+
server_reply = str(reply[:3]) # only first 3 chars are relevant
525527
# no correct NNTP server code received, most likely still propagating?
526528
if not is_number(server_reply):
527529
if VERBOSE:
@@ -531,7 +533,7 @@ def check_send_server_reply(sock, t, group, id, i, host, username, password):
531533
+ " "
532534
+ str(host)
533535
+ ", NNTP reply incorrect:"
534-
+ str(t.split())
536+
+ str(reply.split())
535537
)
536538
server_reply = "NNTP reply incorrect."
537539
error = True # pass these vars so that next article will be sent
@@ -550,7 +552,7 @@ def check_send_server_reply(sock, t, group, id, i, host, username, password):
550552
+ " "
551553
+ str(host)
552554
+ ", NNTP reply: "
553-
+ str(t.split())
555+
+ str(reply.split())
554556
)
555557
error = True # article is not there
556558
elif server_reply in ("412"): # 412 no newsgroup has been selected
@@ -562,35 +564,33 @@ def check_send_server_reply(sock, t, group, id, i, host, username, password):
562564
+ " "
563565
+ str(host)
564566
+ ", NNTP reply: "
565-
+ str(t.split())
567+
+ str(reply.split())
566568
)
567-
print(
568-
"[E] Socket: " + str(i) + " " + str(host) + ", Send: " + str(text)
569-
)
570-
sock.send(text.encode())
569+
print("[E] Socket: " + str(i) + " " + str(host) + ", Send: " + text)
570+
sock.send(text.encode("utf-8"))
571571
elif server_reply in ("221"):
572572
# 221 article retrieved - head follows (reply on HEAD)
573-
msg_id_used = t.split()[2][1:-1] # get msg id to identify ok article
573+
msg_id_used = reply.split()[2][1:-1] # get msg id to identify ok article
574574
if EXTREME:
575575
print(
576576
"[E] Socket: "
577577
+ str(i)
578578
+ " "
579579
+ str(host)
580580
+ ", NNTP reply: "
581-
+ str(t.split())
581+
+ str(reply.split())
582582
)
583583
elif server_reply in ("223"):
584584
# 223 article retrieved - request text separately (reply on STAT)
585-
msg_id_used = t.split()[2][1:-1] # get msg id to identify ok article
585+
msg_id_used = reply.split()[2][1:-1] # get msg id to identify ok article
586586
if EXTREME:
587587
print(
588588
"[E] Socket: "
589589
+ str(i)
590590
+ " "
591591
+ str(host)
592592
+ ", NNTP reply: "
593-
+ str(t.split())
593+
+ str(reply.split())
594594
)
595595
elif server_reply in ("200", "201"):
596596
# 200 service available, posting permitted
@@ -602,14 +602,14 @@ def check_send_server_reply(sock, t, group, id, i, host, username, password):
602602
+ " "
603603
+ str(host)
604604
+ ", NNTP reply: "
605-
+ str(t.split())
605+
+ str(reply.split())
606606
)
607607
text = CHECK_METHOD + " <" + id + ">\r\n" # STAT is faster than HEAD
608608
if EXTREME:
609609
print(
610610
"[E] Socket: " + str(i) + " " + str(host) + ", Send: " + str(text)
611611
)
612-
sock.send(text.encode())
612+
sock.send(text.encode("utf-8"))
613613
elif server_reply in ("381"): # 381 Password required
614614
text = "AUTHINFO PASS %s\r\n" % (password)
615615
if EXTREME:
@@ -619,12 +619,12 @@ def check_send_server_reply(sock, t, group, id, i, host, username, password):
619619
+ " "
620620
+ str(host)
621621
+ ", NNTP reply: "
622-
+ str(t.split())
622+
+ str(reply.split())
623623
)
624624
print(
625625
"[E] Socket: " + str(i) + " " + str(host) + ", Send: " + str(text)
626626
)
627-
sock.send(text.encode())
627+
sock.send(text.encode("utf-8"))
628628
elif server_reply in ("281"): # 281 Authentication accepted
629629
if EXTREME:
630630
print(
@@ -633,7 +633,7 @@ def check_send_server_reply(sock, t, group, id, i, host, username, password):
633633
+ " "
634634
+ str(host)
635635
+ ", NNTP reply: "
636-
+ str(t.split())
636+
+ str(reply.split())
637637
)
638638
elif server_reply in ("211"): # 211 group selected (group)
639639
if EXTREME:
@@ -643,7 +643,7 @@ def check_send_server_reply(sock, t, group, id, i, host, username, password):
643643
+ " "
644644
+ str(host)
645645
+ ", NNTP reply: "
646-
+ str(t.split())
646+
+ str(reply.split())
647647
)
648648
elif server_reply in ("480"): # 480 AUTHINFO required
649649
text = "AUTHINFO USER %s\r\n" % (username)
@@ -654,12 +654,12 @@ def check_send_server_reply(sock, t, group, id, i, host, username, password):
654654
+ " "
655655
+ str(host)
656656
+ ", NNTP reply: "
657-
+ str(t.split())
657+
+ str(reply.split())
658658
)
659659
print(
660660
"[E] Socket: " + str(i) + " " + str(host) + ", Send: " + str(text)
661661
)
662-
sock.send(text.encode())
662+
sock.send(text.encode("utf-8"))
663663
elif str(server_reply[:2]) in ("48", "50"):
664664
# 48X or 50X incorrect news server account settings
665665
print(
@@ -668,7 +668,7 @@ def check_send_server_reply(sock, t, group, id, i, host, username, password):
668668
+ " "
669669
+ str(host)
670670
+ ", Incorrect news server account settings: "
671-
+ str(t)
671+
+ reply
672672
)
673673
elif server_reply in ("205"): # NNTP Service exits normally
674674
sock.close()
@@ -679,7 +679,7 @@ def check_send_server_reply(sock, t, group, id, i, host, username, password):
679679
+ " "
680680
+ str(host)
681681
+ ", NNTP reply: "
682-
+ str(t.split())
682+
+ str(reply.split())
683683
)
684684
if VERBOSE:
685685
print("[V] Socket " + str(i) + " closed.")
@@ -691,7 +691,7 @@ def check_send_server_reply(sock, t, group, id, i, host, username, password):
691691
+ " "
692692
+ str(host)
693693
+ ", NNTP reply: "
694-
+ str(t.split())
694+
+ str(reply.split())
695695
)
696696
error = True # article is assumed to be not there
697697
id_used = True
@@ -703,7 +703,7 @@ def check_send_server_reply(sock, t, group, id, i, host, username, password):
703703
+ " "
704704
+ str(host)
705705
+ ", Not covered NNTP server reply code: "
706-
+ str(t.split())
706+
+ str(reply.split())
707707
)
708708
if VERBOSE or EXTREME:
709709
sys.stdout.flush()
@@ -724,10 +724,10 @@ def check_send_server_reply(sock, t, group, id, i, host, username, password):
724724
print(
725725
"[E] Socket: " + str(i) + " " + str(host) + ", Send: " + str(text)
726726
)
727-
sock.send(text.encode())
727+
sock.send(text.encode("utf-8"))
728728
elif end_loop and server_reply not in ("205"):
729729
text = "QUIT\r\n"
730-
sock.send(text.encode())
730+
sock.send(text.encode("utf-8"))
731731
if EXTREME:
732732
print(
733733
"[E] Socket: " + str(i) + " " + str(host) + ", Send: " + str(text)
@@ -1322,9 +1322,7 @@ def check_failure_status(rar_msg_ids, failed_limit, nzb_age):
13221322
+ " marking requested article as failed."
13231323
)
13241324
sys.stdout.flush()
1325-
reply = "999 Article marked as failed by script.".encode(
1326-
encoding="utf-8"
1327-
)
1325+
reply = "999 Article marked as failed by script."
13281326
failed_wait_count += 1
13291327
if failed_wait_count >= 20:
13301328
print(
@@ -1381,7 +1379,7 @@ def check_failure_status(rar_msg_ids, failed_limit, nzb_age):
13811379
# ID of missing article is not returned by server
13821380
failed_articles += 1
13831381
# found ok article on server, store success:
1384-
if id_used and not error and server_reply == "223".encode():
1382+
if id_used and not error and server_reply == "223":
13851383
# find row index for successfully send article
13861384
# (with reply)
13871385
for j, rar_msg_id in enumerate(rar_msg_ids):
@@ -1415,10 +1413,9 @@ def check_failure_status(rar_msg_ids, failed_limit, nzb_age):
14151413
m = socket_list.index(i)
14161414
for k in range(0, 8): # loop multiple so all data will be received
14171415
for i in socket_list[m:]: # loop through ok sockets
1418-
reply = None
1416+
reply = ""
14191417
try:
14201418
data = sockets[i].recv(chunk)
1421-
reply = ""
14221419
while data:
14231420
reply += data.decode("utf-8")
14241421
data = sockets[i].recv(chunk)
@@ -1476,13 +1473,20 @@ def check_failure_status(rar_msg_ids, failed_limit, nzb_age):
14761473
+ " marking request as failed."
14771474
)
14781475
sys.stdout.flush()
1479-
reply = "999 request marked as failed by script.".encode()
1476+
reply = "999 request marked as failed by script."
14801477
pass
14811478
if reply != None:
14821479
socket_loop_count[i] = 0
14831480
(error, id_used, server_reply, msg_id_used) = (
14841481
check_send_server_reply(
1485-
sockets[i], reply, group, id, i, host, username, password
1482+
sockets[i],
1483+
reply,
1484+
group,
1485+
id,
1486+
i,
1487+
host,
1488+
username,
1489+
password,
14861490
)
14871491
)
14881492
if error and server_reply in ("411", "420", "423", "430"):
@@ -1496,7 +1500,7 @@ def check_failure_status(rar_msg_ids, failed_limit, nzb_age):
14961500
+ " failed."
14971501
)
14981502
# found ok article on server, store success:
1499-
elif not error and server_reply == "223".encode():
1503+
elif not error and server_reply == "223":
15001504
# find row index for successfully send article
15011505
# (with recv reply)
15021506
for j, rar_msg_id in enumerate(rar_msg_ids):
@@ -1511,7 +1515,7 @@ def check_failure_status(rar_msg_ids, failed_limit, nzb_age):
15111515
+ str(failed_articles)
15121516
+ " failed."
15131517
)
1514-
elif not error and server_reply == "205".encode(encoding="utf-8"):
1518+
elif not error and server_reply == "205":
15151519
# socket closed in check_send_server_reply
15161520
socket_list.remove(i)
15171521
if failed_ratio != 100:

0 commit comments

Comments
 (0)