Coder Social home page Coder Social logo

aspen.py's Introduction

Aspen is a filesystem router for Python web frameworks. See aspen.io for framework wrappers.

Installation, Testing, and License

aspen is available on GitHub and on PyPI:

$ pip install aspen

We test against 64-bit Python 3.6, 3.7, 3.8 and 3.9 on Linux: Linux build status

And we test against 32- and 64-bit Python 3.6, 3.7, 3.8 and 3.9 on Windows: Windows build status

aspen is MIT-licensed.

aspen.py's People

Contributors

agners avatar alexishuet avatar amitkot avatar armstrongj avatar berryp avatar bigbluehat avatar chadwhitacre avatar changaco avatar dahlia avatar dowski avatar galuszkak avatar ivoz avatar jaraco avatar jarpineh avatar joeyespo avatar lucretiel avatar lyndsysimon avatar marcusrbrown avatar meatballhat avatar msabramo avatar pjz avatar techtonik avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

aspen.py's Issues

Compression of static files

Aspen supports storing static files in RAM. Compressing this data with brotli or gzip could save both RAM and CPU cycles.

Unexpected `output` in template

I am upgrading a (closed-source) project to Aspen 1.0rc2. In one simplate I conditionally assign a variable output in the request-time Python section, and then conditionally show a message based on the truthiness of the variable. Under 1.0rc2, there is an output object in the default simplate context, so the value is always truthy. I know we've touched on this area before, but I forget where things stand: am I supposed to know this somehow and just be careful with a name like that?

I think the only place we ever really hit this was with response, because we'd do an HTTP call from inside a simplate and bind the result to response, which would overwrite the in-progress Aspen response. Should we rename this to aspen_output to avoid the conflict? Should we prefix other names, like path and qs?

if foo:
    output = 'bar'
[---]
{% if output %}{{ output }}{% endif %}

Not optimized for production use

When changes_reload is False: resources.get() should not touch the filesystem at all (no stat() call), and the dispatcher shouldn't touch the filesystem either (it should build a dispatch tree in RAM when the RequestProcessor is created).

The syntax of path variables is ambiguous

When the dispatcher encounters a file named %varname.xxx.spt, it can't know for sure whether xxx is a typecast or a file extension. Should we change the separator used for typecasting from a dot . to a colon :?

Pure-python alternative to simplates

Adding support for pure-python (.py) dynamic resources, in addition to simplates, could be a solution to several issues. Here's what it could look like:

import things

do_one_time_stuff
a_global_var = None

def GET(website, response):  # dependency injection here
    if bad:
        return response.error(400, 'xxx')
    do_GET_stuff
    return locals()

def POST(request, response):
    do_POST_stuff
    response.redirect('…')

PAGES = []

PAGES.append("""text/html
<p>Lorem ipsum</p>
""")

PAGES.append("""application/json
{'lorem': 'ipsum'}
""")

# or

PAGES = """
[---] text/html
<p>Lorem ipsum</p>
[---] application/json
{'lorem': 'ipsum'}
"""

Notes:

  • it's a little more verbose than a simplate, but not much
  • variables aren't passed implicitly to the templates by default (AspenWeb/pando.py#215)
  • pyflakes friendly (no need for AspenWeb/pando.py#30 and AspenWeb/pando.py#546)
  • also more friendly to other tools, e.g. test coverage measurement
  • single source of truth for supported methods (that's even better than AspenWeb/pando.py#204)
  • possible to decorate functions
  • for proper error reporting we can scan the file to determine the line number each template starts at
  • syntax highlighting of templates is still possible, but instead of making a new syntax highlighter you need to modify the python one

@whit537 What do you think? Why did you originally go with a custom file format? Is there some issue with using pure python that I missed/forgot?

`mmap` for static files

Aspen currently supports two possibilities for static files: open and read them every time they're requested; or store their contents in Python bytestrings. Mapping them using mmap could be an interesting third possibility, and probably a good default for files that aren't too large.

Simplates are assumed to be ASCII even under python 3

In Python 3.0 the default encoding was changed from ASCII to UTF-8 (PEP 3120), so a project that no longer supports Python 2.7 should be able to remove all comments like # coding: utf8, but currently the ones in simplates can't be pruned because Aspen always assumes ASCII by default.

Keeping static files open

Aspen currently supports keeping the contents of static files in RAM (the store_static_files_in_ram setting). I think it should also support keeping open file descriptors instead. It would be a middle ground alternative that improves performance and reliability compared to opening the files over and over, without wasting RAM like store_static_files_in_ram does.

The performance problem of opening the files over and over is that we have to call os.path.realpath() every time to check that the file isn't outside the allowed directories. That function is slow because it has to make a system call for every parent directory (and because it's written in pure Python, but it would still be slowish if it was written in C).

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.