Giter VIP home page Giter VIP logo

Comments (3)

guyzmo avatar guyzmo commented on June 10, 2024

I'm interested in mostly the EventSourceClient part of this library. Why does the constructor build its own url from ssl, url, action, and target parameters, instead of a single url parameter? An SSE server can respond at any location, and it isn't clear what that URL should be.

well, I might have implemented the client in a too specialised way. Basically, the URL that's gonna be polled is built based on those parameters:

self._url = "%s://%s/%s/%s" % ("https" if ssl else "http", url, action, target)

so typically, action is poll per default, and target is the token, so that would be:

https://host.tld/poll/42:42:42:42:42:42

The callback being what you'd want to do with that URL. Per default, it's just logging the events being pushed by the server.

So a good idea would be to make EventSourceClient only caring about the idea of an URL, and create a function that would take all the URL parameters I designed and build the URL, so that building the singleton would look like:

    EventSourceClient(
                      url = build_token_action_url(
                                        base_url = url,
                                        action = args.action,
                                        target = args.token
                      ),
                      retry = args.retry,
                      keep_alive = args.keep_alive,
                      ssl = args.ssl,
                      validate_cert = args.validate_cert,
                      user = args.user,
                      password = args.password).poll()

then for your own needs, you'd only have to feed it the URL, and manufacture your callback function to pass to the constructor.

Would you mind if I forked your EventSourceClient code into a new repository (with credit and link back here), and updated it to be more generic and python 3 compatible?

Thank you for asking, but not only I wouldn't, but this code is GPL, so you're free to do so ☺

But I'd rather have you fork it, and make a PR to improve that code!

Though, I consider that library to have some tech debt due to its age (I mean it's four years old and I haven't been personally using it for over three years).
If I were to rewrite it today, I'd totally drop py2 and tornado support, and and write it towards asyncio and requests.

And I'd also write some pytest unit tests ☺

N.B.: I'm planning on coming to the FOSDEM, so maybe we could take half a day to pair code on this, if you're coming as well.
N.B.2: I'm zmo on freenode, feel free to PRIVMSG me!

from event-source-library.

ottomata avatar ottomata commented on June 10, 2024

Thanks for the response!

Actually, along the way I found https://github.com/btubbs/sseclient, which works pretty well for my purposes. Alas, I won't be at FOSDEM. I'm ottomata on freenode. :)

from event-source-library.

guyzmo avatar guyzmo commented on June 10, 2024

oh, cool, did not know.

Though I'd be happy to upgrade that lib and make it cool again ☺
Also it's (was?) the only lib to provide both server and client implementation 😉

from event-source-library.

Related Issues (14)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.