About tgext.utils
tgext.utils is a collection of utilities for the TurboGears2 web framework.
Installing
tgext.utils can be installed from pypi:
pip install tgext.utils
should just work for most of the users.
CSRF Protection
tgext.utils.csrf provides two decorators @csrf_token and @csrf_protect which generate a CSRF token for inclusion in a form and check that the token is valid.
The user must apply @csrf_token decorator to the action that exposes the form, and put an <input type="hidden"> into the form with a request.csrf_token as the value and _csrf_token as name:
@csrf_token
@expose()
def form(self):
return '''
<form method="POST" action="/post_form">
<input type="hidden" name="_csrf_token" value="%s">
</form>''' % request.csrf_token
The action that receives the form must have @csrf_protect decorator, no particular action or check is required on this action:
@csrf_protect
@expose()
def post_form(self, **kwargs):
return 'OK!'
Slug
tgext.utils.slug provides a way to generate slug for your page
to generate a slug use:
from tgext.utils.slug import slugify
myslug = slugify(model_id, string_to_be_inserted_in_the_url)
to get the id from a slug use:
from tgext.utils.slug import slug2entityid
slug2entityid(myslug)
Storage
tgext.utils.storage is a tool for storing files into /public dir in separated folders.
from tgext.utils.storage import store
filename = store(ufile) # ufile is an instance of cgi.FieldStorage
file is stored inside /public/storage/${uuid1} folder thus also accessible using internal tg file serving.
Metadata
Release files for tgext.utils 0.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| tgext.utils-0.0.4.tar.gz | 5.4 kB | Without provenance | Details for tgext.utils-0.0.4.tar.gz |
Release files / tgext.utils-0.0.4.tar.gz
| Download URL | tgext.utils-0.0.4.tar.gz |
|---|---|
| Size | 5.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fec9e72d43c5dd3d548744c676dfa11d2f2355dc9fffbc50051b0bdf12b1c9ab
|
|
BLAKE2b-256 checksum How to use checksums |
d2fdecf04c8bdf8463b109a231e42e0c660140217eb475d98bff9d9221655a0e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
Python-urllib/3.7
|
Security for tgext.utils 0.0.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.