[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [gettor/master] Fix error and call backs in email message responder



commit 3ca7bdd1036d33cc4a5c41868a1c293ae49bc756
Author: hiro <hiro@xxxxxxxxxxxxxx>
Date:   Wed Oct 16 13:05:12 2019 +0200

    Fix error and call backs in email message responder
---
 gettor/parse/email.py   | 24 ++++++++++++------------
 gettor/parse/twitter.py | 16 ++++++++--------
 2 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/gettor/parse/email.py b/gettor/parse/email.py
index fdeefba..6783cc3 100644
--- a/gettor/parse/email.py
+++ b/gettor/parse/email.py
@@ -151,21 +151,21 @@ class EmailParser(object):
         return request
 
 
-    def check_num_requests(self, request_id, hid, request_service, limit):
+    def too_many_requests(self, request_id, hid, request_service, limit):
         # check limit first
         num_requests = limit
 
         if hid.hexdigest() == self.settings.get('test_hid'):
-            num_requests = 1
+            num_requests = 0
         else:
             num_requests = yield conn.get_num_requests(
                 id=hid.hexdigest(), service=request_service
             )
 
         if num_requests[0][0] < email_requests_limit:
-            return 1
-        else:
             return 0
+        else:
+            return 1
 
 
     def parse(self, msg_str):
@@ -240,7 +240,14 @@ class EmailParser(object):
                 "Found request for {}.".format(request['command']),
                 system="email parser"
             )
-            if self.check_num_requests(request['id'], hid, request['service'], email_requests_limit):
+            check = yield self.too_many_requests(request['id'], hid, request['service'], email_requests_limit):
+            if check
+                log.msg(
+                    "Discarded. Too many requests from {}.".format(
+                        hid.hexdigest()
+                    ), system="email parser"
+                )
+            else:
                 conn.new_request(
                     id=request['id'],
                     command=request['command'],
@@ -250,13 +257,6 @@ class EmailParser(object):
                     date=now_str,
                     status="ONHOLD",
                 )
-            else:
-                log.msg(
-                    "Discarded. Too many requests from {}.".format(
-                        hid.hexdigest()
-                    ), system="email parser"
-                )
-
         else:
             log.msg(
                 "Request not found",
diff --git a/gettor/parse/twitter.py b/gettor/parse/twitter.py
index 4da3961..a6b49f6 100644
--- a/gettor/parse/twitter.py
+++ b/gettor/parse/twitter.py
@@ -124,7 +124,14 @@ class TwitterParser(object):
                 id=str(request['id']), service=request['service']
             )
 
-            if num_requests[0][0] < twitter_requests_limit:
+            if num_requests[0][0] > twitter_requests_limit:
+                log.msg(
+                    "Discarded. Too many requests from {}.".format(
+                        hid.hexdigest()
+                    ), system="twitter parser"
+                )
+
+            else:
                 conn.new_request(
                     id=str(request['id']),
                     command=request['command'],
@@ -135,13 +142,6 @@ class TwitterParser(object):
                     status="ONHOLD",
                 )
 
-            else:
-                log.msg(
-                    "Discarded. Too many requests from {}.".format(
-                        hid.hexdigest()
-                    ), system="twitter parser"
-                )
-
 
     def parse_errback(self, error):
         """

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits