Tres Seaver
2012-03-18 6919cb8daf7c7f7291b8aa10a28334c1a61848e9
Get modules importing, tests running (but failing) under Python 3.2.x.
9 files modified
138 ■■■■■ changed files
repoze/who/_auth_tkt.py 53 ●●●● patch | view | raw | blame | history
repoze/who/_compat.py 11 ●●●● patch | view | raw | blame | history
repoze/who/api.py 2 ●●● patch | view | raw | blame | history
repoze/who/config.py 14 ●●●● patch | view | raw | blame | history
repoze/who/middleware.py 5 ●●●● patch | view | raw | blame | history
repoze/who/plugins/auth_tkt.py 32 ●●●●● patch | view | raw | blame | history
repoze/who/plugins/redirector.py 8 ●●●● patch | view | raw | blame | history
repoze/who/plugins/sql.py 4 ●●●● patch | view | raw | blame | history
repoze/who/plugins/tests/test_authtkt.py 9 ●●●●● patch | view | raw | blame | history
repoze/who/_auth_tkt.py
@@ -37,16 +37,27 @@
non-Python code run under Apache.
"""
try:
    from Cookie import SimpleCookie
except ImportError: #pragma NO COVER Python >= 3.0
    from http.cookies import SimpleCookie
import time as time_mod
try:
    from urllib import quote as url_quote
    from urllib import unquote as url_unquote
except ImportError: #pragma NO COVER Python >= 3.0
    from urllib.parse import quote as url_quote
    from urllib.parse import unquote as url_unquote
try:
    from hashlib import md5
except ImportError:
    from md5 import md5
import Cookie
#from paste import request
try:
    STRING_TYPES = (str, unicode)
except NameError:  #pragma NO COVER Python >= 3.0
    STRING_TYPES = (str,)
from repoze.who._compat import get_cookies
from urllib import quote as url_quote
from urllib import unquote as url_unquote
class AuthTicket(object):
@@ -106,15 +117,17 @@
            self.user_data)
    def cookie_value(self):
        v = '%s%08x%s!' % (self.digest(), int(self.time), url_quote(self.userid))
        v = '%s%08x%s!' % (self.digest(), int(self.time),
                           url_quote(self.userid))
        if self.tokens:
            v += self.tokens + '!'
        v += self.user_data
        return v
    def cookie(self):
        c = Cookie.SimpleCookie()
        c[self.cookie_name] = self.cookie_value().encode('base64').strip().replace('\n', '')
        c = SimpleCookie()
        c_val = self.cookie_value().encode('base64').strip().replace('\n', '')
        c[self.cookie_name] = c_val
        c[self.cookie_name]['path'] = '/'
        if self.secure:
            c[self.cookie_name]['secure'] = 'true'
@@ -144,7 +157,7 @@
    digest = ticket[:32]
    try:
        timestamp = int(ticket[32:40], 16)
    except ValueError, e:
    except ValueError as e:
        raise BadTicket('Timestamp is not a hex integer: %s' % e)
    try:
        userid, data = ticket[40:].split('!', 1)
@@ -363,7 +376,8 @@
        wild_domain = '.' + cur_domain
        expires = 'Sat, 01-Jan-2000 12:00:00 GMT'
        cookies = [
            ('Set-Cookie', '%s=""; Expires="%s"; Path=/' % (self.cookie_name, expires)),
            ('Set-Cookie', '%s=""; Expires="%s"; Path=/' %
             (self.cookie_name, expires)),
            ('Set-Cookie', '%s=""; Expires="%s"; Path=/; Domain=%s' %
             (self.cookie_name, expires, cur_domain)),
            ('Set-Cookie', '%s=""; Expires="%s"; Path=/; Domain=%s' %
@@ -372,6 +386,19 @@
        return cookies
def asbool(obj):
    # Lifted from paste.deploy.converters
    if isinstance(obj, (str, unicode)):
        obj = obj.strip().lower()
        if obj in ['true', 'yes', 'on', 'y', 't', '1']:
            return True
        elif obj in ['false', 'no', 'off', 'n', 'f', '0']:
            return False
        else:
            raise ValueError(
                "String is not true/false: %r" % obj)
    return bool(obj)
def make_auth_tkt_middleware(
    app,
    global_conf,
@@ -379,14 +406,14 @@
    cookie_name='auth_tkt',
    secure=False,
    include_ip=True,
    logout_path=None):
    logout_path=None,
    ):
    """
    Creates the `AuthTKTMiddleware
    <class-paste.auth.auth_tkt.AuthTKTMiddleware.html>`_.
    <class-repoze.who._auth_tkt.AuthTKTMiddleware.html>`_.
    ``secret`` is requird, but can be set globally or locally.
    ``secret`` is required, but can be set globally or locally.
    """
    from paste.deploy.converters import asbool
    secure = asbool(secure)
    include_ip = asbool(include_ip)
    if secret is None:
repoze/who/_compat.py
@@ -1,12 +1,11 @@
import sys
py3k = sys.version_info >= (3, 0)
import wsgiref.util
import wsgiref.headers
if py3k:
    from http.cookies import SimpleCookie
else:
try:
    from Cookie import SimpleCookie
    from Cookie import CookieError
except ImportError: #pragma NO COVER Python >= 3.0
    from http.cookies import SimpleCookie
    from http.cookies import CookieError
def REQUEST_METHOD(environ):
    return environ['REQUEST_METHOD']
repoze/who/api.py
@@ -70,7 +70,7 @@
        for name, value in supplied:
            try:
                verify(value, iface)
            except BrokenImplementation, why:
            except BrokenImplementation as why:
                why = str(why)
                raise ValueError(str(name) + ': ' + why)
            L = interface_registry.setdefault(iface, [])
repoze/who/config.py
@@ -1,8 +1,16 @@
""" Configuration parser
"""
from ConfigParser import ConfigParser
from ConfigParser import ParsingError
from StringIO import StringIO
import pdb; pdb.set_trace()
try:
    from ConfigParser import ConfigParser
    from ConfigParser import ParsingError
except ImportError: #pragma NO COVER Python >= 3.0
    from configparser import ConfigParser
    from configparser import ParsingError
try:
    from StringIO import StringIO
except ImportError: #pragma NO COVER Python >= 3.0
    from io import StringIO
import logging
from pkg_resources import EntryPoint
import sys
repoze/who/middleware.py
@@ -1,5 +1,8 @@
import logging
from StringIO import StringIO
try:
    from StringIO import StringIO
except ImportError: #pragma NO COVER Python >= 3.0
    from io import StringIO
import sys
from repoze.who.api import APIFactory
repoze/who/plugins/auth_tkt.py
@@ -4,13 +4,12 @@
import os
import time
from repoze.who._compat import get_cookies
import repoze.who._auth_tkt as auth_tkt
from zope.interface import implements
from repoze.who.interfaces import IIdentifier
from repoze.who.interfaces import IAuthenticator
from repoze.who._compat import get_cookies
import repoze.who._auth_tkt as auth_tkt
_NOW_TESTING = None  # unit tests can replace
def _now():  #pragma NO COVERAGE
@@ -22,17 +21,24 @@
    implements(IIdentifier, IAuthenticator)
    userid_type_decoders = {
        'int':int,
        'unicode':lambda x: utf_8_decode(x)[0],
        }
    userid_type_decoders = {'int':int}
    try:
        userid_type_decoders[unicode] = ('unicode',
                                         lambda x: utf_8_decode(x)[0])
    except NameError: #pragma NO COVER Python >= 3.0
        pass
    userid_type_encoders = {
        int: ('int', str),
        long: ('int', str),
        unicode: ('unicode', lambda x: utf_8_encode(x)[0]),
        }
    userid_type_encoders = {int: ('int', str)}
    try:
        userid_type_encoders[long] = ('int', str)
    except NameError: #pragma NO COVER Python >= 3.0
        pass
    try:
        userid_type_encoders[unicode] = ('unicode',
                                         lambda x: utf_8_encode(x)[0])
    except NameError: #pragma NO COVER Python >= 3.0
        pass
    def __init__(self, secret, cookie_name='auth_tkt',
                 secure=False, include_ip=False,
                 timeout=None, reissue_time=None, userid_checker=None):
repoze/who/plugins/redirector.py
@@ -1,12 +1,16 @@
import urlparse
try:
    import urlparse
except ImportError: #pragma NO COVER Python >= 3.0
    from urllib import parse as urlparse
import urllib
import cgi
from webob.exc import HTTPFound
from repoze.who._compat import construct_url, header_value
from zope.interface import implements
from repoze.who.interfaces import IChallenger
from repoze.who._compat import construct_url
from repoze.who._compat import header_value
class RedirectorPlugin(object):
    """ Plugin for issuing challenges as redirects to a configured URL.
repoze/who/plugins/sql.py
@@ -90,7 +90,7 @@
        raise ValueError('conn_factory must be specified')
    try:
        conn_factory = resolveDotted(conn_factory)(**kw)
    except Exception, why:
    except Exception as why:
        raise ValueError('conn_factory could not be resolved: %s' % why)
    if compare_fn is not None:
        compare_fn = resolveDotted(compare_fn)
@@ -107,7 +107,7 @@
        raise ValueError('conn_factory must be specified')
    try:
        conn_factory = resolveDotted(conn_factory)(**kw)
    except Exception, why:
    except Exception as why:
        raise ValueError('conn_factory could not be resolved: %s' % why)
    if filter is not None:
        filter = resolveDotted(filter)
repoze/who/plugins/tests/test_authtkt.py
@@ -559,14 +559,17 @@
        self.assertEqual(plugin.userid_checker, make_plugin)
    def test_remember_max_age_unicode(self):
        try:
            u = unicode
        except NameError:
            u = str
        plugin = self._makeOne('secret')
        environ = {'HTTP_HOST':'example.com'}
        
        tkt = self._makeTicket(userid='chris', userdata='')
        result = plugin.remember(environ, {'repoze.who.userid': 'chris',
                                           'max_age': u'500'})
        name,value = result.pop(0)
                                           'max_age': u('500')})
        name, value = result.pop(0)
        self.assertEqual('Set-Cookie', name)
        self.failUnless(isinstance(value, str))
        self.failUnless(