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

subprocess: canonicalize env to bytes on Unix (Python3) #52886

Closed
vstinner opened this issue May 6, 2010 · 7 comments
Closed

subprocess: canonicalize env to bytes on Unix (Python3) #52886

vstinner opened this issue May 6, 2010 · 7 comments
Labels
stdlib Python modules in the Lib dir topic-unicode

Comments

@vstinner
Copy link
Member

vstinner commented May 6, 2010

BPO 8640
Nosy @pitrou, @vstinner
Dependencies
  • bpo-8513: subprocess: support bytes program name (POSIX)
  • Files
  • subprocess_canonalize_env.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 2010-05-18.20:41:52.649>
    created_at = <Date 2010-05-06.22:45:15.260>
    labels = ['library', 'expert-unicode']
    title = 'subprocess: canonicalize env to bytes on Unix (Python3)'
    updated_at = <Date 2010-05-18.20:41:52.648>
    user = 'https://github.com/vstinner'

    bugs.python.org fields:

    activity = <Date 2010-05-18.20:41:52.648>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2010-05-18.20:41:52.649>
    closer = 'vstinner'
    components = ['Library (Lib)', 'Unicode']
    creation = <Date 2010-05-06.22:45:15.260>
    creator = 'vstinner'
    dependencies = ['8513']
    files = ['17358']
    hgrepos = []
    issue_num = 8640
    keywords = ['patch']
    message_count = 7.0
    messages = ['105168', '105174', '105696', '105844', '105845', '105961', '106006']
    nosy_count = 3.0
    nosy_names = ['pitrou', 'vstinner', 'Arfrever']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue8640'
    versions = ['Python 3.2']

    @vstinner
    Copy link
    Member Author

    vstinner commented May 6, 2010

    Python 3.2 has now its os.environb, the bytes version of os.environ. subprocess should get a new envb argument to be able to use pure bytes environmental variables. Examples:

       subprocess.call([b'env], envb={b'PATH': b'/usr/bin'})

    and

       envb = os.environb.copy()
       envb[b'PATH'] = b'/usr/bin'
       subprocess.call([b'env], envb=envb)

    Specify both env and envb would raise an exception. envb should only be available on POSIX (as os.environb).

    Related issues: bpo-8513 (subprocess: support bytes program name) and bpo-8603 (os.environb).

    @vstinner vstinner added stdlib Python modules in the Lib dir topic-unicode labels May 6, 2010
    @pitrou
    Copy link
    Member

    pitrou commented May 6, 2010

    Why wouldn't you give byte variables in env too?

    @vstinner
    Copy link
    Member Author

    Why wouldn't you give byte variables in env too?

    The problem with the canonicalization to bytes is to choice of the preferred type. Eg. env={'PATH': 'a', b'PATH': b'b'}: should we use 'a', 'b' or raise an error?

    subprocess does already convert environ keys and values to bytes on Unix (in subprocess._execute_child() if _posixsubprocess module is present, and in posix_execve()).

    os.get_exec_path() should also support b'PATH' key.

    @vstinner
    Copy link
    Member Author

    pitou> Why wouldn't you give byte variables in env too?

    Ok, attached patch canonicalize env keys and values to bytes. If a variable is defined twice (str name, bytes name), a ValueError is raised.

    The patch depends on bpo-8513: it requires that os.get_exec_path() is patched to support b'PATH' key.

    @vstinner vstinner changed the title subprocess: add envb argument to Popen constructor (Python3, POSIX only) subprocess: canonicalize env to bytes on Unix (Python3) May 16, 2010
    @vstinner
    Copy link
    Member Author

    Python 3.1 accepts duplicate variables (str name, bytes name). It creates the two variables is a random order:

    >>> subprocess.call(['env'], env={'xx': 'str', b'xx': 'bytes'})
    xx=str
    xx=bytes
    0
    >>> subprocess.call(['env'], env={'xxx': 'str', b'xxx': 'bytes'})
    xxx=bytes
    xxx=str
    0

    @vstinner
    Copy link
    Member Author

    os.exeve() and os.exevpe() should also canonicalize env to bytes.

    os.exeve() and os.exevpe(), but not os._exevpe() to avoid doing it twice (once in subprocess, once in os._exevpe). Patch os._exevpe() is not enough because subprocess doesn't call it on Unix if _subprocessposix module is present.

    @vstinner
    Copy link
    Member Author

    My patch to fix bpo-8513 does also fix the examples of this issue and so I think that the canonicalization is no more needed. I will only reopen the issue if I find a good reason to apply the patch :-)

    @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 topic-unicode
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants