devunt has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/124285

Change subject: Ignore expired cookies
......................................................................

Ignore expired cookies

Bug: 63605
Change-Id: Ie04b1ecf43146eaaaa0253deecdb3347397b24a2
---
M login.py
M wikipedia.py
2 files changed, 11 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/compat 
refs/changes/85/124285/1

diff --git a/login.py b/login.py
index ebeccc7..ac0056c 100644
--- a/login.py
+++ b/login.py
@@ -59,6 +59,7 @@
 import query
 import wikipedia as pywikibot
 import config
+from datetime import datetime, timedelta
 
 # On some wikis you are only allowed to run a bot if there is a link to
 # the bot's user page in a specific list.
@@ -233,7 +234,7 @@
                 pywikibot.output(u"%s/%s\n%s" % (response.code, response.msg,
                                                  fakeresponsemsg))
 
-        Reat = re.compile(': (.*?)=(.*?);')
+        Reat = re.compile(': (.*?)=(.*?); (expires=(.*?);)?')
 
         L = {}
         if hasattr(response, 'sheaders'):
@@ -243,6 +244,10 @@
         for eat in ck:
             m = Reat.search(eat)
             if m:
+                exps = m.group(4)
+                if exps:
+                    if (datetime.strptime(exps, '%a, %d-%b-%Y %H:%M:%S %Z') - 
datetime.utcnow()) < timedelta(seconds=1):
+                        continue
                 L[m.group(1)] = m.group(2)
 
         got_token = got_user = False
diff --git a/wikipedia.py b/wikipedia.py
index 13ee2ab..1fe70ac 100644
--- a/wikipedia.py
+++ b/wikipedia.py
@@ -7116,11 +7116,15 @@
         else:
             ck = f.info().getallmatchingheaders('set-cookie')
         if ck:
-            Reat = re.compile(': (.*?)=(.*?);')
+            Reat = re.compile(': (.*?)=(.*?); (expires=(.*?);)?')
             tmpc = {}
             for d in ck:
                 m = Reat.search(d)
                 if m:
+                    exps= m.group(4)
+                    if exps:
+                        if (datetime.datetime.strptime(exps, '%a, %d-%b-%Y 
%H:%M:%S %Z') - datetime.datetime.utcnow()) < datetime.timedelta(seconds=1):
+                            continue
                     tmpc[m.group(1)] = m.group(2)
             if self.cookies(sysop):
                 self.updateCookies(tmpc, sysop)

-- 
To view, visit https://gerrit.wikimedia.org/r/124285
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie04b1ecf43146eaaaa0253deecdb3347397b24a2
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/compat
Gerrit-Branch: master
Gerrit-Owner: devunt <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to