HTTP User-Agent parser for Pyramid
Project description
Project Info
Provides an HTTP User-Agent parser and classifier for the Pyramid web framework.
Documentation: http://pyramid-useragent.readthedocs.org/
Bitbucket: https://bitbucket.org/pior/pyramid_useragent
Setup
Once pyramid_useragent is installed, you typically use the config.include mechanism to include it into your Pyramid project’s configuration. In your Pyramid project’s __init__.py:
config = Configurator(.....)
config.include('pyramid_useragent')
Alternately, instead of using the Configurator’s include method, you can activate Pyramid by changing your application’s .ini file, use the following line:
pyramid.includes = pyramid_useragent
Usage
def demo(request):
client = request.user_agent_classified
if client.is_mobile or client.is_tablet:
return "Download our mobile app!"
if client.is_bot:
return "Are you human? I'am human."
ua = request.user_agent_parsed
if ua.maincomponent.name == 'Links':
return "Did you REALLY use Links?"
if 'AdobeAIR' in ua.components:
if ua.components['AdobeAIR'].version == '3.9.0.1210':
return "Much unsecure, so flaws"
if ua.maincomponent.name == "Mozilla":
return "This is supposed to describe your platform: %s" % (
'; '.join(ua.maincomponent.comments))
return [c.name for c in ua.components.values()]
Tests
pip install -e .[testing]
nosetests
Documentation
pip install -e .[docs]
cd docs
make html
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pyramid_useragent-0.2.tar.gz
(14.1 kB
view hashes)
Built Distribution
Close
Hashes for pyramid_useragent-0.2-py27-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bb46bb44f9db96a1a98964a07cb1bb174be1e30021d9cacbf3dd7088943afa85 |
|
MD5 | 7d914deef480473cfba7afe514ef8eff |
|
BLAKE2b-256 | 9530fa9c460c44f1f33a150d8b459781d4014865bdda7b47701396d23ace78a2 |