Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Zope: Dev

BrowserIdManager help!

 

 

Zope dev RSS feed   Index | Next | Previous | View Threaded


miles at jamkit

May 11, 2008, 1:20 PM

Post #1 of 2 (49 views)
Permalink
BrowserIdManager help!

Hi,

I am attempting to integrate a zope site with some other applications.

I'm trying to get another application to set the _ZopeId browser/session
cookie, so that users can move between the two with a single login.

This requires me to reproduce the code below, so a valid broser Id is
returned:

(from Products.Sessions.BrowserIdManager 505:512)

def getB64TStamp(
b2a=binascii.b2a_base64,gmtime=time.gmtime, time=time.time,
b64_trans=b64_trans, split=string.split,
TimeStamp=TimeStamp.TimeStamp, translate=string.translate
):
t=time()
ts=split(b2a(`TimeStamp(*gmtime(t)[:5]+(t%60,))`)[:-1],'=')[0]
return translate(ts, b64_trans)

Unfortunately, I don't know any C, and the TimeStamp function is only
available in C. I'm hoping someone can spare a few minutes to explain
how this function could be coded in python so I can understand it, and
produce a non-python function to return valid browser ids.

I hope that makes sense!

Thanks

Miles

_______________________________________________
Zope-Dev maillist - Zope-Dev[at]zope.org
http://mail.zope.org/mailman/listinfo/zope-dev
** No cross posts or HTML encoding! **
(Related lists -
http://mail.zope.org/mailman/listinfo/zope-announce
http://mail.zope.org/mailman/listinfo/zope )


tseaver at palladion

May 12, 2008, 8:34 AM

Post #2 of 2 (37 views)
Permalink
Re: BrowserIdManager help! [In reply to]

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Miles wrote:
> Hi,
>
> I am attempting to integrate a zope site with some other applications.
>
> I'm trying to get another application to set the _ZopeId browser/session
> cookie, so that users can move between the two with a single login.
>
> This requires me to reproduce the code below, so a valid broser Id is
> returned:
>
> (from Products.Sessions.BrowserIdManager 505:512)
>
> def getB64TStamp(
> b2a=binascii.b2a_base64,gmtime=time.gmtime, time=time.time,
> b64_trans=b64_trans, split=string.split,
> TimeStamp=TimeStamp.TimeStamp, translate=string.translate
> ):
> t=time()
> ts=split(b2a(`TimeStamp(*gmtime(t)[:5]+(t%60,))`)[:-1],'=')[0]
> return translate(ts, b64_trans)
>
> Unfortunately, I don't know any C, and the TimeStamp function is only
> available in C. I'm hoping someone can spare a few minutes to explain
> how this function could be coded in python so I can understand it, and
> produce a non-python function to return valid browser ids.
>
> I hope that makes sense!

This should do to get the eight-byte representation used by TimeStamp
(the value inside the backquotes):

- --------------------------- %< ---------------------------------------
import struct
from time import gmtime
from time import time

SCONV = 60.0 / float(1<<16) / float(1<<16)

def _toEightBytes(year, month, day, hour, minutes, seconds):
years_offset = year - 1900
months_offset = (years_offset * 12) + (month - 1)
days_offset = months_offset * 31 + (day - 1)
hours_offset = (days_offset * 24) + hour
minutes_offset = (hours_offset * 60) + minutes
seconds_exp = int(seconds / SCONV)
return struct.pack('>L',
minutes_offset) + struct.pack('>L', seconds_exp)

def TimeStamp__data(now=None):
""" Return the current time as an 8-byte string.
"""
if now is None:
now = time()
zulu = gmtime(now)
seconds = now % 60
args = zulu[:5] + (seconds,)
return _toEightBytes(*args)
- --------------------------- %< ---------------------------------------



Tres.
- --
===================================================================
Tres Seaver +1 540-429-0999 tseaver[at]palladion.com
Palladion Software "Excellence by Design" http://palladion.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFIKGNx+gerLs4ltQ4RAlQYAKDPZTJakP3crES4Bk3B06HAxJ1uTQCgn+Vm
oeZIFt1Whn2vxTmL4yrBFYg=
=u0+E
-----END PGP SIGNATURE-----

_______________________________________________
Zope-Dev maillist - Zope-Dev[at]zope.org
http://mail.zope.org/mailman/listinfo/zope-dev
** No cross posts or HTML encoding! **
(Related lists -
http://mail.zope.org/mailman/listinfo/zope-announce
http://mail.zope.org/mailman/listinfo/zope )

Zope dev RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact lists@gossamer-threads.com
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.