mediawiki-utilities / python-mwapi

Simple Python Wrapper around MediaWiki API
http://pythonhosted.org/mwapi
MIT License
30 stars 11 forks source link

mw:api:edit, 'token' versus 'text' parm order, ? #31

Closed MvGulik closed 6 years ago

MvGulik commented 6 years ago

At https://www.mediawiki.org/wiki/API:Edit is says:

Parameters ...

  • token: Edit token. Especially if you are not using the md5 parameter, the token should be sent as the last parameter, or at least after the text parameter, to prevent a bad edit from getting committed if transmission of the body is interrupted for some reason.

Is this "the token should be sent as the last parameter, or at least after the text parameter" supported by python-mwapi ? (bases on a bit of code browsing this seems to be a "no" to me, but I could be wrong)

If 'no', is this something that makes senses to support by python-mwapi ? (for pre https://www.python.org/dev/peps/pep-0468/ supporting python versions that is)

halfak commented 6 years ago

Hmm. This is really awkward to do. It's not clear to me what requests or urllib3 would do if you gave them an OrderedDict to encode as application/x-www-form-urlencoded data. I'm not seeing a clear place in the docs stating that order is respected. We might need to do our own encoding. That'd be icky.

MvGulik commented 6 years ago

I'm not seeing a clear place in the docs stating that order is respected.

Are your referring here to order preservation for/in/with requests or urllib3 ? (I would need to read up on that, if that is the case)

Using an OrderedDict seems to cumbersome to me too (I'm not an expert though).

As far as I see there are just a view cases where the position of some general parameters can matter in mediawiki api calls. Would adding the token parm as separate kw-parm in the final function be a workable option ?

def func(token=None, **rest_parms):
    print('-- '+'token', token) ## "-- token 222"
    print('-- '+'rest_parms', rest_parms) ## "-- rest_parms {'aaa': 111, 'ccc': 333}"

parms = {'aaa':111, 'token':222, 'ccc':333}
func(**parms)

Although technically this would not be order preserving, but defaulting to a presumed order for some general kw-parameters.

MvGulik commented 6 years ago

I take it my idea would be the icky one. Closing.