Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #105595 > unrolled thread

netrc and password containing whitespace

Started byLele Gaifax <lele@metapensiero.it>
First post2016-03-24 11:14 +0100
Last post2016-03-24 11:14 +0100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python


Contents

  netrc and password containing whitespace Lele Gaifax <lele@metapensiero.it> - 2016-03-24 11:14 +0100

#105595 — netrc and password containing whitespace

FromLele Gaifax <lele@metapensiero.it>
Date2016-03-24 11:14 +0100
Subjectnetrc and password containing whitespace
Message-ID<mailman.85.1458814481.2244.python-list@python.org>
Hi all,

I tried to insert an entry in my ~/.netrc for an account having a password
that contains a space, something like:

  machine my-host-name login myname password "My Password"

The standard library netrc module does not seem able to parse it, raising a
NetrcParseError. Other programs (Emacs, to mention one) do the right thing
with an entry like that.

Inspecting the module, I see that it explicitly put the quote chars (both
single and double, that is '"' and "'") in the shlex-based lexer's wordchars:

  def _parse(self, file, fp, default_netrc):
       lexer = shlex.shlex(fp)
       lexer.wordchars += r"""!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~"""
       lexer.commenters = lexer.commenters.replace('#', '')
       ...
       
Since the method read_token() state machine gives higher priority to wordchars
over quotes, it obviously cannot parse the quoted string correctly:

  ...
  elif self.posix and nextchar in self.escape:
      escapedstate = 'a'
      self.state = nextchar
  elif nextchar in self.wordchars:
      self.token = nextchar
      self.state = 'a'
  elif nextchar in self.quotes:
      if not self.posix:
          self.token = nextchar
      self.state = nextchar
  ...

I was not able to lookup an exact definition of netrc's syntax, so I wonder:
is the implementation somewhat flawed, or am I missing something?

Thanks in advance for any hint,
ciao, lele.
-- 
nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
lele@metapensiero.it  |                 -- Fortunato Depero, 1929.

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web