1. 09 Mar, 2016 1 commit
    • Alex Kerfoot's avatar
      Fix CreateString with already-encoded string or bytearray in Python 2.7. · 1e7310e6
      Alex Kerfoot authored
      There was no way to pass an already-encoded string to 
      `builder.CreateString` in Python 2.7:
      
      - Passing a `bytearray` raised a TypeError because `bytearray` was not
        recognized as an instance of `compat.binary_type`.
      - Passing a utf-8 encoded `str` would cause the string to be
        double-encoded, because `compat.string_types = (basestring,)` and
        `basestring` is the base class of `str` and `unicode`, so the logic
        would never reach the `elif isinstance(s, compat.binary_type)` case.
      - Converting a utf-8 encoded bytearray to `bytes` like
        `builder.CreateString(bytes(encoded_string))` does not work because
        in Python 2.7, bytes is just an alias for `str` so it behaves as
        above.
      
      This change allows either `bytes` or `bytearray` as an already-encoded
      string to be passed to `CreateString` in versions of Python that support
      `bytearray`, and falls back to `str` in older versions.
      
      In Python 2, it restricts unencoded string types to `unicode`, so `str`
      can be used as an encoded, binary representaiton.
      1e7310e6
  2. 07 Mar, 2016 5 commits
  3. 03 Mar, 2016 2 commits
  4. 26 Feb, 2016 5 commits
  5. 25 Feb, 2016 1 commit
  6. 22 Feb, 2016 4 commits
  7. 17 Feb, 2016 2 commits
  8. 12 Feb, 2016 2 commits
  9. 11 Feb, 2016 2 commits
  10. 10 Feb, 2016 2 commits
  11. 08 Feb, 2016 2 commits
  12. 03 Feb, 2016 2 commits
  13. 01 Feb, 2016 4 commits
  14. 29 Jan, 2016 1 commit
  15. 28 Jan, 2016 1 commit
  16. 22 Jan, 2016 1 commit
  17. 21 Jan, 2016 3 commits