Ignore:
Timestamp:
Mar 19, 2014, 11:11:30 AM (11 years ago)
Author:
dmik
Message:

python: Update vendor to 2.7.6.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/vendor/current/Lib/netrc.py

    r2 r388  
    33# Module and documentation by Eric S. Raymond, 21 Dec 1998
    44
    5 import os, shlex
     5import os, stat, shlex
     6if os.name == 'posix':
     7    import pwd
    68
    79__all__ = ["netrc", "NetrcParseError"]
     
    2224class netrc:
    2325    def __init__(self, file=None):
     26        default_netrc = file is None
    2427        if file is None:
    2528            try:
     
    2730            except KeyError:
    2831                raise IOError("Could not find .netrc: $HOME is not set")
    29         fp = open(file)
    3032        self.hosts = {}
    3133        self.macros = {}
     34        with open(file) as fp:
     35            self._parse(file, fp, default_netrc)
     36
     37    def _parse(self, file, fp, default_netrc):
    3238        lexer = shlex.shlex(fp)
    3339        lexer.wordchars += r"""!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~"""
     40        lexer.commenters = lexer.commenters.replace('#', '')
    3441        while 1:
    3542            # Look for a machine, default, or macdef top-level keyword
     
    3744            if not tt:
    3845                break
     46            elif tt[0] == '#':
     47                # seek to beginning of comment, in case reading the token put
     48                # us on a new line, and then skip the rest of the line.
     49                pos = len(tt) + 1
     50                lexer.instream.seek(-pos, 1)
     51                lexer.instream.readline()
     52                continue
    3953            elif tt == 'machine':
    4054                entryname = lexer.get_token()
     
    6276            while 1:
    6377                tt = lexer.get_token()
    64                 if (tt=='' or tt == 'machine' or
    65                     tt == 'default' or tt =='macdef'):
     78                if (tt.startswith('#') or
     79                    tt in {'', 'machine', 'default', 'macdef'}):
    6680                    if password:
    6781                        self.hosts[entryname] = (login, account, password)
     
    7892                    account = lexer.get_token()
    7993                elif tt == 'password':
     94                    if os.name == 'posix' and default_netrc:
     95                        prop = os.fstat(fp.fileno())
     96                        if prop.st_uid != os.getuid():
     97                            try:
     98                                fowner = pwd.getpwuid(prop.st_uid)[0]
     99                            except KeyError:
     100                                fowner = 'uid %s' % prop.st_uid
     101                            try:
     102                                user = pwd.getpwuid(os.getuid())[0]
     103                            except KeyError:
     104                                user = 'uid %s' % os.getuid()
     105                            raise NetrcParseError(
     106                                ("~/.netrc file owner (%s) does not match"
     107                                 " current user (%s)") % (fowner, user),
     108                                file, lexer.lineno)
     109                        if (prop.st_mode & (stat.S_IRWXG | stat.S_IRWXO)):
     110                            raise NetrcParseError(
     111                               "~/.netrc access too permissive: access"
     112                               " permissions must restrict access to only"
     113                               " the owner", file, lexer.lineno)
    80114                    password = lexer.get_token()
    81115                else:
Note: See TracChangeset for help on using the changeset viewer.