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

txtorcon > 0.19.0 is returning unicode instead of strings when calling TorProtocol.get_info() #232

Open
hellais opened this issue Apr 28, 2017 · 2 comments

Comments

@hellais
Copy link
Contributor

hellais commented Apr 28, 2017

Since 0.19.0 get_info commands will return unicode values instead of strings. It could be that other people would also be a bit surprised by this fact, so at the very leasts some note should be added to the changelog to mention this or ideally (if there not a good reason to do so) restore the old behavior of returning strings.

Here is a minimal way to reproduce the issue:

import txtorcon
config = txtorcon.TorConfig()
def updates(prog, tag, summary):
    print "%d%%: %s" % (prog, summary)
proto = yield txtorcon.launch_tor(config, reactor, progress_updates=updates)
s = txtorcon.TorState(proto.tor_protocol)
state = yield s.post_bootstrap
result = yield state.protocol.get_info("address")
assert isinstance(result.values()[0], str)

The above snippet will succeed in txtorcon 0.18.0, while fail in txtorcon >= 0.19.0

@meejah
Copy link
Owner

meejah commented Apr 28, 2017

I'm not sure what we can/should do here?

In Python3, str is basically the same as unicode in Python2: a string with some encoding. We're just assuming everything is UTF8 because Tor doesn't declare encodings for anything, but does allow high-ASCII values in "strings" that come back ...

@meejah
Copy link
Owner

meejah commented Apr 28, 2017

The reason I think py3-str or unicode is the right answer for GETINFO (and most other things in tor-control-protocol) is because they're "things that get shown to users, or typed in by users" so they should be "a string with an encoding", not just raw bytes.

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

No branches or pull requests

2 participants