Uploaded image for project: 'Python Driver'
  1. Python Driver
  2. PYTHON-621

Python 3: read(0) on a GridOut instance returns a string instead of bytes

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 2.7
    • Affects Version/s: 2.6.3
    • Component/s: None
    • Labels:
    • Environment:
      Python 3.3.3

      Calling read(0) on a GridOut instance returns "" instead of b"" in Python 3.

      This is because read() checks for a zero size and always returns "", even though the function should always return bytes in Python 3: https://github.com/mongodb/mongo-python-driver/blob/master/gridfs/grid_file.py#L470

      I'm using a library (html5lib) that uses read(0) to determine if it should expect strings or bytes from the file object. So this inconsistency is leading it into handling the file data as strings when it should be handling it as bytes.

            kyle.erf Kyle Erf
            mabeyj Jimmy Mabey
            0 Vote for this issue
            3 Start watching this issue