New submission from Skip Montanaro <skip.montan...@gmail.com>:

Not sure I can really call this a bug, however there is a behavioral change 
between 2.7 and at least 3.6 and 3.7 (probably earlier versions of the 3.x 
series as well). There is no spec for .netrc files that I can find, certainly 
nothing which mentions comment or blank lines. Still, Python's netrc file 
parser seems happy with both.

However, in 3.x a blank line followed immediately by a comment line containing 
actual comment text causes the parser to raise a parse error. I've attached two 
netrc files, netrc-comment-blank, and netrc-blank-comment, identical save for 
the ordering of a blank line and a comment line. Here's what a 2.7.14 session 
looks like:

Python 2.7.14 |Anaconda, Inc.| (default, Mar 27 2018, 17:29:31) 
[GCC 7.2.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import netrc
>>> rc = netrc.netrc(file="/home/skip/tmp/netrc-comment-blank")
>>> rc = netrc.netrc(file="/home/skip/tmp/netrc-blank-comment")

Here's 3.7.0:

Python 3.7.0 (default, Jun 28 2018, 13:15:42) 
[GCC 7.2.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import netrc
>>> rc = netrc.netrc(file="/home/skip/tmp/netrc-comment-blank")
>>> rc = netrc.netrc(file="/home/skip/tmp/netrc-blank-comment")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/skip/miniconda3/envs/python3/lib/python3.7/netrc.py", line 30, in 
__init__
    self._parse(file, fp, default_netrc)
  File "/home/skip/miniconda3/envs/python3/lib/python3.7/netrc.py", line 63, in 
_parse
    "bad toplevel token %r" % tt, file, lexer.lineno)
netrc.NetrcParseError: bad toplevel token 'Comment' 
(/home/skip/tmp/netrc-blank-comment, line 2)

----------
components: Library (Lib)
files: netrc-comment-blank
messages: 321779
nosy: skip.montanaro
priority: normal
severity: normal
stage: needs patch
status: open
title: Obscure netrc parser "bug"
type: behavior
versions: Python 3.6, Python 3.7, Python 3.8
Added file: https://bugs.python.org/file47696/netrc-comment-blank

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue34132>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to