Skip to main content

HTTP User-Agent parser for Pyramid

Project description

Project Info

Provides an HTTP User-Agent parser and classifier for the Pyramid web framework.

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

Changes

0.3

  • Add a User-Agent classifier using the user-agents project

0.2

  • Continuous testing

  • Documentation

0.1

  • Initial release.

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.3.tar.gz (14.5 kB view details)

Uploaded Source

Built Distribution

pyramid_useragent-0.3-py27-none-any.whl (16.0 kB view details)

Uploaded Python 2.7

File details

Details for the file pyramid_useragent-0.3.tar.gz.

File metadata

File hashes

Hashes for pyramid_useragent-0.3.tar.gz
Algorithm Hash digest
SHA256 fa8b86df665d1de8f73f0f0e53ff7bd578d1d6a960161a7fb5829ecda7f66734
MD5 9d4c99c15a1e623465edcba85127019f
BLAKE2b-256 8d8e8184bb1a9c0d3a3e1ac48b0e54d66859c22523d87feffc5c882cf6d94e9a

See more details on using hashes here.

Provenance

File details

Details for the file pyramid_useragent-0.3-py27-none-any.whl.

File metadata

File hashes

Hashes for pyramid_useragent-0.3-py27-none-any.whl
Algorithm Hash digest
SHA256 b881f16fa8ca444842a1d00bd5214dc59681474265df8c07f2a79babd8d32120
MD5 978ae1f7c32e62a2bad1a05bbdd7a830
BLAKE2b-256 84957091f26adc3bd35d5f14c2bd72e15d75670cc1c56312c0773cb33a9b14dd

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page