jenkins-bot has submitted this change and it was merged.
Change subject: Remove LockableCookieJar ......................................................................
Remove LockableCookieJar
The baseclass provides thread-safe locking, so an extra layer of locking is not needed.
Bug: T98670 Change-Id: Ifdc1d0ba19cce14dd00e8f9efc6b0a9dcec9e351 --- M pywikibot/comms/http.py M pywikibot/comms/threadedhttp.py M tests/http_tests.py 3 files changed, 13 insertions(+), 25 deletions(-)
Approvals: Merlijn van Deen: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/comms/http.py b/pywikibot/comms/http.py index e45c52b..b336a0a 100644 --- a/pywikibot/comms/http.py +++ b/pywikibot/comms/http.py @@ -89,7 +89,7 @@ connection_pool = threadedhttp.ConnectionPool() http_queue = Queue.Queue()
-cookie_jar = threadedhttp.LockableCookieJar( +cookie_jar = cookielib.LWPCookieJar( config.datafilepath("pywikibot.lwp")) try: cookie_jar.load() diff --git a/pywikibot/comms/threadedhttp.py b/pywikibot/comms/threadedhttp.py index a388c0f..69cf1f8 100644 --- a/pywikibot/comms/threadedhttp.py +++ b/pywikibot/comms/threadedhttp.py @@ -3,7 +3,7 @@
This class extends httplib2, adding support for: - Cookies, guarded for cross-site redirects - - Thread safe ConnectionPool and LockableCookieJar classes + - Thread safe ConnectionPool class - HttpProcessor thread class - HttpRequest object
@@ -125,15 +125,6 @@ self.lock.release()
-class LockableCookieJar(cookielib.LWPCookieJar): - - """CookieJar with integrated Lock object.""" - - def __init__(self, *args, **kwargs): - cookielib.LWPCookieJar.__init__(self, *args, **kwargs) - self.lock = threading.Lock() - - class Http(httplib2.Http):
"""Subclass of httplib2.Http that stores cookies. @@ -159,7 +150,8 @@ try: self.cookiejar = kwargs.pop('cookiejar') except KeyError: - self.cookiejar = LockableCookieJar() + self.cookiejar = cookielib.CookieJar() + try: self.connection_pool = kwargs.pop('connection_pool') except KeyError: @@ -195,11 +187,8 @@ # Prepare headers headers.pop('cookie', None) req = DummyRequest(uri, headers) - self.cookiejar.lock.acquire() - try: - self.cookiejar.add_cookie_header(req) - finally: - self.cookiejar.lock.release() + self.cookiejar.add_cookie_header(req) + headers = req.headers
# Wikimedia squids: add connection: keep-alive to request headers @@ -243,11 +232,7 @@ del self.connections[conn_key]
# First write cookies - self.cookiejar.lock.acquire() - try: - self.cookiejar.extract_cookies(DummyResponse(response), req) - finally: - self.cookiejar.lock.release() + self.cookiejar.extract_cookies(DummyResponse(response), req)
# Check for possible redirects redirectable_response = ((response.status == 303) or @@ -320,7 +305,7 @@
>>> from .http import Queue >>> queue = Queue.Queue() - >>> cookiejar = LockableCookieJar() + >>> cookiejar = cookielib.CookieJar() >>> connection_pool = ConnectionPool() >>> proc = HttpProcessor(queue, cookiejar, connection_pool) >>> proc.setDaemon(True) @@ -511,7 +496,7 @@
@param queue: The C{Queue.Queue} object that contains L{HttpRequest} objects. - @param cookiejar: The C{LockableCookieJar} cookie object to share among + @param cookiejar: The C{cookielib.CookieJar} cookie object to share among requests. @param connection_pool: The C{ConnectionPool} object which contains connections to share among requests. diff --git a/tests/http_tests.py b/tests/http_tests.py index f3255fd..a624cdb 100644 --- a/tests/http_tests.py +++ b/tests/http_tests.py @@ -24,10 +24,12 @@ from tests.utils import expected_failure_if
if sys.version_info[0] > 2: + from http import cookiejar as cookielib import queue as Queue
unicode = str else: + import cookielib import Queue
@@ -271,8 +273,9 @@ }
def test_threading(self): + """Test using threadedhttp.""" queue = Queue.Queue() - cookiejar = threadedhttp.LockableCookieJar() + cookiejar = cookielib.CookieJar() connection_pool = threadedhttp.ConnectionPool() proc = threadedhttp.HttpProcessor(queue, cookiejar, connection_pool) proc.setDaemon(True)
pywikibot-commits@lists.wikimedia.org