Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:not': 0.03; 'skip:[ 20': 0.04; '-*-': 0.07; 'attribute': 0.07; 'python3': 0.07; 'skip:p 60': 0.07; 'sys': 0.07; 'utf-8': 0.07; 'coding:': 0.09; 'subject:Python3': 0.09; 'python': 0.11; 'def': 0.12; '70,': 0.16; 'python3.': 0.16; 'sha1': 0.16; 'val,': 0.16; 'sender:addr:gmail.com': 0.17; 'app': 0.19; 'solution.': 0.20; 'subject:] ': 0.20; 'import': 0.22; 'error': 0.23; 'config': 0.24; 'skip:e 30': 0.24; 'correct': 0.29; '----': 0.29; 'patch': 0.29; "doesn't": 0.30; '8bit%:3': 0.30; 'skip:& 60': 0.30; 'message- id:@mail.gmail.com': 0.30; "i'm": 0.30; '(which': 0.31; 'code': 0.31; "skip:' 10": 0.31; 'python2.7': 0.31; 'anyone': 0.31; 'file': 0.32; 'run': 0.32; 'skip:- 50': 0.35; 'skip:s 30': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'skip:" 50': 0.36; 'hi,': 0.36; '8bit%:4': 0.38; 'skip:[ 10': 0.38; 'to:addr:python-list': 0.38; 'skip:- 10': 0.38; 'skip:& 20': 0.39; 'does': 0.39; 'subject:[': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.39; '8bit%:6': 0.40; 'even': 0.60; 'save': 0.62; 'here': 0.66; 'sample': 0.67; 'skip:w 60': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:date:message-id:subject:from:to:content-type; bh=x7NnzfW0deCP4q8pMPPJxf2ahpD05XY/z7IXVQh5qmc=; b=IkoiJL5HcpaiEJQ/8t0cTJqLS/CProI1T7JdgAYs7SpWtkF3zrwupscFNFKPJW81Ly X90sz9ESe9k/ymFoDERbTF1qU0GzgbwioLmeJ3eaz2b9Yl8MMoxfHaUkMS4ervBGiZ4c tSxXW7h6s2RXINXBgTi8/5y0jgVK/f+z/VUmV0qhXNrpt7MlM+UkdfkvuXEZhmcbb/uZ WyUXqk1P0u77LVpgy/rv05LmG3KlK8cSDgupK+bVD4giDTs/sN141BH4Y8SvX3SLCWTa RKf0pu2DKUKk+YvbHJhpcEZolpNvpzMsNJw0+mYX/Lj6bTx6jRT5gT6o3ZYvnCZCnvNv ZPug== MIME-Version: 1.0 X-Received: by 10.140.31.247 with SMTP id f110mr18106884qgf.58.1392439154485; Fri, 14 Feb 2014 20:39:14 -0800 (PST) Sender: kwatch@gmail.com Date: Sat, 15 Feb 2014 13:39:14 +0900 X-Google-Sender-Auth: D1TcLWd-AwxwB6gevSngnFGZ_UI Subject: [Q] Beaker 1.6.4 not work on Python3 From: Makoto Kuwata To: python-list@python.org Content-Type: multipart/alternative; boundary=001a113a9c022cb12204f26a81be X-Mailman-Approved-At: Sat, 15 Feb 2014 14:31:01 +0100 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 146 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1392471063 news.xs4all.nl 2879 [2001:888:2000:d::a6]:50721 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:66434 --001a113a9c022cb12204f26a81be Content-Type: text/plain; charset=ISO-8859-1 Hi, Does Beaker 1.6.4 work on Python3 ? Is there anyone using Beaker on Python3? I got the following error on Python 3.3: File "/opt/lang/python/3.2.2/lib/python3.2/http/cookies.py", line 486, in __setitem__ rval, cval = self.value_encode(value) File "/opt/lang/python/3.2.2/lib/python3.2/site-packages/Beaker-1.6.4-py3.2.egg/beaker/session.py", line 70, in value_encode sig = HMAC.new(self.secret, val.encode('UTF-8'), SHA1).hexdigest() AttributeError: 'bytes' object has no attribute 'encode' The following is a monkey patch to avoid this error, but I'm not sure that it is correct solution. from beaker.crypto import hmac as HMAC, hmac_sha1 as SHA1 from beaker.session import SignedCookie def value_encode(self, val): #sig = HMAC.new(self.secret, val.encode('UTF-8'), SHA1).hexdigest() sig = HMAC.new(self.secret, val, SHA1).hexdigest() return str(val), ("%s%s" % (sig, val)) SignedCookie.value_encode = value_encode And, even with monkey patching, Beaker's SessionMiddleware doesn't save session correctly on Python3. Please help me: I want to run Beaker 1.6.4 on Python 3. (Pyton 3.3.3, MacOSX) Here is my sample code (which works on Python2.7 very well!): ------------------------------------------------------ # -*- coding: utf-8 -*- import sys import waitress from beaker.middleware import SessionMiddleware def testapp(environ, start_response): session = environ.get('beaker.session') count = session.get('count', 0) + 1 session['count'] = count session.save() content = "count=%s" % count # start_response('200 OK', [('Content-Type', 'text/plain')]) return [content.encode('utf-8')] config = { 'session.type': 'cookie', 'session.validate_key': 'mysecretstring', } app = SessionMiddleware(testapp, config=config) ## monkey patch for Python3 python3 = sys.version_info[0] == 3 if 0 and python3: from beaker.crypto import hmac as HMAC, hmac_sha1 as SHA1 from beaker.session import SignedCookie def value_encode(self, val): #sig = HMAC.new(self.secret, val.encode('UTF-8'), SHA1).hexdigest() sig = HMAC.new(self.secret, val, SHA1).hexdigest() return str(val), ("%s%s" % (sig, val)) SignedCookie.value_encode = value_encode ## ---- waitress.serve(app, port=8080) ------------------------------------------------------ -- regards, makoto kuwata --001a113a9c022cb12204f26a81be Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Hi,

Does Beaker 1.6.4 work o= n Python3 ?
Is there anyone using Beaker on Python3?

I got the following error on Python 3.3:


=A0 File "/opt/lang/python/3.2.2/li= b/python3.2/http/cookies.py", line 486, in __setitem__
=A0 = =A0 rval, cval =3D self.value_encode(value)
=A0 File "/opt/l= ang/python/3.2.2/lib/python3.2/site-packages/Beaker-1.6.4-py3.2.egg/beaker/= session.py", line 70, in value_encode
=A0 =A0 sig =3D HMAC.new(self.secret, val.encode('UTF-8'), SHA= 1).hexdigest()
AttributeError: 'bytes' object has no attr= ibute 'encode'


The followin= g is a monkey patch to avoid this error,
but I'm not sure that it is correct solution.

=

=A0 =A0 from beaker.crypto import hmac as HMAC, hmac_sh= a1 as SHA1
=A0 =A0 from beaker.session import SignedCookie
<= div> =A0 =A0 def value_encode(self, val):
=A0 =A0 =A0 =A0 #sig =3D HMA= C.new(self.secret, val.encode('UTF-8'), SHA1).hexdigest()
=A0 =A0 =A0 =A0 sig =3D HMAC.new(self.secret, val, SHA1).hexdigest()=
=A0 =A0 =A0 =A0 return str(val), ("%s%s" % (sig, val))
=A0 =A0 SignedCookie.value_encode =3D value_encode


And, even with monkey patching, Beaker's SessionMi= ddleware
doesn't save session correctly on Python3.


Please help me: I want to run Beaker 1.6.4 on Pyt= hon 3.
(Pyton 3.3.3, MacOSX)

Here is my = sample code (which works on Python2.7 very well!):
--------------= ----------------------------------------
# -*- coding: utf-8 -*-

import sys
= import waitress
from beaker.middleware import SessionMiddleware

def testapp(environ, start_response):
=A0 =A0 session =3D environ.get('beaker.session')
=A0 =A0= count =3D session.get('count', 0) + 1
=A0 =A0 session[&#= 39;count'] =3D count
=A0 =A0 session.save()
=A0 =A0= content =3D "count=3D%s" % count
=A0 =A0 #
=A0 =A0 start_response('200 OK', [('Co= ntent-Type', 'text/plain')])
=A0 =A0 return [content.= encode('utf-8')]

config =3D {
= =A0 =A0 'session.type': 'cookie',
=A0 =A0 'session.validate_key': 'mysecretstring',
}
app =3D SessionMiddleware(testapp, config=3Dconfig)
=

## monkey patch for Python3
python3 =3D sys.v= ersion_info[0] =3D=3D 3
if 0 and python3:
=A0 =A0 from beaker.crypto import hmac as = HMAC, hmac_sha1 as SHA1
=A0 =A0 from beaker.session import Signed= Cookie
=A0 =A0 def value_encode(self, val):
=A0 =A0 =A0= =A0 #sig =3D HMAC.new(self.secret, val.encode('UTF-8'), SHA1).hexd= igest()
=A0 =A0 =A0 =A0 sig =3D HMAC.new(self.secret, val, SHA1).hexdigest()
=A0 =A0 =A0 =A0 return str(val), ("%s%s" % (sig, val))
=A0 =A0 SignedCookie.value_encode =3D value_encode
## --= --

waitress.serve(app, port=3D8080)
---------------------------= ---------------------------

--
regards,<= /div>
makoto kuwata

--001a113a9c022cb12204f26a81be--