Skip to content

Commit

Permalink
[FIX] Tokens: Return the csrf token, when such a token is requested
Browse files Browse the repository at this point in the history
With the new token system, most of the token names are now 'csrf'
tokens. So if the token name is unknown it uses a csrf token, but it
still looks for the original token name, which is of course not
present.

Change-Id: I38e326c0f5382a585fba11bc6cbfba1a3dffaca5
  • Loading branch information
xZise committed Sep 12, 2014
1 parent aec6beb commit a44818b
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions pywikibot/site.py
Expand Up @@ -1185,9 +1185,16 @@ class TokenWallet(object):
def __init__(self, site):
self.site = site
self.site._tokens = {}
# TODO: Fetch that from the API with paraminfo
self.special_names = set(['deleteglobalaccount', 'patrol', 'rollback',
'setglobalaccountstatus', 'userrights',
'watch'])

def __getitem__(self, key):
storage = self.site._tokens.setdefault(self.site.user(), {})
if (LV(self.site.version()) >= LV('1.24wmf19')
and key not in self.special_names):
key = 'csrf'
if key not in storage:
self.site.preload_tokens([key])
return storage[key]
Expand Down Expand Up @@ -2295,11 +2302,7 @@ def preload_tokens(self, types):
data = api.Request(site=self, action='tokens',
type='|'.join(types)).submit()
else:
# TODO: Fetch that from the API with paraminfo
special_names = set(['deleteglobalaccount', 'patrol', 'rollback',
'setglobalaccountstatus', 'userrights',
'watch'])
new_tokens = [token if token in special_names else 'csrf'
new_tokens = [token if token in self.tokens.special_names else 'csrf'
for token in types]
data = api.Request(action='query', meta='tokens',
type='|'.join(new_tokens)).submit()
Expand Down

0 comments on commit a44818b

Please sign in to comment.