torchbox/wagtail — pull request #33 by spapas (2014-02-13 02:13:03+00:00)
Title: Make embedly optional, refactor code and add proper exception handling

This fixes #26. First of all there is some refactoring: All low level
embed functions have been moved to the wagtail.wagtailembeds.embeds
package. There you will see:

. embed.py (which is more or less a copy of the old embeds.py)
. oembed_api.py which includes some low level code for using embedding
with the help of oembed, without any external dependencies (python-oembed
was not working very well and since oembed is just a URL get to a specific
URL I implemented it with urllib2 and json),
. endpoints.json which is a list of oembed endpoints I got from
https://github.com/panzi/oembedendpoints/blob/master/endpoints-regexp.json
. unittests.py with some tests to check that well known sites like
youtube, vimeo etc work fine with the oembed_api

The code refactoring also includes a number of exceptions which are handled
now (instead of just returning None). The get_embed function is included in
try / except blocks and if an exception occurs then the output will be an emtpy
string (this was the behavior before the refactor). However, in the chooser.py
function the type of the exception will be checked and a nice message will be
shown to the editor.

Finally, to choose between embedly and the oembed a check is made to see
if the embedly library has been installed and also check if EMBEDLY_KEY
has been set in the settings. If these two checks are both true then the
get_embed will be assigned to get_embed_embedly -- else it will be
assigned to get_embed_oembed.

Also, the embedly library is now removed from setup.py requirements --
remember to write in the docs what the user should do in case she wants
to actually use it.