Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/simonw/django-signed
Signing utilities for Django, to try out an API which is being proposed for inclusion in Django core.
https://github.com/simonw/django-signed
Last synced: 26 days ago
JSON representation
Signing utilities for Django, to try out an API which is being proposed for inclusion in Django core.
- Host: GitHub
- URL: https://github.com/simonw/django-signed
- Owner: simonw
- Created: 2009-09-26T09:15:14.000Z (about 15 years ago)
- Default Branch: master
- Last Pushed: 2009-12-06T17:37:41.000Z (almost 15 years ago)
- Last Synced: 2024-10-07T13:53:39.987Z (about 1 month ago)
- Language: Python
- Homepage:
- Size: 83 KB
- Stars: 37
- Watchers: 4
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README
Awesome Lists containing this project
README
django_signed
=============This project demonstrates a proposed signing API for Django. You can run the
test suite like so:cd examples
./manage.py testThe API is under heavy development. It is described in more detail here:
http://code.djangoproject.com/wiki/Signing
The mailing list discussion is here:
http://groups.google.com/group/django-developers/browse_thread/thread/133509246caf1d91
TODO:
- Add support for expiring signatures
- Try using a class instead of functions, as suggested by Johannes Dollinger
- Cookie signing functions
- Middleware that illustrates the proposed request cookie signing API
- Support key migration from an OLD_SECRET_KEY to the current onebaseconv.py
-----------Part of this module is baseconv.py, which I hope to contribute to
django.utils. baseconv allows you to convert between integers and various
different string representations of those numbers. For example:>>> import baseconv
>>> i = 102971
>>> baseconv.base2.from_int(i)
'11001001000111011'
>>> baseconv.base16.from_int(i)
'1923B'
>>> baseconv.base36.from_int(i)
'27gb'
>>> baseconv.base62.from_int(i)
'Qmp'You can convert back again using the to_int(string) method:
>>> baseconv.base2.to_int('11001001000111011')
102971
>>> baseconv.base16.to_int('1923B')
102971
>>> baseconv.base36.to_int('27gb')
102971
>>> baseconv.base62.to_int('Qmp')
102971This is principally useful as a compression scheme for transmitting numbers as
ascii text - in particular for URLs (URL shortening services such as bit.ly
use this technique). The signed cookie implementation uses this to represent
a unix timestamp in as few characters as possible, to keep cookie lengths
down.If you wish to use your own shortening scheme you can use the BaseConvertor
class. For example, you might want to just use characters that aren't easily confused with each other - the alphabet omitting i, l and o:>>> convertor = baseconv.BaseConverter('abcdefghjkmnpqrstuvwxyz')
>>> convertor.from_int(102971)
'jmsa'
>>> convertor.to_int('jmsa')
102971