@@ -480,7 +480,9 @@ def is_number(s):
480
480
return False
481
481
482
482
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
+ ):
484
486
"""
485
487
Check NNTP server messages, send data for next recv.
486
488
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):
508
510
"[E] check_send_server_reply(sock= "
509
511
+ str (sock )
510
512
+ ", t= "
511
- + str ( t )
513
+ + reply
512
514
+ " ,group= "
513
515
+ str (group )
514
516
+ " , id= "
@@ -521,7 +523,7 @@ def check_send_server_reply(sock, t, group, id, i, host, username, password):
521
523
id_used = False # is id used via HEAD / STAT request to NNTP server
522
524
msg_id_used = None
523
525
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
525
527
# no correct NNTP server code received, most likely still propagating?
526
528
if not is_number (server_reply ):
527
529
if VERBOSE :
@@ -531,7 +533,7 @@ def check_send_server_reply(sock, t, group, id, i, host, username, password):
531
533
+ " "
532
534
+ str (host )
533
535
+ ", NNTP reply incorrect:"
534
- + str (t .split ())
536
+ + str (reply .split ())
535
537
)
536
538
server_reply = "NNTP reply incorrect."
537
539
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):
550
552
+ " "
551
553
+ str (host )
552
554
+ ", NNTP reply: "
553
- + str (t .split ())
555
+ + str (reply .split ())
554
556
)
555
557
error = True # article is not there
556
558
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):
562
564
+ " "
563
565
+ str (host )
564
566
+ ", NNTP reply: "
565
- + str (t .split ())
567
+ + str (reply .split ())
566
568
)
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" ))
571
571
elif server_reply in ("221" ):
572
572
# 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
574
574
if EXTREME :
575
575
print (
576
576
"[E] Socket: "
577
577
+ str (i )
578
578
+ " "
579
579
+ str (host )
580
580
+ ", NNTP reply: "
581
- + str (t .split ())
581
+ + str (reply .split ())
582
582
)
583
583
elif server_reply in ("223" ):
584
584
# 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
586
586
if EXTREME :
587
587
print (
588
588
"[E] Socket: "
589
589
+ str (i )
590
590
+ " "
591
591
+ str (host )
592
592
+ ", NNTP reply: "
593
- + str (t .split ())
593
+ + str (reply .split ())
594
594
)
595
595
elif server_reply in ("200" , "201" ):
596
596
# 200 service available, posting permitted
@@ -602,14 +602,14 @@ def check_send_server_reply(sock, t, group, id, i, host, username, password):
602
602
+ " "
603
603
+ str (host )
604
604
+ ", NNTP reply: "
605
- + str (t .split ())
605
+ + str (reply .split ())
606
606
)
607
607
text = CHECK_METHOD + " <" + id + ">\r \n " # STAT is faster than HEAD
608
608
if EXTREME :
609
609
print (
610
610
"[E] Socket: " + str (i ) + " " + str (host ) + ", Send: " + str (text )
611
611
)
612
- sock .send (text .encode ())
612
+ sock .send (text .encode ("utf-8" ))
613
613
elif server_reply in ("381" ): # 381 Password required
614
614
text = "AUTHINFO PASS %s\r \n " % (password )
615
615
if EXTREME :
@@ -619,12 +619,12 @@ def check_send_server_reply(sock, t, group, id, i, host, username, password):
619
619
+ " "
620
620
+ str (host )
621
621
+ ", NNTP reply: "
622
- + str (t .split ())
622
+ + str (reply .split ())
623
623
)
624
624
print (
625
625
"[E] Socket: " + str (i ) + " " + str (host ) + ", Send: " + str (text )
626
626
)
627
- sock .send (text .encode ())
627
+ sock .send (text .encode ("utf-8" ))
628
628
elif server_reply in ("281" ): # 281 Authentication accepted
629
629
if EXTREME :
630
630
print (
@@ -633,7 +633,7 @@ def check_send_server_reply(sock, t, group, id, i, host, username, password):
633
633
+ " "
634
634
+ str (host )
635
635
+ ", NNTP reply: "
636
- + str (t .split ())
636
+ + str (reply .split ())
637
637
)
638
638
elif server_reply in ("211" ): # 211 group selected (group)
639
639
if EXTREME :
@@ -643,7 +643,7 @@ def check_send_server_reply(sock, t, group, id, i, host, username, password):
643
643
+ " "
644
644
+ str (host )
645
645
+ ", NNTP reply: "
646
- + str (t .split ())
646
+ + str (reply .split ())
647
647
)
648
648
elif server_reply in ("480" ): # 480 AUTHINFO required
649
649
text = "AUTHINFO USER %s\r \n " % (username )
@@ -654,12 +654,12 @@ def check_send_server_reply(sock, t, group, id, i, host, username, password):
654
654
+ " "
655
655
+ str (host )
656
656
+ ", NNTP reply: "
657
- + str (t .split ())
657
+ + str (reply .split ())
658
658
)
659
659
print (
660
660
"[E] Socket: " + str (i ) + " " + str (host ) + ", Send: " + str (text )
661
661
)
662
- sock .send (text .encode ())
662
+ sock .send (text .encode ("utf-8" ))
663
663
elif str (server_reply [:2 ]) in ("48" , "50" ):
664
664
# 48X or 50X incorrect news server account settings
665
665
print (
@@ -668,7 +668,7 @@ def check_send_server_reply(sock, t, group, id, i, host, username, password):
668
668
+ " "
669
669
+ str (host )
670
670
+ ", Incorrect news server account settings: "
671
- + str ( t )
671
+ + reply
672
672
)
673
673
elif server_reply in ("205" ): # NNTP Service exits normally
674
674
sock .close ()
@@ -679,7 +679,7 @@ def check_send_server_reply(sock, t, group, id, i, host, username, password):
679
679
+ " "
680
680
+ str (host )
681
681
+ ", NNTP reply: "
682
- + str (t .split ())
682
+ + str (reply .split ())
683
683
)
684
684
if VERBOSE :
685
685
print ("[V] Socket " + str (i ) + " closed." )
@@ -691,7 +691,7 @@ def check_send_server_reply(sock, t, group, id, i, host, username, password):
691
691
+ " "
692
692
+ str (host )
693
693
+ ", NNTP reply: "
694
- + str (t .split ())
694
+ + str (reply .split ())
695
695
)
696
696
error = True # article is assumed to be not there
697
697
id_used = True
@@ -703,7 +703,7 @@ def check_send_server_reply(sock, t, group, id, i, host, username, password):
703
703
+ " "
704
704
+ str (host )
705
705
+ ", Not covered NNTP server reply code: "
706
- + str (t .split ())
706
+ + str (reply .split ())
707
707
)
708
708
if VERBOSE or EXTREME :
709
709
sys .stdout .flush ()
@@ -724,10 +724,10 @@ def check_send_server_reply(sock, t, group, id, i, host, username, password):
724
724
print (
725
725
"[E] Socket: " + str (i ) + " " + str (host ) + ", Send: " + str (text )
726
726
)
727
- sock .send (text .encode ())
727
+ sock .send (text .encode ("utf-8" ))
728
728
elif end_loop and server_reply not in ("205" ):
729
729
text = "QUIT\r \n "
730
- sock .send (text .encode ())
730
+ sock .send (text .encode ("utf-8" ))
731
731
if EXTREME :
732
732
print (
733
733
"[E] Socket: " + str (i ) + " " + str (host ) + ", Send: " + str (text )
@@ -1322,9 +1322,7 @@ def check_failure_status(rar_msg_ids, failed_limit, nzb_age):
1322
1322
+ " marking requested article as failed."
1323
1323
)
1324
1324
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."
1328
1326
failed_wait_count += 1
1329
1327
if failed_wait_count >= 20 :
1330
1328
print (
@@ -1381,7 +1379,7 @@ def check_failure_status(rar_msg_ids, failed_limit, nzb_age):
1381
1379
# ID of missing article is not returned by server
1382
1380
failed_articles += 1
1383
1381
# 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" :
1385
1383
# find row index for successfully send article
1386
1384
# (with reply)
1387
1385
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):
1415
1413
m = socket_list .index (i )
1416
1414
for k in range (0 , 8 ): # loop multiple so all data will be received
1417
1415
for i in socket_list [m :]: # loop through ok sockets
1418
- reply = None
1416
+ reply = ""
1419
1417
try :
1420
1418
data = sockets [i ].recv (chunk )
1421
- reply = ""
1422
1419
while data :
1423
1420
reply += data .decode ("utf-8" )
1424
1421
data = sockets [i ].recv (chunk )
@@ -1476,13 +1473,20 @@ def check_failure_status(rar_msg_ids, failed_limit, nzb_age):
1476
1473
+ " marking request as failed."
1477
1474
)
1478
1475
sys .stdout .flush ()
1479
- reply = "999 request marked as failed by script." . encode ()
1476
+ reply = "999 request marked as failed by script."
1480
1477
pass
1481
1478
if reply != None :
1482
1479
socket_loop_count [i ] = 0
1483
1480
(error , id_used , server_reply , msg_id_used ) = (
1484
1481
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 ,
1486
1490
)
1487
1491
)
1488
1492
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):
1496
1500
+ " failed."
1497
1501
)
1498
1502
# found ok article on server, store success:
1499
- elif not error and server_reply == "223" . encode () :
1503
+ elif not error and server_reply == "223" :
1500
1504
# find row index for successfully send article
1501
1505
# (with recv reply)
1502
1506
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):
1511
1515
+ str (failed_articles )
1512
1516
+ " failed."
1513
1517
)
1514
- elif not error and server_reply == "205" . encode ( encoding = "utf-8" ) :
1518
+ elif not error and server_reply == "205" :
1515
1519
# socket closed in check_send_server_reply
1516
1520
socket_list .remove (i )
1517
1521
if failed_ratio != 100 :
0 commit comments