Giter Club home page Giter Club logo

Comments (2)

Knio avatar Knio commented on May 26, 2024

I will start working on this

from dominate.

Knio avatar Knio commented on May 26, 2024

Here is my proposed format for server configs:

'''
format of httpserver.sites:

[ SPECIFIER, HANDLER, ... ]
where SPECIFIER is one of:
  * a regular expression string - matches that hostname (or uri, in a sub-handler)
  * an HTTP error code          - matches that error code
  * HTTPError                   - matches all errors
  * None                        - matches None or the empty string
  * True                        - matches everything

If no specifiers match, an HTTPError(404) will be raised.
If multiple SPECIFIERs match, the last one will be used. If the last one raises a 404 error, then the second last one will be used, etc.
Note that if a leaf-node (final handler) raises a 404, that error will be handled normally and will not cause the resolver to keep looking

and HANDLER is one of:
  * [ SPECIFIER, HANDLER, ...]  - to do further processing
  * a function object           - will be called with f(*args) where args is a list of all regex matches that were encountered in the entire processing of this request. The function's return value will then be used as a new HANDLER
  * a handler object            - will be called with .handle(httpserver, request, response, *args) (or .handle_error(..) if this is an error match)
  * None                        - do nothing
  * an HTTPError instance       - this error will be raised

'''

# an example:
sites = [

  True, [ 
    # example.zkpq.ca didn't match, redirect the user to the right hostname
    '^/.*$', HTTPError(302, 'http://example.zkpq.ca')
  ]

  '^example.zkpq.ca$', [
    '^/(\w+)$',   lambda x:pyyscript        ('.', '%s.py' %x), # need lambda to add '.py'
    '^/src(.*)$', lambda x:syntaxfileserver ('../..',  x),    # serve the source dir with highlighting. don't need a lambda here, but it works
    '^/doc(.*)$', fileserver('../',    x),    # serve the documentation 

    HTTPError:    lambda :pyyscript('.', 'error.py'), # generic error
    404:          lambda :pyyscript('.', '404.py'),   # specific error
  ]

]

# TODO: make pyy_httpserver acctually implement this!

from dominate.

Related Issues (20)

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.