Code Monkey home page Code Monkey logo

sse's Introduction

sse

Server Sent Events protocol implemetation on python2 and python3 in the same codebase.

Python tested versions:

  • Python 2.7.x
  • Python 3.2.x
  • PyPy 1.9.0r

Api documentation:

Sse.__init__(default_retry=2000)

Constructor. On this method is called, automaticali initialize the internal buffer with retry statement with 2000ms as default value.

Sse.set_retry(num)

Method for set a custom retry value on initialized Sse intance.

Sse.set_event_id(event_id)

The specification of sse indicates that you can put ids to events. For more info, see: http://www.w3.org/TR/eventsource/#concept-event-stream-last-event-id

With this method, can set or reset the id value.

Sse.reset_event_id()

Helper method for reseting event id.

Sse.add_message(event, text, encoding='utf-8')

Method for add messages to the buffer and associate this messages to events. The event parameter can be a unicode string and text can be string, list, tuple or set.

Sse.flush()

Clears the internal buffer.

Sse.__str__()

Returns a raw output of buffer, ready for set to client. NOTE: this method will be used only on python3.

Sse.__unicode__()

Returns a raw output of buffer. Same as __str__ but returns unicode value on python2. Is not used on python3.

Aditional info:

  • Sse instance object can be used as iterator. On finish the iteration the internal buffer is automaticaly cleared.
  • Can use dynamic methods Sse.add_event_eventname(text='foo') as alias of Sse.add_message('eventname', 'foo')

License:

BSD License

sse's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sse's Issues

encoding is not passed to _parse_text

add_message accepts encoding as parameter but never passes it further down when calling _parse_text.
Also _parse_text does not accept such a parameter but it's implementation assumes it's been passed.

Event ID not recognized by Chrome when it follows after two new lines

I need to specify unique ID to each of my event. For this purpose on server I use method set_event_id after add_message method call.

On server I use:

sse.add_message('myevent', 'hello')
sse.set_event_id('123')
yield

In browser I get

event: myevent
data: hello

id: 123

and after reconnect by EventSource object, browser doesn't set HTTP_LAST_EVENT_ID header.

I tried to manual modify server response and set it to

event: myevent
data: hello
id: 123

With this response browser normally set HTTP_LAST_EVENT_ID to '123' after next reconnect.

What I'm doing wrong? How can I force the browser to set header to 123 with Sse methods?

I used Chrome 33.0.1750

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.