Skip to content

Commit

Permalink
Merge branch 'trunk' into 9192-dmollerm-reverse_proxy_resource_docstring
Browse files Browse the repository at this point in the history
  • Loading branch information
wiml committed Nov 20, 2018
2 parents ce15faf + 8d18e4f commit cdac057
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 11 deletions.
11 changes: 11 additions & 0 deletions src/twisted/internet/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,17 @@ class ConnectionAborted(ConnectionLost):
@since: 11.1
"""

def __str__(self):
s = [(
"Connection was aborted locally using"
" ITCPTransport.abortConnection"
)]
if self.args:
s.append(': ')
s.append(' '.join(self.args))
s.append('.')
return ''.join(s)



class ConnectionDone(ConnectionClosed):
Expand Down
41 changes: 41 additions & 0 deletions src/twisted/internet/test/test_error.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright (c) Twisted Matrix Laboratories.
# See LICENSE for details.

"""
Tests for L{twisted.internet.error}
"""

from __future__ import division, absolute_import

from twisted.trial.unittest import SynchronousTestCase
from twisted.internet import error



class ConnectionAbortedTests(SynchronousTestCase):
"""
Tests for the L{twisted.internet.error.ConnectionAborted} exception.
"""
def test_str(self):
"""
The default message of L{ConnectionAborted} is a sentence which points
to L{ITCPTransport.abortConnection()}
"""
self.assertEqual(
("Connection was aborted locally"
" using ITCPTransport.abortConnection."),
str(error.ConnectionAborted()),
)


def test_strArgs(self):
"""
Any arguments passed to L{ConnectionAborted} are included in its
message.
"""
self.assertEqual(
("Connection was aborted locally using"
" ITCPTransport.abortConnection:"
" foo bar."),
str(error.ConnectionAborted('foo', 'bar')),
)
4 changes: 2 additions & 2 deletions src/twisted/logger/_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ def failure(self, format, failure=None, level=LogLevel.critical, **kwargs):
or::
d = deferredFrob(knob)
d.addErrback(lambda f: log.failure, "While frobbing {knob}",
f, knob=knob)
d.addErrback(lambda f: log.failure("While frobbing {knob}",
f, knob=knob))
This method is generally meant to capture unexpected exceptions in
code; an exception that is caught and handled somehow should be logged,
Expand Down
1 change: 1 addition & 0 deletions src/twisted/newsfragments/9125.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improved the exception text for mutually exclusive function arguments.
1 change: 1 addition & 0 deletions src/twisted/newsfragments/9334.doc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The errback example in the docstring of twisted.logger.Logger.failure has been corrected.
1 change: 1 addition & 0 deletions src/twisted/newsfragments/9522.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The message of twisted.internet.error.ConnectionAborted is no longer truncated.
5 changes: 4 additions & 1 deletion src/twisted/python/deprecate.py
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,10 @@ def wrapped(*args, **kwargs):
arguments = _passed(spec, args, kwargs)
for this, that in argumentPairs:
if this in arguments and that in arguments:
raise TypeError("nope")
raise TypeError(
("The %r and %r arguments to %s "
"are mutually exclusive.") %
(this, that, _fullyQualifiedName(wrappee)))
return wrappee(*args, **kwargs)
return wrapped
return wrapper
20 changes: 12 additions & 8 deletions src/twisted/test/test_sslverify.py
Original file line number Diff line number Diff line change
Expand Up @@ -1031,8 +1031,9 @@ def test_tlsProtocolsAtLeastWithMinimum(self):
insecurelyLowerMinimumTo=sslverify.TLSVersion.TLSv1_2,
)

# Best error message
self.assertEqual(e.exception.args, ("nope",))
self.assertIn('raiseMinimumTo', e.exception.args[0])
self.assertIn('insecurelyLowerMinimumTo', e.exception.args[0])
self.assertIn('exclusive', e.exception.args[0])


def test_tlsProtocolsNoMethodWithAtLeast(self):
Expand All @@ -1049,8 +1050,9 @@ def test_tlsProtocolsNoMethodWithAtLeast(self):
raiseMinimumTo=sslverify.TLSVersion.TLSv1_2,
)

# Best error message
self.assertEqual(e.exception.args, ("nope",))
self.assertIn('method', e.exception.args[0])
self.assertIn('raiseMinimumTo', e.exception.args[0])
self.assertIn('exclusive', e.exception.args[0])


def test_tlsProtocolsNoMethodWithMinimum(self):
Expand All @@ -1067,8 +1069,9 @@ def test_tlsProtocolsNoMethodWithMinimum(self):
insecurelyLowerMinimumTo=sslverify.TLSVersion.TLSv1_2,
)

# Best error message
self.assertEqual(e.exception.args, ("nope",))
self.assertIn('method', e.exception.args[0])
self.assertIn('insecurelyLowerMinimumTo', e.exception.args[0])
self.assertIn('exclusive', e.exception.args[0])


def test_tlsProtocolsNoMethodWithMaximum(self):
Expand All @@ -1085,8 +1088,9 @@ def test_tlsProtocolsNoMethodWithMaximum(self):
lowerMaximumSecurityTo=sslverify.TLSVersion.TLSv1_2,
)

# Best error message
self.assertEqual(e.exception.args, ("nope",))
self.assertIn('method', e.exception.args[0])
self.assertIn('lowerMaximumSecurityTo', e.exception.args[0])
self.assertIn('exclusive', e.exception.args[0])


def test_tlsVersionRangeInOrder(self):
Expand Down

0 comments on commit cdac057

Please sign in to comment.