[issue5645] test_memoryio fails for py3k on windows

Hirokazu Yamamoto report at bugs.python.org
Sat Apr 4 04:13:53 CEST 2009


Hirokazu Yamamoto <ocean-city at m2.ccsnet.ne.jp> added the comment:

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'.

----------
nosy: +ocean-city

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue5645>
_______________________________________


More information about the Python-bugs-list mailing list