Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

util._LazyHexFormatter() returns str in py2, bytes in py3 #715

Closed
FirefighterBlu3 opened this issue Jul 16, 2016 · 2 comments
Closed

util._LazyHexFormatter() returns str in py2, bytes in py3 #715

FirefighterBlu3 opened this issue Jul 16, 2016 · 2 comments

Comments

@FirefighterBlu3
Copy link

this results in TypeError: __str__ returned non-string (type bytes)

a simple fix that works for both py2 and 3 is to append .decode() as shown to ensure a string representation is returned for both versions.

class _LazyHexFormatter(object):
    """
    This is used to avoid calling binascii.hexlify() on data given to
    log.debug() calls unless debug is active (for example). Like::

        self.log.debug(
            "Some data: {octets}",
            octets=_LazyHexFormatter(os.urandom(32)),
        )
    """
    __slots__ = ('obj',)

    def __init__(self, obj):
        self.obj = obj

    def __str__(self):
        return binascii.hexlify(self.obj).decode()
@oberstet
Copy link
Contributor

ah, right.

actually, there is code dup here too : https://github.com/crossbario/autobahn-python/blob/master/autobahn/asyncio/util.py#L20

gonna fix both ..

@oberstet
Copy link
Contributor

fixed on master

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants