• Kirill Smelkov's avatar
    golang_str: Fix iter(bstr) to yield byte instead of unicode character · 8d76276c
    Kirill Smelkov authored
    In a72c1c1a (golang_str: bstr/ustr iteration) things were initially
    implemented to follow Go semantic exactly with bytestring iteration
    yielding unicode characters as explained in
    https://blog.golang.org/strings. However this makes bstr not a 100%
    drop-in compatible replacement for std str under py2, and even though my
    initial testing was saying this change does not affect programs in
    practice it turned out to be not the case.
    
    For example with bstr.__iter__ yielding unicode characters running
    gpython on py2 with builtin str patched to be bstr will break sometimes
    when importing uuid:
    
    There uuid reads 16 bytes from /dev/random and then wants to iterate
    those 16 bytes as single bytes and then expects that the length
    of the resulting sequence is exactly 16:
    
         int = long(('%02x'*16) % tuple(map(ord, bytes)), 16)
    
         ( https://github.com/python/cpython/blob/2.7-0-g8d21aa21f2c/Lib/uuid.py#L147 )
    
    which breaks if some of the read bytes...
    8d76276c