python - Library needs to store object in a Web session: suggestions on API design -



python - Library needs to store object in a Web session: suggestions on API design -

i'm developing openid consumer library [1] job in 2 separate web requests:

when user requests authentication library discovers info url provided user. this info used during web request when library finishes authentication.

i want advice on how best design library api persisting "discovery information" between 2 requests:

i inquire caller provide own session object both calls , library store , read own object it:

result = openid.request(session, url) # stores discovery in `session` # ... openid.authenticate(session, auth_data) # reads discovery `session`

i don't aesthetically looks inversion of control: bring own buffer, we'll utilize you. also, "session" not well-defined interface , may expose limitations. example, sessions in django default want store json-serializable objects , object representing discovery info of custom class json doesn't recognize.

i homecoming discovery info caller , allow them deal see fit:

result, discovery = openid.request(url) session['openid.discovery'] = discovery # ... openid.authenticate(session['openid.discovery'], auth_data)

this makes library cleaner (no need invent session key names or session cleanup policies) moves job caller. okay if caller library code implementing openid behaviour web framework, not okay if caller application developer shouldn't bothered sort of book-keeping.

which approach best (for subjective definition of "best")? there one?

second approach cleaner, because:

normal homecoming values improve "out" arguments it doesn't restrict format of session object (in fact, there may no explicit session object @ all)

python openid api-design

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -