-----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 [EMAIL PROTECTED] 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@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 )