Get modules importing, tests running (but failing) under Python 3.2.x.
| | |
| | | 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): |
| | |
| | | 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' |
| | |
| | | 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) |
| | |
| | | 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' % |
| | |
| | | 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, |
| | |
| | | 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: |
| | |
| | | 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'] |
| | |
| | | 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, []) |
| | |
| | | """ 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 |
| | |
| | | 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 |
| | |
| | | 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 |
| | |
| | | |
| | | 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): |
| | |
| | | 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. |
| | |
| | | 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) |
| | |
| | | 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) |
| | |
| | | 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( |