Skip to content

_PyCoreConfig: add stdio_encoding and stdio_errors #78666

Closed

Description

@vstinner
BPO 34485
Nosy @ncoghlan, @vstinner
PRs
  • bpo-34485: Add _PyCoreConfig.stdio_encoding #8881
  • bpo-34485: Enhance init_sys_streams() #8978
  • bpo-34485: Fix _Py_InitializeCore() for C locale coercion #8979
  • [3.7] bpo-34485: Fix _Py_InitializeCore() for C locale coercion (GH-8979) #8981
  • bpo-34485: Add _Py_ClearStandardStreamEncoding() #8982
  • bpo-34485: stdout uses surrogateescape on POSIX locale #8986
  • [3.7] bpo-34485: stdout uses surrogateescape on POSIX locale (GH-8986) #8987
  • bpo-34485, Windows: LC_CTYPE set to user preference #8988
  • bpo-34485: Emit C locale coercion warning later #9002
  • bpo-34485: Fix pymain_read_conf() LC_ALL locale #9041
  • bpo-34544: pymain_read_conf() don't change LC_ALL #9045
  • 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 2018-08-29.09:50:04.427>
    created_at = <Date 2018-08-23.23:44:09.419>
    labels = ['3.8']
    title = '_PyCoreConfig: add stdio_encoding and stdio_errors'
    updated_at = <Date 2018-09-03.15:32:34.723>
    user = 'https://github.com/vstinner'

    bugs.python.org fields:

    activity = <Date 2018-09-03.15:32:34.723>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2018-08-29.09:50:04.427>
    closer = 'vstinner'
    components = []
    creation = <Date 2018-08-23.23:44:09.419>
    creator = 'vstinner'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 34485
    keywords = ['patch']
    message_count = 15.0
    messages = ['323980', '324290', '324294', '324297', '324298', '324306', '324309', '324311', '324315', '324316', '324349', '324382', '324384', '324511', '324526']
    nosy_count = 2.0
    nosy_names = ['ncoghlan', 'vstinner']
    pr_nums = ['8881', '8978', '8979', '8981', '8982', '8986', '8987', '8988', '9002', '9041', '9045']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue34485'
    versions = ['Python 3.8']

    Activity

    1. vstinner commented on Aug 23, 2018

      @vstinner
      MemberAuthor

      Currently, the code to select the encoding and error handler of sys.stdin, sys.stdout and sys.stderr is run later in Py_Initialize(). I propose to move most of this code into _PyCoreConfig_Read() and add stdio_encoding and stdio_errors to _PyCoreConfig to easily let Python embedders to select the encoding.

      Attached PR implements this idea. During Py_Initialize(), the code still reads the LC_CTYPE locale to choose the error handler if stdio_errors is NULL. This check cannot be done earlier, since the LC_CTYPE locale is only set to the user locale in Py_Initialize(): after _PyCoreConfig_Read().

      The Py_SetStandardStreamEncoding() function has been added by Nick Coghlan in bpo-16129.

      This new pre-initialization API allows embedding
      applications like Blender to force a particular
      encoding and error handler for the standard IO streams.
      
    2. vstinner commented on Aug 28, 2018

      @vstinner
      MemberAuthor

      New changeset 9e4994d by Victor Stinner in branch 'master':
      bpo-34485: Enhance init_sys_streams() (GH-8978)
      9e4994d

    3. vstinner commented on Aug 28, 2018

      @vstinner
      MemberAuthor

      New changeset 2c8ddcf by Victor Stinner in branch 'master':
      bpo-34485: Fix _Py_InitializeCore() for C locale coercion (GH-8979)
      2c8ddcf

    4. vstinner commented on Aug 28, 2018

      @vstinner
      MemberAuthor

      New changeset 98c49c6 by Victor Stinner in branch '3.7':
      bpo-34485: Fix _Py_InitializeCore() for C locale coercion (GH-8979) (GH-8981)
      98c49c6

    5. vstinner commented on Aug 28, 2018

      @vstinner
      MemberAuthor

      New changeset 124b9eb by Victor Stinner in branch 'master':
      bpo-34485: Add _Py_ClearStandardStreamEncoding() (GH-8982)
      124b9eb

    6. vstinner commented on Aug 29, 2018

      @vstinner
      MemberAuthor

      New changeset 315877d by Victor Stinner in branch 'master':
      bpo-34485: stdout uses surrogateescape on POSIX locale (GH-8986)
      315877d

    7. vstinner commented on Aug 29, 2018

      @vstinner
      MemberAuthor

      New changeset 0b9ea4b by Victor Stinner in branch '3.7':
      [3.7] bpo-34485: stdout uses surrogateescape on POSIX locale (GH-8986) (GH-8987)
      0b9ea4b

    8. vstinner commented on Aug 29, 2018

      @vstinner
      MemberAuthor

      New changeset 177d921 by Victor Stinner in branch 'master':
      bpo-34485, Windows: LC_CTYPE set to user preference (GH-8988)
      177d921

    9. vstinner commented on Aug 29, 2018

      @vstinner
      MemberAuthor

      New changeset dfe0dc7 by Victor Stinner in branch 'master':
      bpo-34485: Add _PyCoreConfig.stdio_encoding (GH-8881)
      dfe0dc7

    10. vstinner commented on Aug 29, 2018

      @vstinner
      MemberAuthor

      Oh wow, I didn't expect that it would be so complicated to "just" get the encoding of sys.stdout... I had to fix many bugs to be able to do that!

    11. vstinner commented on Aug 29, 2018

      @vstinner
      MemberAuthor

      New changeset cf21504 by Victor Stinner in branch 'master':
      bpo-34485: Emit C locale coercion warning later (GH-9002)
      cf21504

    12. ncoghlan commented on Aug 30, 2018

      @ncoghlan
      Contributor

      Yeah, there were some good reasons I went with the relatively brute force option of provideding Blender with a new config API call back in bpo-16129 - as we've seen, actually fixing it properly has been a multi-year multi-person effort :)

    13. vstinner commented on Aug 30, 2018

      @vstinner
      MemberAuthor

      Yeah, there were some good reasons I went with the relatively brute force option of provideding Blender with a new config API call back in bpo-16129 - as we've seen, actually fixing it properly has been a multi-year multi-person effort :)

      Yeah, I see ;-) Thanks for Py_SetStandardStreamEncoding(), it fixed Blender use case!

    14. vstinner commented on Sep 3, 2018

      @vstinner
      MemberAuthor

      New changeset f01b2a1 by Victor Stinner in branch 'master':
      bpo-34544: Fix setlocale() in pymain_read_conf() (GH-9041)
      f01b2a1

    15. vstinner commented on Sep 3, 2018

      @vstinner
      MemberAuthor

      New changeset 73b00be by Victor Stinner in branch 'master':
      bpo-34544: pymain_read_conf() don't change LC_ALL (GH-9045)
      73b00be

    16. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions