Skip to content

Koala-Kaolin/pyweb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pyweb

Introduction

This is a light Framework for Python HTTP server.

The purpose of this Framework is to ease POC development. It supports both HTTP 1.1 and WebSocket (RFC 6455) protocols.

HTTP actions and WebSocket handlers are hot reloaded without killing running processes.

Installation

Prerequisites

This Framework needs Python 3+.

To run the GUI, tkinter is needed.

Install

chmod +x ./setup.py ./setup.py build

This command generates a pyweb.pyz.

Certificate generation

Generate a SSL pair of keys: ./setup.py ssl creates run/certificate.crt and run/privateKey.key

Running

Declare pyz as default executable for *.pyz files.

Start the serveur: ./setup.py run -h or ./pyz ./pyweb.pyz -h or pthon3 ./pyweb.pyz -h

You should get:

usage: pyweb.pyz [-h] [-nogui] [-port [PORT]] [-add ADD [ADD ...]]
                 [-m M [M ...]] [-testing] [-testfile [TESTFILE]] [-secured]
                 [-certfile [CERTFILE]] [-keyfile [KEYFILE]]

Optional app description

optional arguments:
  -h, --help            show this help message and exit
  -nogui                without gui
  -port [PORT]          port
  -add ADD [ADD ...]    directory
  -m M [M ...]          module for actions
  -testing              with tests
  -testfile [TESTFILE]  javascript test file
  -secured              secured
  -certfile [CERTFILE]  certificate path
  -keyfile [KEYFILE]    private key file

Replace -h by your configuration parameters.

Default tests URL :

Log files

Two files recreated after each launch:

  • sys.stdin is redirected to run/pyweb.err
  • sys.stdout is redirected to pyweb.log

Getting started and Overview

Edit file lab.py as needed. This python script is dynamicly reloaded.

URL parameters

@core.http("GET", "/root/{id}/{action}.do")
def action_1 (headers, parameters, id: "path", action: "path"):
  return answer(200, hs={}, body="Hello world")

Pattern

@core.http("GET|POST", "/test/unique/{id}")
def action_test_unique(
        headers,
        params,
        id: "path",
        ptexte: "text [a-zA-Z]{10}",
        htexte: "header",
        pnum: "number .{10}"=1234567890,
        pfile: "file"=None):
    """
    Fonction de test
    @param headers http headers
    @param params all parameters dictionnary
    @param id mandatotory path element
    @param ptexte mandatory text parameter with exactly 10 letters
    @param htexte parameter from header
    @param pnum parameter with 10 carachters with default value 1234567890
    @param pfile optionnal file
    """
return answer(200, body="<html>Hello %s</html>" % ptexte, mime="text/html")

Project

Structure

Your Pyweb server actions:

  • ./lab.py
  • ./print.py

Tests directory:

  • ./www/test.js (generated by staarting the server with testing option)
  • ./www/testlib.*

Documentation:

  • ./doc/*

Archive ./pyweb.pyz sources files:

  • ./src/*.py

From work directory:

  • ./work/certificate.crt (generated by ./setup.py ssl)
  • ./work/privateKey.key (generated by ./setup.py ssl)
  • ./work/pyweb.err
  • ./work/pyweb.log

Others:

  • ./README.md
  • ./LICENSE
  • ./setup.py