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

Support TextReceiveStream(..., strip_newlines=True) #2

Open
mozesa opened this issue Jan 13, 2020 · 4 comments
Open

Support TextReceiveStream(..., strip_newlines=True) #2

mozesa opened this issue Jan 13, 2020 · 4 comments

Comments

@mozesa
Copy link

mozesa commented Jan 13, 2020

Hello oremanj,

I would like to ask for your kind help.

I use your tricycle library in one of my project with great pealsure. 👍

import trio
import tricycle


async def main():
    async with await trio.open_tcp_stream("192.168.0.1", 23) as tcp_stream:  # type: trio.SocketStream
        msg_stream = tricycle.TextReceiveStream(tcp_stream, "utf-8", newline="\r\n")
        async for msg in msg_stream:
            print(msg)


trio.run(main)

I only have a subtle issue, as you can see the new line character is "\r\n" and every message contains this character as well. What I mean is that msg == "#5G9803880F ###*071 RL30217638 *=\r\n". So currently I have to use msg.strip() method.
I think that there is no use leaving control characters in the messages themself.
And it would be super awesome to have messages without new line characters out-of-box. 😃

But off course it is up to you, I just would like to know your opinion about it.

Btw, I find very helpful the your discussion about of graceful shutdown.

Thanks for your help in advance.

@oremanj
Copy link
Owner

oremanj commented Jan 13, 2020

Hi, thanks for your interest! TextReceiveStream keeps the newlines in the output because regular Python file objects (io.TextIOWrapper, the thing you get bak from open()) keep the newlines; TextReceiveStream isn't implemented using regular Python file objects, but I thought it advisable to keep the same semantics, since most people's expectations will be based at some level on that. (Trio's async file objects are a wrapper around regular Python file objects, so they keep the newlines as well.)

I'd be willing to add a strip_newlines=True constructor argument in a future release, but the default will remain False.

@mozesa
Copy link
Author

mozesa commented Jan 13, 2020

Thank you so much for letting it know.

@mozesa mozesa closed this as completed Jan 13, 2020
@oremanj oremanj changed the title TextReceiveStream and the newline characters Support TextReceiveStream(..., strip_newlines=True) Jan 13, 2020
@oremanj
Copy link
Owner

oremanj commented Jan 13, 2020

Reopening to track strip_newlines=True.

@oremanj oremanj reopened this Jan 13, 2020
@mozesa
Copy link
Author

mozesa commented Apr 6, 2020

Up 👍

oremanj are you planning to release a new version with some crispy new features? 😄

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