GitLab is used only for code review, issue tracking and project management. Canonical locations for source code are still https://gitweb.torproject.org/ https://git.torproject.org/ and git-rw.torproject.org.

Commit 12d12174 authored by Cecylia Bocovich's avatar Cecylia Bocovich

Update database function callers

Now that we've moved from the twisted adbapi, our database calls no
longer return deferred objects. This updates the callers to reflect our
new function signatures.
parent 3d6fb34e
......@@ -23,7 +23,6 @@ from email import message_from_string
from email.utils import parseaddr
from twisted.python import log
from twisted.internet import defer
from ..utils.db import SQLite3
from ..utils import validate_email
......@@ -54,8 +53,8 @@ class EmailParser(object):
self.settings = settings
self.dkim = dkim
self.to_addr = to_addr
self.locales = []
self.platforms = self.settings.get("platforms")
self.get_locales()
def normalize(self, msg):
# Normalization will convert <Alice Wonderland> alice@wonderland.net
......@@ -162,15 +161,11 @@ class EmailParser(object):
else:
return True
@defer.inlineCallbacks
def get_locales(self):
dbname = self.settings.get("dbname")
conn = SQLite3(dbname)
locales = yield conn.get_locales()
for l in locales:
self.locales.append(l[0])
self.locales = conn.get_locales()
def parse(self, msg_str):
"""
......@@ -218,7 +213,6 @@ class EmailParser(object):
return request
@defer.inlineCallbacks
def parse_callback(self, request):
"""
Callback invoked when the message has been parsed. It stores the
......@@ -247,12 +241,12 @@ class EmailParser(object):
system="email parser"
)
num_requests = yield conn.get_num_requests(
num_requests = conn.get_num_requests(
id=hid, service=request_service
)
check = self.too_many_requests(
hid, test_hid, num_requests[0][0], email_requests_limit
hid, test_hid, num_requests, email_requests_limit
)
if check:
......
......@@ -20,7 +20,6 @@ from datetime import datetime
import configparser
from twisted.python import log
from twisted.internet import defer
from ..utils.db import SQLite3
from ..utils import strings
......@@ -89,7 +88,6 @@ class TwitterParser(object):
return request
@defer.inlineCallbacks
def parse_callback(self, request):
"""
Callback invoked when the message has been parsed. It stores the
......@@ -115,11 +113,11 @@ class TwitterParser(object):
hid = hashlib.sha256(str(request['id']).encode('utf-8'))
# check limits first
num_requests = yield conn.get_num_requests(
num_requests = conn.get_num_requests(
id=hid.hexdigest(), service=request['service']
)
num_requests += yield conn.get_num_requests(
num_requests += conn.get_num_requests(
id=str(request['id']), service=request['service']
)
......
......@@ -151,11 +151,11 @@ class Sendmail(object):
"""
# Manage help and links messages separately
help_requests = yield self.conn.get_requests(
help_requests = self.conn.get_requests(
status="ONHOLD", command="help", service="email"
)
link_requests = yield self.conn.get_requests(
link_requests = self.conn.get_requests(
status="ONHOLD", command="links", service="email"
)
......@@ -183,12 +183,12 @@ class Sendmail(object):
body=body_msg
)
yield self.conn.update_stats(
self.conn.update_stats(
command="help", platform='', language='en',
service="email"
)
yield self.conn.remove_request(
self.conn.remove_request(
id=id, service="email", date=date
)
......@@ -214,7 +214,7 @@ class Sendmail(object):
locale = locales['en']['locale']
log.info("Getting links for {} {}.".format(platform, language))
links = yield self.conn.get_links(
links = self.conn.get_links(
platform=platform, language=language, status="ACTIVE"
)
......@@ -236,12 +236,12 @@ class Sendmail(object):
body=body_msg
)
yield self.conn.update_stats(
self.conn.update_stats(
command="links", platform=platform, language=language,
service="email"
)
yield self.conn.remove_request(
self.conn.remove_request(
id=id, service="email", date=date
)
......
......@@ -117,11 +117,11 @@ class Twitterdm(object):
).addCallback(tp.parse_callback).addErrback(tp.parse_errback)
# Manage help and links messages separately
help_requests = yield self.conn.get_requests(
help_requests = self.conn.get_requests(
status="ONHOLD", command="help", service="twitter"
)
link_requests = yield self.conn.get_requests(
link_requests = self.conn.get_requests(
status="ONHOLD", command="links", service="twitter"
)
......@@ -152,12 +152,12 @@ class Twitterdm(object):
message=body_msg
)
yield self.conn.update_stats(
self.conn.update_stats(
command="help", platform='', language='en',
service="twitter"
)
yield self.conn.update_request(
self.conn.update_request(
id=request[0], hid=hid.hexdigest(), status="SENT",
service="twitter", date=date
)
......@@ -186,7 +186,7 @@ class Twitterdm(object):
locale = locales[language]['locale']
log.info("Getting links for {}.".format(platform))
links = yield self.conn.get_links(
links = self.conn.get_links(
platform=platform, language=locale, status="ACTIVE"
)
......@@ -233,12 +233,12 @@ class Twitterdm(object):
message=body_msg
)
yield self.conn.update_stats(
self.conn.update_stats(
command="links", platform=platform, language=locale,
service="twitter"
)
yield self.conn.update_request(
self.conn.update_request(
id=request[0], hid=hid.hexdigest(), status="SENT",
service="twitter", date=date
)
......
......@@ -28,7 +28,6 @@ def process_email(message):
try:
ep = EmailParser(settings, "gettor@torproject.org")
yield ep.get_locales().addErrback(ep.parse_errback)
yield defer.maybeDeferred(
ep.parse, message
).addCallback(ep.parse_callback).addErrback(ep.parse_errback)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment