Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nntplib is not IPv6-capable #46005

Closed
dmorr mannequin opened this issue Dec 19, 2007 · 17 comments
Closed

nntplib is not IPv6-capable #46005

dmorr mannequin opened this issue Dec 19, 2007 · 17 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@dmorr
Copy link
Mannequin

dmorr mannequin commented Dec 19, 2007

BPO 1664
Nosy @pitrou, @vstinner, @giampaolo
Files
  • nntplib_ipv6.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2009-05-14.21:23:38.409>
    created_at = <Date 2007-12-19.20:07:10.392>
    labels = ['type-bug', 'library']
    title = 'nntplib is not IPv6-capable'
    updated_at = <Date 2009-05-14.22:25:27.340>
    user = 'https://bugs.python.org/dmorr'

    bugs.python.org fields:

    activity = <Date 2009-05-14.22:25:27.340>
    actor = 'dmorr'
    assignee = 'none'
    closed = True
    closed_date = <Date 2009-05-14.21:23:38.409>
    closer = 'pitrou'
    components = ['Library (Lib)']
    creation = <Date 2007-12-19.20:07:10.392>
    creator = 'dmorr'
    dependencies = []
    files = ['9001']
    hgrepos = []
    issue_num = 1664
    keywords = ['patch']
    message_count = 17.0
    messages = ['58822', '78504', '78505', '78506', '78507', '78508', '78578', '78579', '78585', '78676', '84845', '84846', '84847', '85015', '85020', '87767', '87775']
    nosy_count = 5.0
    nosy_names = ['pitrou', 'vstinner', 'giampaolo.rodola', 'dmorr', 'morrowc']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue1664'
    versions = ['Python 2.6']

    @dmorr
    Copy link
    Mannequin Author

    dmorr mannequin commented Dec 19, 2007

    nntplib hardcodes AF_INET for the socket address family. This prevents
    it from using IPv6. Attached is a patch that converts NNTP.__init__() to
    use socket.create_connection(), which is IPv6-capable.

    @dmorr dmorr mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Dec 19, 2007
    @morrowc
    Copy link
    Mannequin

    morrowc mannequin commented Dec 30, 2008

    This patch doesn't appear to work for python2.5.1 ->

    Python 2.5.1 (r251:54863, Jun 15 2008, 18:24:51) 
    [GCC 4.3.0 20080428 (Red Hat 4.3.0-8)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> from nntplib import NNTP
    >>> conn = NNTP('newszilla6.xs4all.nl')
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/usr/lib/python2.5/nntplib.py", line 114, in __init__
        self.sock = socket.create_connection((host, port))
    AttributeError: 'module' object has no attribute 'create_connection'

    (at least for me it doesn't work...
    Linux hostnamehere 2.6.26.6-79.fc9.i686 #1 SMP Fri Oct 17 14:52:14 EDT
    2008 i686 i686 i386 GNU/Linux)

    I'd be happy to try something else, or debug in other ways it that'd
    help... This really ought to get fixed if possible.

    @dmorr
    Copy link
    Mannequin Author

    dmorr mannequin commented Dec 30, 2008

    Yes. The patch is against 2.6. It uses the socket.create_connection()
    helper function, which was added in 2.6. See http://svn.python.org/view?
    rev=54546&view=rev for the commit message.

    If you really want to apply it to 2.5, it's trivial to adapt the patch.
    Just replace the call to create_connection() with something like this:

        msg = "getaddrinfo returns an empty list"
        for res in getaddrinfo(host, port, 0, SOCK_STREAM):
            af, socktype, proto, canonname, sa = res
            sock = None
            try:
                sock = socket(af, socktype, proto)
                if timeout is not _GLOBAL_DEFAULT_TIMEOUT:
                    sock.settimeout(timeout)
                sock.connect(sa)
                self.sock = sock
        except error, msg:
            if sock is not None:
                sock.close()
    
        raise error, msg

    @morrowc
    Copy link
    Mannequin

    morrowc mannequin commented Dec 30, 2008

    oh crap :( I saw the 2.6 AFTER I posted the message :( sorry. grr, have
    to find a fix for 2.5 I suppose now.

    Thanks.

    @morrowc
    Copy link
    Mannequin

    morrowc mannequin commented Dec 30, 2008

    oy, and I'm not reading emails properly. I'll try the fix you propose
    for 2.5.

    @morrowc
    Copy link
    Mannequin

    morrowc mannequin commented Dec 30, 2008

    a possible fix for 2.5 is:

    morrowc@tweezer:/tmp$ diff -U3 nntplib.py.orig nntplib.py
    --- nntplib.py.orig     2008-12-30 01:06:14.000000000 -0500
    +++ nntplib.py  2008-12-30 01:07:33.000000000 -0500
    @@ -109,8 +109,19 @@
             """
             self.host = host
             self.port = port
    -        self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    -        self.sock.connect((self.host, self.port))
    +        msg = "getaddrinfo returns an empty list"
    +        for res in socket.getaddrinfo(self.host, self.port, 0, 
    socket.SOCK_STREAM):
    +          af, socktype, proto, canonname, sa = res
    +          sock = None
    +          try:
    +            self.sock = socket.socket(af, socktype, proto)
    +            self.sock.connect(sa)
    +
    +          except error, msg:
    +            if self.sock is not None:
    +                self.sock.close()
    +            raise NNTPError, msg
    +
             self.file = self.sock.makefile('rb')
             self.debugging = 0
             self.welcome = self.getresp()

    I'll open a bug against 2.5 now with this.

    @vstinner
    Copy link
    Member

    I like nntplib_ipv6.patch: it's a generic solution (may support
    address families other than IPv6) and reuse code
    (socket.create_connection()) is always a good thing :-)

    @vstinner
    Copy link
    Member

    About Python 2.5: this branch doesn't accept bugfix anymore, only
    security issues. So only Python 2.6+ and 3.0+ can be patched.

    @morrowc
    Copy link
    Mannequin

    morrowc mannequin commented Dec 31, 2008

    Are we sure that the 2.6 fix (in the patch) will make it into 2.6? (and
    the right upstream patching will happen to the 3.0 code as well?)

    @pitrou
    Copy link
    Member

    pitrou commented Jan 1, 2009

    I was going to suggest writing a test but I see that nntplib hasn't got
    a single unit test :-O

    @dmorr
    Copy link
    Mannequin Author

    dmorr mannequin commented Mar 31, 2009

    Any chance of this being applied soon? It's been sitting in the
    bugtracker for over a year now.

    @vstinner
    Copy link
    Member

    @dmorr: It would be faster if nntplib has some tests :-/

    @dmorr
    Copy link
    Mannequin Author

    dmorr mannequin commented Mar 31, 2009

    I'm confused by that.

    In order to apply a 3 line patch (which replaces one standard library
    function with another), you want an entire test suite written for
    nntplib?

    If we're willing to accept that nttplib works reasonably well now, why
    is the testsuite necessary? socket.create_connection() is already used
    in several other modules.

    @morrowc
    Copy link
    Mannequin

    morrowc mannequin commented Apr 1, 2009

    This is a little silly and painful... it's utterly broken to hardcode
    the AF type in this way, could we please apply a patch (something like
    the proposed seems to work fine) and get this rolled into the next release?

    It seems really lame to not be able to support normal internet protocols
    in a tools language.

    @pitrou
    Copy link
    Member

    pitrou commented Apr 1, 2009

    Assuming the patch does work, +1 for applying it.

    @pitrou
    Copy link
    Member

    pitrou commented May 14, 2009

    Your patch is committed in r72640. Thanks!

    @pitrou pitrou closed this as completed May 14, 2009
    @dmorr
    Copy link
    Mannequin Author

    dmorr mannequin commented May 14, 2009

    Thanks.

    Is there any chance of getting bug 1655 fixed as well? imaplib has the
    same issue as nntplib, and the patch is identical.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants