This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ocean-city
Recipients kristjan.jonsson, ocean-city
Date 2009-04-04.02:13:51
SpamBayes Score 7.3402936e-07
Marked as misclassified No
Message-id <1238811233.51.0.911495113235.issue5645@psf.upfronthosting.co.za>
In-reply-to
Content
I'm sure, but with following test code,

def run(module):
    print("///////////////////////////////")
    print("//", module)
    memio = module.StringIO(newline=None)
    # The C StringIO decodes newlines in write() calls, but the Python
    # implementation only does when reading.  This function forces them to
    # be decoded for testing.
    def force_decode():
        memio.seek(0)
        print("-------->", repr(memio.getvalue()))
        memio.seek(0)
        print("========>", repr(memio.read()))
    def print_newlines():
        print(repr(memio.newlines))
    print_newlines() # None
    memio.write("a\n")
    force_decode()
    print_newlines() # "\n"
    memio.write("b\r\n")
    force_decode()
    print_newlines() # ("\n", "\r\n")
    memio.write("c\rd")
    force_decode()
    print_newlines() # ("\r", "\n", "\r\n")

def main():
    import _pyio, _io
    run(_pyio)
    run(_io)

if __name__ == '__main__':
    main()

//---------------------------------------------

I get result

///////////////////////////////
// <module '_pyio' from 'e:\python-dev\py3k\l
None
--------> 'a\r\n'
========> 'a\n'
'\r\n'
--------> 'a\r\nb\r\r\n'
========> 'a\nb\n\n'
('\r', '\r\n')
--------> 'a\r\nb\r\r\nc\rd'
========> 'a\nb\n\nc\nd'
('\r', '\r\n')
///////////////////////////////
// <module 'io' (built-in)>
None
--------> 'a\n'
========> 'a\n'
'\n'
--------> 'a\nb\n'
========> 'a\nb\n'
('\n', '\r\n')
--------> 'a\nb\nc\nd'
========> 'a\nb\nc\nd'
('\r', '\n', '\r\n')

//---------------------------------------------

Maybe universal new line decode behavior is inverse
between _pyio and _io?

That is, _pyio's write() converts '\n' to platform new line, and _io's
write() converts platform new line to '\n'.
History
Date User Action Args
2009-04-04 02:13:53ocean-citysetrecipients: + ocean-city, kristjan.jonsson
2009-04-04 02:13:53ocean-citysetmessageid: <1238811233.51.0.911495113235.issue5645@psf.upfronthosting.co.za>
2009-04-04 02:13:51ocean-citylinkissue5645 messages
2009-04-04 02:13:51ocean-citycreate