Message 44433

Author
ced
Date
2018-10-16.10:52:05
Message id
44433

Content

On 2018-10-16 10:27, Sebastien Marie wrote:
> > 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.

By duplication, I mean the code in ServerProxy.__init__ that decides
which Transport to use will need to be duplicated. That's why I prefer
that we improve Python stdlib instead. See the attached patch.

> > 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.

Indeed I think some glue code to nicely manage it is welcomed.

> 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('party.party')
>       ...

I think it will be better that the "obtain_session" was the context
manager instead of set_xmlrpc. It will login and also set the config and
restore the previous one at exit.

Files

File name Uploaded Type Details
xmlrpc-transport-headers.patch ced, 2018-10-16.10:52:05 text/plain view
History
Date User Action Args
2018-10-16 10:52:06cedsetrecipients: + semarie
2018-10-16 10:52:06cedlinkissue7783 messages
2018-10-16 10:52:05cedcreate

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