r46895 - some cleanups
hawkowl-TA+aISz0psMTMxyoc4vAAJOcrHinNvQL0E9HWUfgJXw@public.gmane.org
| Newsgroups | gmane.comp.python.twisted.commits |
|---|---|
| Message-ID | <[email protected]> |
Author: hawkowl
Date: Thu Mar 3 09:03:39 2016
New Revision: 46895
Modified:
branches/conch-checkers-py3-8225/twisted/conch/checkers.py
branches/conch-checkers-py3-8225/twisted/python/compat.py
Log:
some cleanups
Modified: branches/conch-checkers-py3-8225/twisted/conch/checkers.py
==============================================================================
--- branches/conch-checkers-py3-8225/twisted/conch/checkers.py (original)
+++ branches/conch-checkers-py3-8225/twisted/conch/checkers.py Thu Mar 3 09:03:39 2016
@@ -43,8 +43,14 @@
def verifyCryptedPassword(crypted, pw):
"""
+ Check that the password, when crypted, matches the stored crypted password.
+
+ @param crypted: The stored crypted password.
@type crypted: L{str}
+ @param pw: The password the user has given.
@type pw: L{str}
+
+ @rtype: L{bool}
"""
return crypt.crypt(pw, crypted) == crypted
@@ -101,15 +107,17 @@
def requestAvatarId(self, credentials):
+ # We get bytes, but the Py3 pwd module uses str. So attempt to decode
+ # it using the same method that CPython does for the file on disk.
+ if _PY3:
+ username = credentials.username.decode(sys.getfilesystemencoding())
+ password = credentials.password.decode(sys.getfilesystemencoding())
+ else:
+ username = credentials.username
+ password = credentials.password
+
for func in self._getByNameFunctions:
try:
- if _PY3:
- # CPython decodes these using the default filesystem
- # encoding, but we want bytes, so encode it back.
- username = credentials.username.decode(
- sys.getfilesystemencoding())
- else:
- username = credentials.username
pwnam = func(username)
except KeyError:
return defer.fail(UnauthorizedLogin("invalid username"))
@@ -119,14 +127,6 @@
if crypted == '':
continue
- if _PY3:
- # CPython decodes these using the default filesystem
- # encoding, but we want bytes, so encode it back.
- password = credentials.password.decode(
- sys.getfilesystemencoding())
- else:
- password = credentials.password
-
if verifyCryptedPassword(crypted, password):
return defer.succeed(credentials.username)
# fallback
Modified: branches/conch-checkers-py3-8225/twisted/python/compat.py
==============================================================================
--- branches/conch-checkers-py3-8225/twisted/python/compat.py (original)
+++ branches/conch-checkers-py3-8225/twisted/python/compat.py Thu Mar 3 09:03:39 2016
@@ -574,9 +574,6 @@
def items(d):
return list(d.items())
- def _keys(d):
- return list(d.keys())
-
xrange = range
izip = zip
else:
@@ -589,9 +586,6 @@
def items(d):
return d.items()
- def _keys(d):
- return d.keys()
-
xrange = xrange
from itertools import izip
izip # shh pyflakes
@@ -618,13 +612,17 @@
@rtype: L{list}
"""
-_keys.__doc__ = """
-Return a list of the keys of C{d}.
-
-@type d: L{dict}
-@rtype: L{list}
-"""
+def _keys(d):
+ """
+ Return a list of the keys of C{d}.
+ @type d: L{dict}
+ @rtype: L{list}
+ """
+ if _PY3:
+ return list(d.keys())
+ else:
+ return d.keys()