python-basicauth

An incredibly simple HTTP basic auth implementation
Download

python-basicauth Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Other/Proprietary Li...
  • Price:
  • FREE
  • Publisher Name:
  • Randall Degges
  • Publisher web site:
  • http://github.com/comradeb14ck/

python-basicauth Tags


python-basicauth Description

python-basicauth is a dead simple HTTP basic auth encoder and decoder. Why? Because HTTP should be drop dead easy. That's why.InstallTo install ``python-basicauth``, simply run ``pip install basicauth`` and you'll get the latest version installed automatically.UsageTo generate an encoded basic auth string:``` python>>> from basicauth import encode>>> username, password = 'rdegges', 'omghax!!!'>>> encoded_str = encode(username, password)>>> print encoded_str'Basic cmRlZ2dlczpvbWdoYXglMjElMjElMjE='```To decode an encoded basic auth string:``` python>>> from basicauth import decode>>> encoded_str = 'Basic cmRlZ2dlczpvbWdoYXglMjElMjElMjE=' # From the example above.>>> username, password = decode(encoded_str)>>> print (username, password)('rdegges', 'omghax!!!')```We can also decode the hash directly:``` python>>> from basicauth import decode>>> encoded_str = 'cmRlZ2dlczpvbWdoYXglMjElMjElMjE=' # From the example above.>>> username, password = decode(encoded_str)>>> print (username, password)('rdegges', 'omghax!!!')```And if there are errors:``` python>>> from basicauth import decode, DecodeError>>> encoded_str = 'lol omg cmRlZ2dlczpvbWdoYXglMjElMjElMjE=' # Invalid hash.>>> username, password = decode(encoded_str)Traceback (most recent call last): File "< stdin >", line 1, in File "basicauth/__init__.py", line 49, in decode raise DecodeErrorbasicauth.DecodeError```TestsWant to run the tests? No problem:``` bash$ git clone git://github.com/rdegges/python-basicauth.git$ cd python-basicauth$ python setup.py develop...$ pip install -r requirements.txt # Install test dependencies.$ nosetests.............----------------------------------------------------------------------Ran 13 tests in 0.166sOKProduct's homepage


python-basicauth Related Software