module rss.rss_simple_server

Inheritance diagram of pyrsslocal.rss.rss_simple_server

Short summary

module pyrsslocal.rss.rss_simple_server

This modules contains a class which implements a simple server.

source on GitHub

Classes

class

truncated documentation

RSSServer

Defines a :epkg:`RSS` server dedicated to one specific database. You can read the blog post RSS Reader. …

RSSSimpleHandler

You can read the blog post RSS Reader. defines a simple handler …

Static Methods

staticmethod

truncated documentation

run_server

Starts the server.

Methods

method

truncated documentation

__enter__

what to do when creating the class

__exit__

what to do when removing the instance (close the log file)

__init__

__init__

Regular constructor, an instance is created for each request, do not store any data for a longer time than a request. …

get_javascript_paths

returns all the location where the server should look for a java script

interpret_parameter_as_list_int

interpret a list of parameters, each of them is a list of integer separated by ,

main_page

returns the main page (case the server is called with no path)

process_event

Processes an event, it expects a format like the following:

process_event

process an event, and log it

serve_content_web

functions to overload (executed after serve_content)

Documentation

This modules contains a class which implements a simple server.

source on GitHub

class pyrsslocal.rss.rss_simple_server.RSSServer(server_address, dbfile, RequestHandlerClass=<class 'pyrsslocal.rss.rss_simple_server.RSSSimpleHandler'>, main_page='rss_reader.html', root='somewhere/workspace/pyrsslocal/pyrsslocal_UT_37_std/_doc/sphinxdoc/source/pyrsslocal/rss', logfile=None, fLOG=None)[source]

Bases: socketserver.ThreadingMixIn, http.server.HTTPServer

Defines a :epkg:`RSS` server dedicated to one specific database. You can read the blog post RSS Reader.

source on GitHub

Parameters
  • server_address – address of the server

  • RequestHandlerClass – it should be RSSSimpleHandler

  • dbfile – database filename (SQLlite format)

  • main_page – main page for the service (when requested with no specific file)

  • root – folder when the server will look into for files such as the main page

  • fLOG – logging function

source on GitHub

__enter__()[source]

what to do when creating the class

source on GitHub

__exit__(exc_type, exc_value, traceback)[source]

what to do when removing the instance (close the log file)

source on GitHub

__init__(server_address, dbfile, RequestHandlerClass=<class 'pyrsslocal.rss.rss_simple_server.RSSSimpleHandler'>, main_page='rss_reader.html', root='somewhere/workspace/pyrsslocal/pyrsslocal_UT_37_std/_doc/sphinxdoc/source/pyrsslocal/rss', logfile=None, fLOG=None)[source]
Parameters
  • server_address – address of the server

  • RequestHandlerClass – it should be RSSSimpleHandler

  • dbfile – database filename (SQLlite format)

  • main_page – main page for the service (when requested with no specific file)

  • root – folder when the server will look into for files such as the main page

  • fLOG – logging function

source on GitHub

process_event(event)[source]

Processes an event, it expects a format like the following:

type1/uuid/type2/args
Parameters

event – string to log

source on GitHub

static run_server(server, dbfile, thread=False, port=8080, logfile=None, fLOG=None)[source]

Starts the server.

Parameters
  • server – None or string, see below

  • dbfile – file to the RSS database (SQLite)

  • thread – if True, the server is run in a thread and the function returns right away, otherwite, it runs the server.

  • port – port to use

  • logfile – file for the log or “stdout” for the standard output

  • fLOG – logging function

Returns

server if thread is False, the thread otherwise (the thread is started)

About the parameter server:

  • None, it becomes RSSServer(('localhost', 8080), dbfile, RSSSimpleHandler)

  • <server>, it becomes RSSServer((server, 8080), dbfile, RSSSimpleHandler)

Warning

If you kill the python program while the thread is still running, python interpreter might be closed completely.

source on GitHub

class pyrsslocal.rss.rss_simple_server.RSSSimpleHandler(request, client_address, server)[source]

Bases: pyrsslocal.simple_server.simple_server_custom.SimpleHandler

You can read the blog post RSS Reader.

defines a simple handler used by HTTPServer

Firefox works better for local files.

This server serves RSS content.

For every section containing a python script, the class will add a local variable dbrss which gives access to the blogs database. That’s why the following section works:

<script type="text/python">
for blogs in dbrss.enumerate_blogs() :
    print (blogs.html())
</script>

Whenever a url is preceded by /logs/click/`, the class will log an event in the logs.

The final page will look like this:

../../_images/page11.png

FAQ: The server is slow or does not respond to a click

For some reason, it usually happens on Firefox. Chrome works better. The script python embedded in the HTML page and interpreted by the server make it slow to run. It should be replaced by javascript. Maybe Firefox detects the answer is not fast enough and it requires one or two more clicks to get the server to respond.

source on GitHub

Regular constructor, an instance is created for each request, do not store any data for a longer time than a request.

source on GitHub

__init__(request, client_address, server)[source]

Regular constructor, an instance is created for each request, do not store any data for a longer time than a request.

source on GitHub

get_javascript_paths()[source]

returns all the location where the server should look for a java script

Returns

list of paths

source on GitHub

interpret_parameter_as_list_int(ps)[source]

interpret a list of parameters, each of them is a list of integer separated by ,

Parameters

ps – something like params.get("blog_selected")

Returns

list of int

source on GitHub

main_page()[source]

returns the main page (case the server is called with no path)

Returns

default page

source on GitHub

process_event(st)[source]

process an event, and log it

Parameters

st – string to process

source on GitHub

serve_content_web(path, method, params)[source]

functions to overload (executed after serve_content)

Parameters
  • path – ParseResult

  • method – GET or POST

  • params – params parsed from the url + others

source on GitHub