Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #66434

[Q] Beaker 1.6.4 not work on Python3

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 <kwatch@gmail.com>
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 <kwa@kuwata-lab.com>
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 <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.6994.1392471063.18130.python-list@python.org> (permalink)
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

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

[Q] Beaker 1.6.4 not work on Python3 Makoto Kuwata <kwa@kuwata-lab.com> - 2014-02-15 13:39 +0900

csiph-web