Skip to content

netrc: accept open file object as initialization argument #98235

@steelman

Description

@steelman

Feature or enhancement

Make netrc class accept open file object (io.TextIOBase subclass) as an initialization argument.

Pitch

Providing netrc data via StringIO makes it possible to retrieve it from a verity of different sources e.g. an encrypted file. With few additional lines lines of code .netrc becomes a secure password store.

import gpg

with open(file) as file_gpg:
    with gpg.Context() as c:
        plaintext = c.decrypt(file_gpg)[0]
        nrc_data = io.StringIO(plaintext.decode('utf-8'))
        nrc = netrc.netrc(nrc_data)
passwd = nrc.authenticators(hostname)[2]

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions