Iotic-Labs / py-ubjson

Universal Binary JSON draft-12 serializer for Python
Apache License 2.0
42 stars 12 forks source link

sys.stdin.buffer not always available - causes exception #1

Closed oberstet closed 8 years ago

oberstet commented 8 years ago

This is triggered from our unit tests on CPython 3.5.1 (with the binary extension):

autobahn/wamp/test/test_serializer.py:34: in <module>
    from autobahn.wamp import serializer
autobahn/wamp/serializer.py:501: in <module>
    import ubjson
../../../cpy351_6/lib/python3.5/site-packages/ubjson/__init__.py:29: in <module>
    from .encoder import dump, dumpb, EncoderException  # noqa
ubjson/encoder.py:23: in init ubjson.encoder (ubjson/encoder.py3.c:6793)
    ???
ubjson/compat.py:64: in init ubjson.compat (ubjson/compat.py3.c:1403)
    ???
E   AttributeError: 'DontReadFromInput' object has no attribute 'buffer'

When I (manually) disable the extension (by commenting ext_modules in setup.py):

autobahn/wamp/serializer.py:501: in <module>
    import ubjson
../../../cpy351_6/lib/python3.5/site-packages/py_ubjson-0.8.3-py3.5.egg/ubjson/__init__.py:29: in <module>
    from .encoder import dump, dumpb, EncoderException  # noqa
../../../cpy351_6/lib/python3.5/site-packages/py_ubjson-0.8.3-py3.5.egg/ubjson/encoder.py:23: in <module>
    from .compat import Mapping, Sequence, INTEGER_TYPES, UNICODE_TYPE, TEXT_TYPES, BYTES_TYPES
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

    """Python v2.7 (NOT 2.6) compatibility"""

    # pylint: disable=unused-import,invalid-name,redefined-variable-type,wrong-import-position,no-name-in-module
    # pylint: disable=import-error

    from sys import stderr, stdout, stdin, version_info

    PY2 = (version_info[0] == 2)

    if PY2:
        # pylint:disable=undefined-variable
        INTEGER_TYPES = (int, long)  # noqa
        UNICODE_TYPE = unicode  # noqa
        TEXT_TYPES = (str, unicode)  # noqa
        BYTES_TYPES = (str,)

        STDIN_RAW = stdin
        STDOUT_RAW = stdout
        STDERR_RAW = stderr

    else:
        INTEGER_TYPES = (int,)
        UNICODE_TYPE = str
        TEXT_TYPES = (str,)
        BYTES_TYPES = (bytes, bytearray)

>       STDIN_RAW = stdin.buffer  # pylint: disable=no-member
E       AttributeError: 'DontReadFromInput' object has no attribute 'buffer'

../../../cpy351_6/lib/python3.5/site-packages/py_ubjson-0.8.3-py3.5.egg/ubjson/compat.py:64: AttributeError
================================================================= 3 failed, 123 passed, 1 error in 0.71 seconds ==================================================================
make: *** [test_asyncio] Fehler 1
oberstet commented 8 years ago

actually, this might be a pytest issue .. still investigating

vtermanis commented 8 years ago

I think I've addressed the issue in the referenced commit on the dev-contrib branch. Could you please check whether this solves the problem you've described here?

oberstet commented 8 years ago

@vtermanis can confirm, that works!

vtermanis commented 8 years ago

Available in v0.8.4