Giter VIP home page Giter VIP logo

mimerender's People

Contributors

adamwill avatar akuckartz avatar dbtsai avatar ericfrederich avatar felixonmars avatar jfinkels avatar martinblech avatar thomasst avatar wojcikstefan avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mimerender's Issues

Send "Vary" header automatically

I believe that mimerender should send a "Vary" header with value set to "Accept" by default, since it is doing content negotiation based on the "Accept" header. Failing to send this header may result in cache corruption, particularly for public caches that may be serving many users.

I have a trivial patch* to add this header, and I modified one of the tests to cover it as well. I am using Flask, so I added support for other frameworks but I have no real idea if I have done it correctly.

I did test this with Flask's built-in (development) server as well as with Apache/mod_wsgi and both work fine. Apache appends "Accept-Encoding" to the "Vary" header because I have mod_deflate (or mod_gzip, whatever it is) and this also seems to work fine.

Please let me know what you think and if you want a pull request.

Cheers,

*https://github.com/mehaase/mimerender/commit/ff87abe93d0c58b80f97ff451a5c908d0b6e92d9

Broken on Python 3.4

Python 3.4 fixes functools.update_wrapper() and functools.wraps(). Your code currently depends on the old, arguably broken behavior. Trace back:

File "lib/python3.4/site-packages/mimerender.py", line 246, in wrapper
content = renderer(**result)
TypeError: () got an unexpected keyword argument 'blah'

"Accept: */*" should choose default function

If client send Accept: */* in request, mimerender should choose the default function to return the response to client.

My current workaround:

import mimerender
# suppose I want to use json as the default format
mimerender._MIME_TYPES['json'] = ('application/json', '*/*',)
mimerender = mimerender.WebPyMimeRender()
# do other things below

but this workaround is ugly, and the return Content-Type would be */*

Include copy of license in source / tarballs

mimerender claims MIT as its license, but AFAICT does not include the text of the license anywhere in the source tree on github, nor in the release tarballs. The MIT license includes this text:

" The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software."

i.e. the license itself requires that it be included with distributions of the code, yet the canonical distribution of the code does not include it. As the Fedora licensing guidelines - https://fedoraproject.org/wiki/Packaging:LicensingGuidelines - and similar guidelines for other distributions (e.g. Debian) state, "In cases where the upstream has chosen a license that requires that a copy of the license text be distributed along with the binaries and/or source code, but does not provide a copy of the license text (in the source tree, or in some rare cases, anywhere), the packager should do their best to point out this confusion to upstream.", so I am doing that. Please include a copy of the license in the source. The usual way to do this would be to include the text in the top-level directory as a file named LICENSE or COPYING.

Additions to source tarball

Hi,

I am currently making mimerender available in the official Debian repositories.

While the package is fine, overall, it would be great to have the docs/ and examples/ included in the official source tarball (i.e. that on PyPI).

Please also consider pgp-signing the upload to pypi so we in Debian (and other distributions) can create a trusted build.

Thanks,
Nik

JSON-LD

application/ld+jsonshould be added.

Possibility of setting renderer centrally

Hi,
Is it possible to set the renderer somewhere centrally while initializing the mimerender? So that actual decorator can be called without params and it will be easy to add new renderer.

Renderers should have access to HTTP header and HTTP status information

Consider the JSONP section of the GitHub API. They insert both the HTTP status code and the HTTP header information into the (padded) JSON object in the body of the response. There is currently no clean way to implement this behavior with mimerender.

It would be nice for mimerender to have some mechanism that allows renderers to receive as (positional or keyword) arguments a dictionary representation of the HTTP headers, as well as the HTTP status code.

Content-Type sometimes wrong with recent Python 3 and pypy(?)

You have a few travis runs - one for the most recent commit:

https://travis-ci.org/martinblech/mimerender/builds/55794367

and two for recent PRs:

https://travis-ci.org/martinblech/mimerender/builds/55276527
https://travis-ci.org/martinblech/mimerender/builds/103693109

where the 'pypy' run of the test suite failed, with two tests failing because of Content-Type being 'application/xml' instead of 'text/xml'. Interestingly, I seem to get the exact same error sometimes when running the test suite with Python 3 on Fedora Rawhide - that's Python 3.5. It never seems to fail with Python 2. Sometimes the test suite passes, though.

I'm afraid I don't know what the actual problem is, but clearly there's some kind of issue there.

mimerender shouldn't render __init__()

mimerender should only process GET(), POST(), PUT(), DELETE()

This problem can be reproduced by adding a __init__() function to class greet and do not add any return statement.

Here's what I got

Traceback (most recent call last):
  File "/home/yegle/venv/lib/python2.7/site-packages/web/application.py", line 237, in process
    return self.handle()
  File "/home/yegle/venv/lib/python2.7/site-packages/web/application.py", line 228, in handle
    return self._delegate(fn, self.fvars, args)
  File "/home/yegle/venv/lib/python2.7/site-packages/web/application.py", line 409, in _delegate
    return handle_class(cls)
  File "/home/yegle/venv/lib/python2.7/site-packages/web/application.py", line 384, in handle_class
    tocall = getattr(cls(), meth)
  File "/home/yegle/venv/lib/python2.7/site-packages/mimerender.py", line 179, in wrapper
    content = renderer(**result)
TypeError: <lambda>() argument after ** must be a mapping, not NoneType

mimerender breaks app.route in flask

The following sample always prints "Other!", even if trying to access the index view.

from flask import Flask
import mimerender

mimerender = mimerender.FlaskMimeRender()

render_html = lambda message: '<html><body>%s</body></html>' % message

app = Flask(__name__)

@app.route('/')
@mimerender(default = 'html', html = render_html)
def index():
    return {'message': 'Hello, World!'}

@app.route('/other/')
@mimerender(default = 'html', html = render_html)
def other():
    return {'message': 'Other!'}

if __name__ == "__main__":
    app.run(debug=True)

Add MANIFEST.in with link to LICENSE

I've put together a build of mimerender for conda-forge. (conda-forge/staged-recipes#1522) It'd be good to include a hard link to the license file in the build, but doing so requires that the license file be explicitly referenced in a MANIFEST.in file so that the license gets bundled in the source distribution.

CORS

Could you give me a few sentences telling me how to add support for CORS? I'll code it up if you'll help me figure out where to hook it in.

Here's a snip I found that should work.

ALLOWED = ['http://localhost:5000']
response = make_response(data)
origin = request.headers['Origin']
if origin in ALLOWED:
response.headers['Access-Control-Allow-Origin'] = origin

Thanks.

list rendering

If i want to render a list as root element to json, i get a "TypeError: () argument after ** must be a mapping, not list" from line 211.

... not sure, if this is a bug or a layer 8 error ;)
thx

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.