Message 44432

Message id


> This sounds quiet complex and requires a lot of specific code.
> At the end, it is only about putting the right Authorization headers. I find that the Transport from xmlrpc.client could be a little bit more flexible and allow to take extra headers as parameter. I think it will be good to try to improve Python stdlib first.

xmlrpc.client has two classes: Transport and SafeTransport, and we
should to deal with it. I agree that it isn't really flexible.

but it isn't really a code duplication, even if we should provide
SessionTransport and SessionSafeTransport classes. SessionSafeTransport
could inherit from SessionTransport + SafeTransport to have the logic
for session handling while keeping the one for SSL.

> For the login/logout, they should already be available as common.db.login and common.db.logout.

yes they are available, but usage for common.db.login is a bit complex
to figure without example. Maybe proteus README should contains an
example of proper usage.

I attached a minimal diff, mostly for archival purpose:
- make XmlrpcConfig() to be usable with `with' syntax (it revokes
  session token on exit by calling common.db.logout)
- SessionTransport and SessionSafeTransport transport classes
- obtain_session() function as shortcut around common.db.login

Most of them (SessionTransport, SessionSafeTransport and
obtain_session()) could live outside proteus.

Usage could be something like:

import proteus
from proteus import Model
from proteus.config import SessionTransport

session = proteus.config.obtain_session('http://hostname/dbname/', 'username', 'password')
with proteus.config.set_xmlrpc('http://hostname/dbname/', transport=SessionTransport(session)) as config:
      Party = Model.get('')

or with ssl and specific context:

import proteus
import ssl
from proteus import Model
from proteus.config import SessionSafeTransport

context = ssl._create_default_https_context()
context.check_hostname = False
context.verify_mode = ssl.CERT_NONE

session = proteus.config.obtain_session('https://hostname/dbname/', 'username', 'password', context=context)
with proteus.config.set_xmlrpc('https://hostname/dbname/', transport=SessionSafeTransport(session, context=context)) as config:
	Party = Model.get('')


File name Uploaded Type Details
session-subclassing.diff semarie, 2018-10-16.10:27:47 text/plain view
Date User Action Args
2018-10-16 10:27:48semariesetrecipients: + ced
2018-10-16 10:27:48semarielinkissue7783 messages
2018-10-16 10:27:48semariecreate

Showing 10 items. Show all history (warning: this could be VERY long)