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

shlex (or perhaps cStringIO) and unicode strings #43912

Closed
drylock mannequin opened this issue Aug 29, 2006 · 9 comments
Closed

shlex (or perhaps cStringIO) and unicode strings #43912

drylock mannequin opened this issue Aug 29, 2006 · 9 comments
Labels
stdlib Python modules in the Lib dir

Comments

@drylock
Copy link
Mannequin

drylock mannequin commented Aug 29, 2006

BPO 1548891
Nosy @birkenfeld, @pitrou
Files
  • cio.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 2011-10-22.19:32:33.825>
    created_at = <Date 2006-08-29.21:16:22.000>
    labels = ['library']
    title = 'shlex (or perhaps cStringIO) and unicode strings'
    updated_at = <Date 2011-10-23.02:38:02.332>
    user = 'https://bugs.python.org/drylock'

    bugs.python.org fields:

    activity = <Date 2011-10-23.02:38:02.332>
    actor = 'python-dev'
    assignee = 'none'
    closed = True
    closed_date = <Date 2011-10-22.19:32:33.825>
    closer = 'pitrou'
    components = ['Library (Lib)']
    creation = <Date 2006-08-29.21:16:22.000>
    creator = 'drylock'
    dependencies = []
    files = ['23492']
    hgrepos = []
    issue_num = 1548891
    keywords = ['patch']
    message_count = 9.0
    messages = ['29709', '29710', '146126', '146128', '146132', '146162', '146184', '146185', '146217']
    nosy_count = 4.0
    nosy_names = ['georg.brandl', 'drylock', 'pitrou', 'python-dev']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue1548891'
    versions = ['Python 2.7']

    @drylock
    Copy link
    Mannequin Author

    drylock mannequin commented Aug 29, 2006

    Python 2.5c1 (r25c1:51305, Aug 19 2006, 18:23:29)
    [GCC 4.1.2 20060814 (prerelease) (Debian 4.1.1-11)] on
    linux2

    (Also seen in 2.4)

    shlex.split do not like unicode strings:

    >>> shlex.split(u"foo")
    ['f\x00\x00\x00o\x00\x00\x00o\x00\x00\x00']

    The shlex code IMO suggests that it should accept
    unicode (as it checks for argument being an instance of
    basestring).

    Digging slightly into this, this seems to be a
    difference between StringIO and cStringIO. While
    cStringIO claims it accepts unicode as long as it
    encode too ASCII it gives invalid results:

    >>> sys.getdefaultencoding()
    'ascii'
    
    
    >>> cStringIO.StringIO(u'foo').getvalue()
    'f\x00\x00\x00o\x00\x00\x00o\x00\x00\x00'

    Perhaps cStringIO should .encode to ASCII encoding
    before consuming the input, as I can't imagine anyone
    cares about the above result (which I guess are the
    UCS-2 or UCS-4 characters).

    @drylock drylock mannequin closed this as completed Aug 29, 2006
    @drylock drylock mannequin assigned birkenfeld Aug 29, 2006
    @drylock drylock mannequin added the stdlib Python modules in the Lib dir label Aug 29, 2006
    @drylock drylock mannequin closed this as completed Aug 29, 2006
    @drylock drylock mannequin assigned birkenfeld Aug 29, 2006
    @drylock drylock mannequin added the stdlib Python modules in the Lib dir label Aug 29, 2006
    @birkenfeld
    Copy link
    Member

    Logged In: YES
    user_id=849994

    Thanks for your report, this is now fixed in rev. 52301,
    52302 (2.5).

    @pitrou
    Copy link
    Member

    pitrou commented Oct 21, 2011

    Still happens on latest 2.7:

    >>> from cStringIO import StringIO
    >>> sio = StringIO(u"abc")
    >>> sio.getvalue()
    'a\x00b\x00c\x00'

    @pitrou pitrou reopened this Oct 21, 2011
    @pitrou pitrou reopened this Oct 21, 2011
    @pitrou
    Copy link
    Member

    pitrou commented Oct 21, 2011

    And unsurprisingly so, since the fix was reverted in r56830 by Georg.

    @pitrou
    Copy link
    Member

    pitrou commented Oct 21, 2011

    Georg, is this patch ok to you?

    @birkenfeld
    Copy link
    Member

    If you think it's fine to change this behavior, then yes :)

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Oct 22, 2011

    New changeset 27ae7d4e1983 by Antoine Pitrou in branch '2.7':
    Issue bpo-1548891: The cStringIO.StringIO() constructor now encodes unicode
    http://hg.python.org/cpython/rev/27ae7d4e1983

    @pitrou
    Copy link
    Member

    pitrou commented Oct 22, 2011

    If you think it's fine to change this behavior, then yes :)

    Well, the "documented" behaviour makes no sense.
    Either it should raise TypeError or convert. Since write() converts, it's logical for the constructor to do so as well.

    @pitrou pitrou closed this as completed Oct 22, 2011
    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Oct 23, 2011

    New changeset 0b39f2486314 by Éric Araujo in branch '2.7':
    Note that the bpo-1548891 fix indirectly fixes shlex (bpo-6988, bpo-1170)
    http://hg.python.org/cpython/rev/0b39f2486314

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

    No branches or pull requests

    2 participants