r46893 - porting

hawkowl-TA+aISz0psMTMxyoc4vAAJOcrHinNvQL0E9HWUfgJXw@public.gmane.org
Newsgroups gmane.comp.python.twisted.commits
Message-ID <[email protected]>
Author: hawkowl
Date: Thu Mar  3 08:53:13 2016
New Revision: 46893

Modified:
   branches/conch-checkers-py3-8225/twisted/conch/checkers.py
   branches/conch-checkers-py3-8225/twisted/conch/error.py
   branches/conch-checkers-py3-8225/twisted/conch/test/test_checkers.py
   branches/conch-checkers-py3-8225/twisted/python/compat.py
   branches/conch-checkers-py3-8225/twisted/python/dist3.py

Log:
porting

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 08:53:13 2016
@@ -8,7 +8,7 @@
 
 from __future__ import absolute_import, division
 
-import base64
+import sys
 import binascii
 import errno
 
@@ -20,7 +20,6 @@
     import crypt
 
 try:
-    # Python 2.5 got spwd to interface with shadow passwords
     import spwd
 except ImportError:
     spwd = None
@@ -33,7 +32,7 @@
 from twisted.cred.credentials import IUsernamePassword, ISSHPrivateKey
 from twisted.cred.error import UnauthorizedLogin, UnhandledCredentials
 from twisted.internet import defer
-from twisted.python.compat import _keys, _PY3
+from twisted.python.compat import _keys, _PY3, _b64decodebytes
 from twisted.python import failure, reflect, log
 from twisted.python.deprecate import deprecatedModuleAttribute
 from twisted.python.util import runAsEffectiveUser
@@ -58,6 +57,7 @@
 
     @param username: the username of the user to return the passwd database
         information for.
+    @type username: L{str}
     """
     if pwd is None:
         return None
@@ -72,6 +72,7 @@
 
     @param username: the username of the user to return the shadow database
         information for.
+    @type username: L{str}
     """
     if spwd is not None:
         f = spwd.getspnam
@@ -88,8 +89,8 @@
     databases of a compatible format.
 
     @ivar _getByNameFunctions: a C{list} of functions which are called in order
-        to valid a user.  The default value is such that the /etc/passwd
-        database will be tried first, followed by the /etc/shadow database.
+        to valid a user.  The default value is such that the C{/etc/passwd}
+        database will be tried first, followed by the C{/etc/shadow} database.
     """
     credentialInterfaces = IUsernamePassword,
 
@@ -103,7 +104,10 @@
         for func in self._getByNameFunctions:
             try:
                 if _PY3:
-                    username = credentials.username.decode('ascii')
+                    # 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)
@@ -116,7 +120,10 @@
                         continue
 
                     if _PY3:
-                        password = credentials.password.decode('ascii')
+                        # 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
 
@@ -222,7 +229,7 @@
                 if len(l2) < 2:
                     continue
                 try:
-                    if base64.decodestring(l2[1]) == credentials.blob:
+                    if _b64decodebytes(l2[1]) == credentials.blob:
                         return True
                 except binascii.Error:
                     continue

Modified: branches/conch-checkers-py3-8225/twisted/conch/error.py
==============================================================================
--- branches/conch-checkers-py3-8225/twisted/conch/error.py	(original)
+++ branches/conch-checkers-py3-8225/twisted/conch/error.py	Thu Mar  3 08:53:13 2016
@@ -7,8 +7,9 @@
 Maintainer: Paul Swartz
 """
 
-from twisted.cred.error import UnauthorizedLogin
+from __future__ import absolute_import, division
 
+from twisted.cred.error import UnauthorizedLogin
 
 
 class ConchError(Exception):

Modified: branches/conch-checkers-py3-8225/twisted/conch/test/test_checkers.py
==============================================================================
--- branches/conch-checkers-py3-8225/twisted/conch/test/test_checkers.py	(original)
+++ branches/conch-checkers-py3-8225/twisted/conch/test/test_checkers.py	Thu Mar  3 08:53:13 2016
@@ -15,7 +15,6 @@
     cryptSkip = None
 
 import os
-import base64
 
 from collections import namedtuple
 from io import BytesIO
@@ -23,6 +22,7 @@
 from zope.interface.verify import verifyObject
 
 from twisted.python import util
+from twisted.python.compat import _b64encodebytes
 from twisted.python.failure import Failure
 from twisted.python.reflect import requireModule
 from twisted.trial.unittest import TestCase
@@ -34,6 +34,7 @@
 from twisted.python.fakepwd import UserDatabase, ShadowDatabase
 from twisted.test.test_process import MockOS
 
+
 if requireModule('cryptography') and requireModule('pyasn1'):
     dependencySkip = None
     from twisted.conch.ssh import keys
@@ -162,9 +163,10 @@
 
     def setUp(self):
         self.checker = checkers.SSHPublicKeyDatabase()
-        self.key1 = base64.encodebytes(b"foobar")
-        self.key2 = base64.encodebytes(b"eggspam")
-        self.content = b"t1 %s foo\nt2 %s egg\n" % (self.key1, self.key2)
+        self.key1 = _b64encodebytes(b"foobar")
+        self.key2 = _b64encodebytes(b"eggspam")
+        self.content = (b"t1 " + self.key1 + b" foo\nt2 " + self.key2 +
+                        b" egg\n")
 
         self.mockos = MockOS()
         self.mockos.path = FilePath(self.mktemp())

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 08:53:13 2016
@@ -679,6 +679,12 @@
     "twisted.python.compat",
     "OrderedDict")
 
+if _PY3:
+    from base64 import encodebytes as _b64encodebytes
+    from base64 import decodebytes as _b64decodebytes
+else:
+    from base64 import encodestring as _b64encodebytes
+    from base64 import decodestring as _b64decodebytes
 
 
 __all__ = [
@@ -710,4 +716,7 @@
     "urlquote",
     "urlunquote",
     "cookielib",
+    "_keys",
+    "_b64encodebytes",
+    "_b64decodebytes",
 ]

Modified: branches/conch-checkers-py3-8225/twisted/python/dist3.py
==============================================================================
--- branches/conch-checkers-py3-8225/twisted/python/dist3.py	(original)
+++ branches/conch-checkers-py3-8225/twisted/python/dist3.py	Thu Mar  3 08:53:13 2016
@@ -47,6 +47,8 @@
     "twisted.application.strports",
     "twisted.application.test",
     "twisted.conch",
+    "twisted.conch.checkers",
+    "twisted.conch.error",
     "twisted.conch.ssh",
     "twisted.conch.ssh._cryptography_backports",
     "twisted.conch.ssh.common",
@@ -161,6 +163,7 @@
     "twisted.python.deprecate",
     "twisted.python.dist3",
     "twisted.python.failure",
+    "twisted.python.fakepwd",
     "twisted.python.filepath",
     "twisted.python.lockfile",
     "twisted.python.log",
@@ -249,6 +252,7 @@
     "twisted.application.test.test_internet",
     "twisted.application.test.test_service",
     "twisted.conch.test.test_keys",
+    "twisted.conch.test.test_checkers",
     "twisted.cred.test.test_cramauth",
     "twisted.cred.test.test_cred",
     "twisted.cred.test.test_digestauth",
@@ -466,9 +470,6 @@
     "twisted.names.root",
     # Echo is ported for twisted.application tests:
     "twisted.protocols.wire",
-    # Required by twisted.test.test_twistd
-    # https://twistedmatrix.com/trac/ticket/7958
-    "twisted.python.fakepwd",
     # Missing test coverage:
     "twisted.protocols.loopback",
     # Minimally used by setup3.py:
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.