module server.documentation_server

Inheritance diagram of pyquickhelper.server.documentation_server

Short summary

module pyquickhelper.server.documentation_server

This file defines a simple local server delivering generating documentation.

source on GitHub

Classes

class

truncated documentation

DocumentationHandler

Define a simple handler used by HTTPServer, it just serves local content.

DocumentationThreadServer

defines a thread which holds a web server

Functions

function

truncated documentation

run_doc_server

Runs the server.

Properties

property

truncated documentation

daemon

A boolean value indicating whether this thread is a daemon thread. This must be set before start() is called, otherwise …

ident

Thread identifier of this thread or None if it has not been started. This is a nonzero integer. See the get_ident() …

name

A string used for identification purposes only. It has no semantics. Multiple threads may be given the same name. …

native_id

Native integral thread ID of this thread, or None if it has not been started. This is a non-negative integer. …

Static Methods

staticmethod

truncated documentation

_print_cache

Displays the most requested files.

add_mapping

Adds a mapping associated to a local path to watch.

execute

Locally executes a python script.

get_from_cache

Retrieves a file from the cache if it was cached, it the file was added later than a day, it returns None.

get_ftype

defines the header to send (type of files) based on path

get_mappings

Returns a copy of the mappings.

html_code_renderer

Produces a html code for code.

process_html_path

Processes a HTML content, replaces path which are relative to the root and not the project.

update_cache

Updates the cache.

Methods

method

truncated documentation

__init__

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

__init__

do_GET

What to do is case of GET request.

do_POST

What to do is case of POST request.

do_redirect

Redirection when url is just the website.

feed

Displays something.

get_file_content

Returns the content of a local file.

LOG

logging function

run

Runs the server.

send_headers

defines the header to send (type of files) based on path

serve_content

Tells what to do based on the path. The function intercepts the path /localfile/, otherwise it calls serve_content_web. …

serve_content_web

Functions to overload (executed after serve_content).

serve_main_page

Displays all the mapping for the default path.

shutdown

Shuts down the service.

shutdown

Shuts down the server, if it does not work, you can still kill the thread:

Documentation

This file defines a simple local server delivering generating documentation.

source on GitHub

class pyquickhelper.server.documentation_server.DocumentationHandler(request, client_address, server)[source]

Bases: BaseHTTPRequestHandler

Define a simple handler used by HTTPServer, it just serves local content.

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

LOG(*args, **kwargs)[source]

logging function

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

static _print_cache(n=20)[source]

Displays the most requested files.

source on GitHub

static add_mapping(key, value)[source]

Adds a mapping associated to a local path to watch.

Parameters:
  • key – key in http://locahost:8008/key/

  • value – local path

Python documentation says list are protected against multithreading (concurrent accesses). If you run the server multiple times, the mappings stays because it is a static variable.

source on GitHub

do_GET()[source]

What to do is case of GET request.

source on GitHub

do_POST()[source]

What to do is case of POST request.

source on GitHub

do_redirect(path='/index.html')[source]

Redirection when url is just the website.

Parameters:

path – path to redirect to (a string)

source on GitHub

static execute(localpath)[source]

Locally executes a python script.

Parameters:

localpath – local python script

Returns:

output, error

source on GitHub

feed(anys, script_python=False, params=None)[source]

Displays something.

Parameters:
  • anys – string

  • script_python – if True, the function processes script sections

  • params – extra parameters when a script must be executed (should be a dictionary)

A script section looks like:

<script type="text/python">
from pandas import DataFrame
pars = [ { "key":k, "value":v } for k,v in params ]
tbl = DataFrame (pars)
print ( tbl.to_html(class_table="myclasstable") )
</script>

The server does not interpret Python, to do that, you need to use pyrsslocal.

source on GitHub

get_file_content(localpath, ftype, path=None)[source]

Returns the content of a local file.

Parameters:
  • localpath – local filename

  • ftype – r or rb

  • path – if != None, the filename will be path/localpath

Returns:

content

This function implements a simple cache mechanism.

source on GitHub

static get_from_cache(key)[source]

Retrieves a file from the cache if it was cached, it the file was added later than a day, it returns None.

Parameters:

key – key

Returns:

content or None if None found or too old

source on GitHub

static get_ftype(apath)[source]

defines the header to send (type of files) based on path

Parameters:

apath – location (a string)

Returns:

htype, ftype (html, css, …)

If a type is missing, you should look for the MIME TYPE on a search engine.

See also media-types

source on GitHub

static get_mappings()[source]

Returns a copy of the mappings.

Returns:

dictionary of mappings

source on GitHub

static html_code_renderer(localpath, content)[source]

Produces a html code for code.

Parameters:
  • localpath – local path to file (local or not)

  • content – content of the file

Returns:

html string

source on GitHub

static process_html_path(project, content)[source]

Processes a HTML content, replaces path which are relative to the root and not the project.

Parameters:
  • project – project, ex: pyquickhelper

  • content – page content

Returns:

modified content

source on GitHub

send_headers(path)[source]

defines the header to send (type of files) based on path

Parameters:

path – location (a string)

Returns:

type (html, css, …)

source on GitHub

serve_content(cpath, method='GET')[source]

Tells what to do based on the path. The function intercepts the path /localfile/, otherwise it calls serve_content_web.

If you type http://localhost:8080/root/file, assuming root is mapped to a local folder. It will display this file.

Parameters:
  • cpath – ParseResult

  • method – GET or POST

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

serve_main_page()[source]

Displays all the mapping for the default path.

source on GitHub

shutdown()[source]

Shuts down the service.

source on GitHub

static update_cache(key, content)[source]

Updates the cache.

Parameters:
  • key – key

  • content – content to place

source on GitHub

class pyquickhelper.server.documentation_server.DocumentationThreadServer(server)[source]

Bases: Thread

defines a thread which holds a web server

attribute

meaning

server

the server of run

source on GitHub

Parameters:

server – to run

source on GitHub

__init__(server)[source]
Parameters:

server – to run

source on GitHub

run()[source]

Runs the server.

source on GitHub

shutdown()[source]

Shuts down the server, if it does not work, you can still kill the thread:

self.kill()

source on GitHub

pyquickhelper.server.documentation_server.run_doc_server(server, mappings, thread=False, port=8079)[source]

Runs the server.

Parameters:
  • server – if None, it becomes HTTPServer(('localhost', 8080), DocumentationHandler)

  • mappings – prefixes with local folders (dictionary)

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

  • port – port to use

Returns:

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

How to run a local server which serves the documentation?

The following code will create a local server: http://localhost:8079/pyquickhelper/.

this_fold = os.path.dirname(pyquickhelper.server.documentation_server.__file__)
this_path = os.path.abspath( os.path.join( this_fold,
            "..", "..", "..", "dist", "html") )
run_doc_server(None, mappings = { "pyquickhelper": this_path } )

The same server can serves more than one project. More than one mappings can be sent.

source on GitHub