============
URL handlers
============

For URIs that are URLs we provide a base handler class that implements the
`allow` and `classify` methods, so that protocol-specific handlers like HTTP
and FTP only have to implement the actual `check` method.

>>> from gocept.lms.handler import AbstractURLHandler
>>> handler = AbstractURLHandler()

Allowing URLs
=============

The HTTP handler does not allow us to talk to localhost by default:

>>> handler.allow('ftp://localhost/')
False

Hosts are managed through a black list that lives in gocept.lms.filter.

>>> import gocept.lms.filter
>>> gocept.lms.filter.HOST_BLACKLIST.discard('localhost')

>>> handler.allow('ftp://localhost/')
True

Clean up:

>>> gocept.lms.filter.HOST_BLACKLIST.add('localhost')


URL classification
==================

The handler classifies HTTP URLs by their host name:

>>> handler.classify('http://localhost/')
'localhost'

>>> handler.classify('https://example.com:8080/foo')
'example.com'


Checking
========

As the URL handler class is abstract, the check method is not implemented:

>>> handler.check('foo')
Traceback (most recent call last):
AttributeError: 'AbstractURLHandler' object has no attribute 'check'
