Giter Site home page Giter Site logo

pygrim's People

Contributors

dark-light-cz avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

pygrim's Issues

Unify and enhance error_handler, custom_error_handler and not_found_handler decorators

Three decorators, namely @error_handler, @custom_error_handler and @not_found_hander, are now used to mark controller method as a handler for "not good" situation. In fact, these decorators do very similar job (handle an error state).

@custom_error_handler and @error_handler are in fact the same -- @error_handler catches BaseException. @not_found_handler should catch NotFoundException, that should be returned to code.

Both @error_handler and @not_found_handler should take prefix argument which restricts them to request with uri.startswith(prefix)

Enable custom not-found handlers

not_found decorator might get a list of path prefixes. If requested url cannot be handled by any route but starts with a prefix registered for not_found handler, such handler will be used for handling 404 situation. default_not_found handler will be the last to be used, when no other match the requested url

Prolong session cookie

Session cookie is sent to user only when it is created! It should be re-sent on every response.

Rewrite flash messages

Getting flash messages should support for filtering (by message type). Only iterated messages are to be removed -- e.g., iterating over error flash messages will not discard any other message from session.

Implement tool for input validation

Pygrim should contain some factory method to create validator: it should be initialized by data source (e.g., context.POST) and validation rules (e.g. pairs of (variable_name, validator) ). Validator should be functor (implementing call). Calling validator should either raise an exception (when invalid input is given) or return validated value. Validators won't be part of pygrim and won't be restricted in any other way than requiring call method.

Implement generator type response

Implement correct behaviour when Response.body is a generator type -- don't wait till it is iterated over, but send parts as they are being iterated.

Add support for multiple views

Allow pygrim server to have several kinds of view components registered. Each route handler should specify which view class should be used to render the result.

For raw result (return response body without any rendering), new class (RawView) should be implemented.

Together with this change, template data dump should be turned into separate view class (JsonView), and server should change selected view class to JsonView when dump switch is on.

PyGrim should check (on postfork phase) if RawView and JsonView are enabled. If any is disabled, warning should be logged about core component being disabled.

Instead of disabling the view, DummyView should be used -- it does not render any body and sends default response headers.

Separate start and runtime logs

Currently, pygrim uses single log for all messages. It might be useful to have separated log levels for different situations, such as server start, server runtime.

Load session when it is accessed

Currently, @method(session=True) is used for loading session. Change session implementation so it is loaded when accessed -- regardless of route setting.

Session will be saved when route handle successfully returns. When not-found or exception is used, session will not be saved by PyGrim -- needs to be saved manually, if required.

Don't allow to create new session after cookies were sent

When cookies have already been sent to client, session can still be created (e.g., by generator used as response body). If cookie headers have already been sent, PyGrim has no way to inform user about his session id.

When cookie headers have been sent (and no session have been used at that moment), raise on attempt to create new session.

Register routes with decorator

Routes should now be registered with @route decorator -- its parameters will be passed to Route.

PyGrim should have route_dump capability -- print all routes, nof-founds and errors that are registered, plus info about their handles: their names, in which file and line it is implemented, etc.

Several features will become obsolete and deprecated: method for creating routes, @method decorator, checking if handle is exposed.

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.