Avoid un-checked use of 'unicode' builtin.
| | |
| | | from hashlib import md5 |
| | | except ImportError: |
| | | from md5 import md5 |
| | | try: |
| | | STRING_TYPES = (str, unicode) |
| | | except NameError: #pragma NO COVER Python >= 3.0 |
| | | STRING_TYPES = (str,) |
| | | |
| | | from repoze.who._compat import get_cookies |
| | | from repoze.who._compat import STRING_TYPES |
| | |
| | | |
| | | |
| | | def maybe_encode(s, encoding='utf8'): |
| | | if isinstance(s, unicode): |
| | | if not isinstance(s, type(b'')): |
| | | s = s.encode(encoding) |
| | | return s |
| | | |
| | |
| | | |
| | | def asbool(obj): |
| | | # Lifted from paste.deploy.converters |
| | | if isinstance(obj, (str, unicode)): |
| | | if isinstance(obj, STRING_TYPES): |
| | | obj = obj.strip().lower() |
| | | if obj in ['true', 'yes', 'on', 'y', 't', '1']: |
| | | return True |
| | |
| | | 'Path=/' % new_val)) |
| | | |
| | | def test_remember_creds_different_unicode_userid(self): |
| | | from repoz.who._compat import u |
| | | plugin = self._makeOne('secret') |
| | | old_val = self._makeTicket(userid='userid') |
| | | environ = self._makeEnviron({'HTTP_COOKIE':'auth_tkt=%s' % old_val}) |
| | | userid = unicode('\xc2\xa9', 'utf-8') |
| | | userid = u('\xc2\xa9', 'utf-8') |
| | | new_val = self._makeTicket(userid=userid.encode('utf-8'), |
| | | userdata='userid_type:unicode') |
| | | result = plugin.remember(environ, {'repoze.who.userid':userid, |
| | |
| | | self.assertEqual(plugin.userid_checker, make_plugin) |
| | | |
| | | def test_remember_max_age_unicode(self): |
| | | try: |
| | | u = unicode |
| | | except NameError: |
| | | u = str |
| | | from repoz.who._compat import u |
| | | 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')}) |