Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
6fe56a32
Commit
6fe56a32
authored
Jun 11, 2014
by
R David Murray
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#14758: add IPv6 support to smtpd.
Patch by Milan Oberkirch.
parent
1144da58
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
58 additions
and
15 deletions
+58
-15
Doc/library/smtpd.rst
Doc/library/smtpd.rst
+2
-2
Doc/whatsnew/3.5.rst
Doc/whatsnew/3.5.rst
+4
-0
Lib/smtpd.py
Lib/smtpd.py
+2
-1
Lib/test/mock_socket.py
Lib/test/mock_socket.py
+7
-4
Lib/test/test_smtpd.py
Lib/test/test_smtpd.py
+43
-8
No files found.
Doc/library/smtpd.rst
View file @
6fe56a32
...
...
@@ -68,8 +68,8 @@ SMTPServer Objects
.. versionchanged:: 3.4
The *map* argument was added.
.. versionchanged:: 3.5
the *decode_data* argument was added
.
.. versionchanged:: 3.5
the *decode_data* argument was added, and *localaddr*
and *remoteaddr* may now contain IPv6 addresses
.
DebuggingServer Objects
...
...
Doc/whatsnew/3.5.rst
View file @
6fe56a32
...
...
@@ -194,6 +194,10 @@ smtpd
is ``True`` for backward compatibility reasons, but will change to ``False``
in Python 3.6. (Contributed by Maciej Szulik in :issue:`19662`.)
* It is now possible to provide, directly or via name resolution, IPv6
addresses in the :class:`~smtpd.SMTPServer` constructor, and have it
successfully connect. (Contributed by Milan Oberkirch in :issue:`14758`.)
socket
------
...
...
Lib/smtpd.py
View file @
6fe56a32
...
...
@@ -610,7 +610,8 @@ class SMTPServer(asyncore.dispatcher):
self
.
_decode_data
=
decode_data
asyncore
.
dispatcher
.
__init__
(
self
,
map
=
map
)
try
:
self
.
create_socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
gai_results
=
socket
.
getaddrinfo
(
*
localaddr
)
self
.
create_socket
(
gai_results
[
0
][
0
],
gai_results
[
0
][
1
])
# try to re-use a server port if possible
self
.
set_reuse_addr
()
self
.
bind
(
localaddr
)
...
...
Lib/test/mock_socket.py
View file @
6fe56a32
...
...
@@ -35,8 +35,9 @@ class MockFile:
class
MockSocket
:
"""Mock socket object used by smtpd and smtplib tests.
"""
def
__init__
(
self
):
def
__init__
(
self
,
family
=
None
):
global
_reply_data
self
.
family
=
family
self
.
output
=
[]
self
.
lines
=
[]
if
_reply_data
:
...
...
@@ -108,8 +109,7 @@ class MockSocket:
def
socket
(
family
=
None
,
type
=
None
,
proto
=
None
):
return
MockSocket
()
return
MockSocket
(
family
)
def
create_connection
(
address
,
timeout
=
socket_module
.
_GLOBAL_DEFAULT_TIMEOUT
,
source_address
=
None
):
...
...
@@ -144,13 +144,16 @@ def gethostname():
def
gethostbyname
(
name
):
return
""
def
getaddrinfo
(
host
,
port
):
return
socket_module
.
getaddrinfo
(
host
,
port
)
gaierror
=
socket_module
.
gaierror
error
=
socket_module
.
error
# Constants
AF_INET
=
None
AF_INET
=
socket_module
.
AF_INET
AF_INET6
=
socket_module
.
AF_INET6
SOCK_STREAM
=
None
SOL_SOCKET
=
None
SO_REUSEADDR
=
None
Lib/test/test_smtpd.py
View file @
6fe56a32
...
...
@@ -36,7 +36,8 @@ class SMTPDServerTest(unittest.TestCase):
smtpd
.
socket
=
asyncore
.
socket
=
mock_socket
def
test_process_message_unimplemented
(
self
):
server
=
smtpd
.
SMTPServer
(
'a'
,
'b'
,
decode_data
=
True
)
server
=
smtpd
.
SMTPServer
((
support
.
HOST
,
0
),
(
'b'
,
0
),
decode_data
=
True
)
conn
,
addr
=
server
.
accept
()
channel
=
smtpd
.
SMTPChannel
(
server
,
conn
,
addr
,
decode_data
=
True
)
...
...
@@ -52,19 +53,39 @@ class SMTPDServerTest(unittest.TestCase):
def
test_decode_data_default_warns
(
self
):
with
self
.
assertWarns
(
DeprecationWarning
):
smtpd
.
SMTPServer
(
'a'
,
'b'
)
smtpd
.
SMTPServer
(
(
support
.
HOST
,
0
),
(
'b'
,
0
)
)
def
tearDown
(
self
):
asyncore
.
close_all
()
asyncore
.
socket
=
smtpd
.
socket
=
socket
class
TestFamilyDetection
(
unittest
.
TestCase
):
def
setUp
(
self
):
smtpd
.
socket
=
asyncore
.
socket
=
mock_socket
def
tearDown
(
self
):
asyncore
.
close_all
()
asyncore
.
socket
=
smtpd
.
socket
=
socket
@
unittest
.
skipUnless
(
support
.
IPV6_ENABLED
,
"IPv6 not enabled"
)
def
test_socket_uses_IPv6
(
self
):
server
=
smtpd
.
SMTPServer
((
support
.
HOSTv6
,
0
),
(
support
.
HOST
,
0
),
decode_data
=
False
)
self
.
assertEqual
(
server
.
socket
.
family
,
socket
.
AF_INET6
)
def
test_socket_uses_IPv4
(
self
):
server
=
smtpd
.
SMTPServer
((
support
.
HOST
,
0
),
(
support
.
HOSTv6
,
0
),
decode_data
=
False
)
self
.
assertEqual
(
server
.
socket
.
family
,
socket
.
AF_INET
)
class
SMTPDChannelTest
(
unittest
.
TestCase
):
def
setUp
(
self
):
smtpd
.
socket
=
asyncore
.
socket
=
mock_socket
self
.
old_debugstream
=
smtpd
.
DEBUGSTREAM
self
.
debug
=
smtpd
.
DEBUGSTREAM
=
io
.
StringIO
()
self
.
server
=
DummyServer
(
'a'
,
'b'
)
self
.
server
=
DummyServer
(
(
support
.
HOST
,
0
),
(
'b'
,
0
)
)
conn
,
addr
=
self
.
server
.
accept
()
self
.
channel
=
smtpd
.
SMTPChannel
(
self
.
server
,
conn
,
addr
,
decode_data
=
True
)
...
...
@@ -79,7 +100,9 @@ class SMTPDChannelTest(unittest.TestCase):
self
.
channel
.
handle_read
()
def
test_broken_connect
(
self
):
self
.
assertRaises
(
DummyDispatcherBroken
,
BrokenDummyServer
,
'a'
,
'b'
)
self
.
assertRaises
(
DummyDispatcherBroken
,
BrokenDummyServer
,
(
support
.
HOST
,
0
),
(
'b'
,
0
))
def
test_server_accept
(
self
):
self
.
server
.
handle_accept
()
...
...
@@ -513,11 +536,21 @@ class SMTPDChannelTest(unittest.TestCase):
self
.
channel
.
_SMTPChannel__addr
=
'spam'
def
test_decode_data_default_warning
(
self
):
server
=
DummyServer
(
'a'
,
'b'
)
server
=
DummyServer
(
(
support
.
HOST
,
0
),
(
'b'
,
0
)
)
conn
,
addr
=
self
.
server
.
accept
()
with
self
.
assertWarns
(
DeprecationWarning
):
smtpd
.
SMTPChannel
(
server
,
conn
,
addr
)
@
unittest
.
skipUnless
(
support
.
IPV6_ENABLED
,
"IPv6 not enabled"
)
class
SMTPDChannelIPv6Test
(
SMTPDChannelTest
):
def
setUp
(
self
):
smtpd
.
socket
=
asyncore
.
socket
=
mock_socket
self
.
old_debugstream
=
smtpd
.
DEBUGSTREAM
self
.
debug
=
smtpd
.
DEBUGSTREAM
=
io
.
StringIO
()
self
.
server
=
DummyServer
((
support
.
HOSTv6
,
0
),
(
'b'
,
0
))
conn
,
addr
=
self
.
server
.
accept
()
self
.
channel
=
smtpd
.
SMTPChannel
(
self
.
server
,
conn
,
addr
,
decode_data
=
True
)
class
SMTPDChannelWithDataSizeLimitTest
(
unittest
.
TestCase
):
...
...
@@ -525,7 +558,7 @@ class SMTPDChannelWithDataSizeLimitTest(unittest.TestCase):
smtpd
.
socket
=
asyncore
.
socket
=
mock_socket
self
.
old_debugstream
=
smtpd
.
DEBUGSTREAM
self
.
debug
=
smtpd
.
DEBUGSTREAM
=
io
.
StringIO
()
self
.
server
=
DummyServer
(
'a'
,
'b'
)
self
.
server
=
DummyServer
(
(
support
.
HOST
,
0
),
(
'b'
,
0
)
)
conn
,
addr
=
self
.
server
.
accept
()
# Set DATA size limit to 32 bytes for easy testing
self
.
channel
=
smtpd
.
SMTPChannel
(
self
.
server
,
conn
,
addr
,
32
,
...
...
@@ -576,7 +609,8 @@ class SMTPDChannelWithDecodeDataFalse(unittest.TestCase):
smtpd
.
socket
=
asyncore
.
socket
=
mock_socket
self
.
old_debugstream
=
smtpd
.
DEBUGSTREAM
self
.
debug
=
smtpd
.
DEBUGSTREAM
=
io
.
StringIO
()
self
.
server
=
DummyServer
(
'a'
,
'b'
,
decode_data
=
False
)
self
.
server
=
DummyServer
((
support
.
HOST
,
0
),
(
'b'
,
0
),
decode_data
=
False
)
conn
,
addr
=
self
.
server
.
accept
()
# Set decode_data to False
self
.
channel
=
smtpd
.
SMTPChannel
(
self
.
server
,
conn
,
addr
,
...
...
@@ -620,7 +654,8 @@ class SMTPDChannelWithDecodeDataTrue(unittest.TestCase):
smtpd
.
socket
=
asyncore
.
socket
=
mock_socket
self
.
old_debugstream
=
smtpd
.
DEBUGSTREAM
self
.
debug
=
smtpd
.
DEBUGSTREAM
=
io
.
StringIO
()
self
.
server
=
DummyServer
(
'a'
,
'b'
)
self
.
server
=
DummyServer
((
support
.
HOST
,
0
),
(
'b'
,
0
),
decode_data
=
True
)
conn
,
addr
=
self
.
server
.
accept
()
# Set decode_data to True
self
.
channel
=
smtpd
.
SMTPChannel
(
self
.
server
,
conn
,
addr
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment