r46842 - Merge strcred-dist3-8216: port twisted.cred.strcred to Python 3.
mithrandi-TA+aISz0psMTMxyoc4vAAJOcrHinNvQL0E9HWUfgJXw@public.gmane.org
| Newsgroups | gmane.comp.python.twisted.commits |
|---|---|
| Message-ID | <[email protected]> |
Author: mithrandi
Date: Wed Feb 24 08:49:47 2016
New Revision: 46842
Added:
trunk/twisted/topfiles/8216.feature
Modified:
trunk/twisted/cred/checkers.py
trunk/twisted/cred/strcred.py
trunk/twisted/cred/test/test_strcred.py
trunk/twisted/python/dist3.py
Log:
Merge strcred-dist3-8216: port twisted.cred.strcred to Python 3.
Fixes: #8216
Author: hawkowl
Reviewer: mithrandi
Modified: trunk/twisted/cred/checkers.py
==============================================================================
--- trunk/twisted/cred/checkers.py (original)
+++ trunk/twisted/cred/checkers.py Wed Feb 24 08:49:47 2016
@@ -95,7 +95,7 @@
return defer.maybeDeferred(
credentials.checkPassword,
self.users[credentials.username]).addCallback(
- self._cbPasswordMatch, bytes(credentials.username))
+ self._cbPasswordMatch, credentials.username)
else:
return defer.fail(error.UnauthorizedLogin())
Modified: trunk/twisted/cred/strcred.py
==============================================================================
--- trunk/twisted/cred/strcred.py (original)
+++ trunk/twisted/cred/strcred.py Wed Feb 24 08:49:47 2016
@@ -1,4 +1,4 @@
-# -*- test-case-name: twisted.test.test_strcred -*-
+# -*- test-case-name: twisted.cred.test.test_strcred -*-
#
# Copyright (c) Twisted Matrix Laboratories.
# See LICENSE for details.
@@ -14,6 +14,8 @@
- unix
"""
+from __future__ import absolute_import, division
+
import sys
from zope.interface import Interface, Attribute
Modified: trunk/twisted/cred/test/test_strcred.py
==============================================================================
--- trunk/twisted/cred/test/test_strcred.py (original)
+++ trunk/twisted/cred/test/test_strcred.py Wed Feb 24 08:49:47 2016
@@ -8,7 +8,6 @@
from __future__ import absolute_import, division
import os
-from io import BytesIO
from twisted import plugin
from twisted.trial import unittest
@@ -19,6 +18,11 @@
from twisted.python.fakepwd import UserDatabase
from twisted.python.reflect import requireModule
+if compat._PY3:
+ from io import StringIO
+else:
+ from io import BytesIO as StringIO
+
try:
import crypt
except ImportError:
@@ -267,12 +271,12 @@
"""
def setUp(self):
- self.admin = credentials.UsernamePassword('admin', 'asdf')
- self.alice = credentials.UsernamePassword('alice', 'foo')
- self.badPass = credentials.UsernamePassword('alice', 'foobar')
- self.badUser = credentials.UsernamePassword('x', 'yz')
+ self.admin = credentials.UsernamePassword(b'admin', b'asdf')
+ self.alice = credentials.UsernamePassword(b'alice', b'foo')
+ self.badPass = credentials.UsernamePassword(b'alice', b'foobar')
+ self.badUser = credentials.UsernamePassword(b'x', b'yz')
self.filename = self.mktemp()
- FilePath(self.filename).setContent('admin:asdf\nalice:foo\n')
+ FilePath(self.filename).setContent(b'admin:asdf\nalice:foo\n')
self.checker = strcred.makeChecker('file:' + self.filename)
@@ -334,7 +338,7 @@
should produce a warning.
"""
oldOutput = cred_file.theFileCheckerFactory.errorOutput
- newOutput = BytesIO()
+ newOutput = StringIO()
cred_file.theFileCheckerFactory.errorOutput = newOutput
strcred.makeChecker('file:' + self._fakeFilename())
cred_file.theFileCheckerFactory.errorOutput = oldOutput
@@ -458,7 +462,7 @@
Test that the --help-auth argument correctly displays all
available authentication plugins, then exits.
"""
- newStdout = BytesIO()
+ newStdout = StringIO()
options = DummyOptions()
options.authOutput = newStdout
self.assertRaises(SystemExit, options.parseOptions, ['--help-auth'])
@@ -471,7 +475,7 @@
Test that the --help-auth-for argument will correctly display
the help file for a particular authentication plugin.
"""
- newStdout = BytesIO()
+ newStdout = StringIO()
options = DummyOptions()
options.authOutput = newStdout
self.assertRaises(
@@ -533,7 +537,8 @@
def setUp(self):
self.filename = self.mktemp()
- file(self.filename, 'w').write('admin:asdf\nalice:foo\n')
+ with open(self.filename, 'wb') as f:
+ f.write(b'admin:asdf\nalice:foo\n')
self.goodChecker = checkers.FilePasswordDB(self.filename)
self.badChecker = checkers.FilePasswordDB(
self.filename, hash=self._hash)
@@ -655,7 +660,7 @@
break
self.assertNotIdentical(invalidFactory, None)
# Capture output and make sure the warning is there
- newStdout = BytesIO()
+ newStdout = StringIO()
options.authOutput = newStdout
self.assertRaises(SystemExit, options.parseOptions,
['--help-auth-type', 'anonymous'])
@@ -667,11 +672,3 @@
"SSHCheckerTests", "UnixCheckerTests", "AnonymousCheckerTests",
"MemoryCheckerTests", "StrcredFunctionsTests", "PublicAPITests"
]
-
-
-if compat._PY3:
- __all3__ = ["SSHCheckerTests", "PublicAPITests", "StrcredFunctionsTests"]
- for name in __all__[:]:
- if name not in __all3__:
- globals()[name].skip = "Not yet ported to Python 3."
- del name, __all3__
Modified: trunk/twisted/python/dist3.py
==============================================================================
--- trunk/twisted/python/dist3.py (original)
+++ trunk/twisted/python/dist3.py Wed Feb 24 08:49:47 2016
@@ -59,6 +59,7 @@
"twisted.cred.credentials",
"twisted.cred.error",
"twisted.cred.portal",
+ "twisted.cred.strcred",
"twisted.cred.test",
"twisted.internet",
"twisted.internet._baseprocess",