module rss.rss_simple_server
¶
Short summary¶
module pyrsslocal.rss.rss_simple_server
This modules contains a class which implements a simple server.
Classes¶
class |
truncated documentation |
---|---|
Defines a RSS server dedicated to one specific database. You can read the blog post RSS Reader. … |
|
You can read the blog post RSS Reader. Defines a simple … |
Static Methods¶
staticmethod |
truncated documentation |
---|---|
Starts the server. |
Methods¶
method |
truncated documentation |
---|---|
What to do when creating the class. |
|
What to do when removing the instance (close the log file). |
|
Regular constructor, an instance is created for each request, do not store any data for a longer time than a request. … |
|
Returns all the location where the server should look for a java script. |
|
Interprets a list of parameters, each of them is a list of integer separated by |
|
Returns the main page (case the server is called with no path). |
|
Processes an event, it expects a format like the following: |
|
Processes an event, and log it. |
|
Functions to overload (executed after serve_content). |
Documentation¶
This modules contains a class which implements a simple server.
- 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_39_std/_doc/sphinxdoc/source/pyrsslocal/rss', logfile=None, fLOG=None)¶
Bases:
ThreadingMixIn
,HTTPServer
Defines a RSS server dedicated to one specific database. You can read the blog post RSS Reader.
- 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
- __enter__()¶
What to do when creating the class.
- __exit__(exc_type, exc_value, traceback)¶
What to do when removing the instance (close the log file).
- __init__(server_address, dbfile, RequestHandlerClass=<class 'pyrsslocal.rss.rss_simple_server.RSSSimpleHandler'>, main_page='rss_reader.html', root='somewhere/workspace/pyrsslocal/pyrsslocal_UT_39_std/_doc/sphinxdoc/source/pyrsslocal/rss', logfile=None, fLOG=None)¶
- 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
- process_event(event)¶
Processes an event, it expects a format like the following:
type1/uuid/type2/args
- Parameters:
event – string to log
- static run_server(server, dbfile, thread=False, port=8080, logfile=None, fLOG=None)¶
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 becomesRSSServer(('localhost', 8080), dbfile, RSSSimpleHandler)
<server>
, it becomesRSSServer((server, 8080), dbfile, RSSSimpleHandler)
Warning
If you kill the python program while the thread is still running, python interpreter might be closed completely.
- class pyrsslocal.rss.rss_simple_server.RSSSimpleHandler(request, client_address, server)¶
Bases:
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:Regular constructor, an instance is created for each request, do not store any data for a longer time than a request.
- __init__(request, client_address, server)¶
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.
- Returns:
list of paths
- interpret_parameter_as_list_int(ps)¶
Interprets 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
- main_page()¶
Returns the main page (case the server is called with no path).
- Returns:
default page
- process_event(st)¶
Processes an event, and log it.
- Parameters:
st – string to process
- serve_content_web(path, method, params)¶
Functions to overload (executed after serve_content).
- Parameters:
path – ParseResult
method – GET or POST
params – params parsed from the url + others