aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorC. Scott Ananian <cscott@cscott.net>2014-08-13 14:35:42 -0400
committerMatěj Cepl <mcepl@cepl.eu>2024-09-04 00:27:30 +0200
commitc3a0255029531b672c369e732fd2ab47b112b462 (patch)
tree5ea11c6effd43dbb0863bb6335eaa2a63098a776 /src
parent0e6e5f5057832c42edb592916444fb6b96aacccc (diff)
downloadwikipediafs-c3a0255029531b672c369e732fd2ab47b112b462.tar.gz
Fix login on wikimedia foundation sites; fix test case in article.py.
Diffstat (limited to 'src')
-rw-r--r--src/wikipediafs/article.py28
-rw-r--r--src/wikipediafs/user.py24
2 files changed, 34 insertions, 18 deletions
diff --git a/src/wikipediafs/article.py b/src/wikipediafs/article.py
index c323ae4..e9adc56 100644
--- a/src/wikipediafs/article.py
+++ b/src/wikipediafs/article.py
@@ -244,14 +244,31 @@ if __name__ == "__main__":
import random
import sys
from user import User
-
+ import logging
+ logger = logging.getLogger("mydebuglogger")
+ logger.setLevel(logging.DEBUG)
+ hdlr = logging.StreamHandler()
+ hdlr.setLevel(logging.DEBUG)
+ formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
+ hdlr.setFormatter(formatter)
+ logger.addHandler(hdlr)
+
params = {
"host" : "www.mblondel.org",
"basename" : "/mediawiki/index.php",
- "https" : True
+ "https" : True,
+ "logger": logger
}
+ title = "Test"
+ destructive = True
- if len(sys.argv) == 3:
+ if True:
+ params["host"], params["basename"] = sys.argv[1], sys.argv[2]
+ user = User(sys.argv[3], sys.argv[4], **params)
+ params["cookie_str"] = user.getCookieString()
+ title = sys.argv[5]
+ destructive = False
+ elif len(sys.argv) == 3:
# Uses username and password if passed
user = User(sys.argv[1], sys.argv[2], **params)
params["cookie_str"] = user.getCookieString()
@@ -263,8 +280,9 @@ if __name__ == "__main__":
user = User(sys.argv[1], sys.argv[2], **params)
params["cookie_str"] = user.getCookieString()
- art = Article("Test", **params)
+ art = Article(title, **params)
print art.get()
- art.set("Test ! (%s)" % str(random.random()))
+ if destructive:
+ art.set("Test ! (%s)" % str(random.random()))
diff --git a/src/wikipediafs/user.py b/src/wikipediafs/user.py
index c28eb2d..5955476 100644
--- a/src/wikipediafs/user.py
+++ b/src/wikipediafs/user.py
@@ -138,19 +138,18 @@ class User:
conn.close()
printlog(self.logger, "debug", "cookie_list:")
- printlog(self.logger, "debug", cookies)
-
- if cookies.has_key('wikidbUserName'):
- cookie_str = ""
- for k, v in cookies.iteritems():
- if cookie_str == "":
- cookie_str = "%s=%s;" % (k, v)
- else:
- cookie_str += " %s=%s;" % (k, v)
- printlog(self.logger, "info", "Logged in successfully with username %s" % self.username)
- return cookie_str
+
+ cookies = [ cookie for cookie in cookies if
+ re.match(r'\w+Session=', cookie) or
+ cookie.startswith('centralauth_') ]
+ if len(cookies) > 0:
+ printlog(self.logger, "info",
+ "Logged in successfully with username %s" % self.username)
+ #self.logger.info("; ".join(cookies))
+ return "; ".join(cookies)
else:
- printlog(self.logger, "warning", "Could not log in with username %s" % self.username)
+ printlog(self.logger, "warning",
+ "Could not log in with username %s: %s" % (self.username, "; ".join(cookies)))
return None
@@ -186,4 +185,3 @@ if __name__ == "__main__":
user = User(sys.argv[3], password, **params)
user.getCookieString()
-