Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 0cc862c
Showing
22 changed files
with
424 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.pyc | ||
.installed.cfg | ||
bin | ||
develop-eggs | ||
dist | ||
downloads | ||
eggs | ||
parts | ||
django_push.egg-info |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
Copyright (c) 2010 Bruno Renié | ||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without modification, | ||
are permitted provided that the following conditions are met: | ||
|
||
1. Redistributions of source code must retain the above copyright notice, | ||
this list of conditions and the following disclaimer. | ||
|
||
2. Redistributions in binary form must reproduce the above copyright | ||
notice, this list of conditions and the following disclaimer in the | ||
documentation and/or other materials provided with the distribution. | ||
|
||
3. Neither the name of this project nor the names of its contributors may be | ||
used to endorse or promote products derived from this software without | ||
specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR | ||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | ||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
Django-PuSH | ||
=========== | ||
|
||
PubSubHubbub support for Django | ||
|
||
Publisher | ||
--------- | ||
|
||
TBA | ||
|
||
|
||
Subscriber | ||
---------- | ||
|
||
TBA | ||
|
||
|
||
Hub | ||
--- | ||
|
||
TBA |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
############################################################################## | ||
# | ||
# Copyright (c) 2006 Zope Foundation and Contributors. | ||
# All Rights Reserved. | ||
# | ||
# This software is subject to the provisions of the Zope Public License, | ||
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. | ||
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED | ||
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS | ||
# FOR A PARTICULAR PURPOSE. | ||
# | ||
############################################################################## | ||
"""Bootstrap a buildout-based project | ||
Simply run this script in a directory containing a buildout.cfg. | ||
The script accepts buildout command-line options, so you can | ||
use the -c option to specify an alternate configuration file. | ||
$Id: bootstrap.py 105417 2009-11-01 15:15:20Z tarek $ | ||
""" | ||
|
||
import os, shutil, sys, tempfile, urllib2 | ||
from optparse import OptionParser | ||
|
||
tmpeggs = tempfile.mkdtemp() | ||
|
||
is_jython = sys.platform.startswith('java') | ||
|
||
# parsing arguments | ||
parser = OptionParser() | ||
parser.add_option("-v", "--version", dest="version", | ||
help="use a specific zc.buildout version") | ||
parser.add_option("-d", "--distribute", | ||
action="store_true", dest="distribute", default=False, | ||
help="Use Disribute rather than Setuptools.") | ||
|
||
parser.add_option("-c", None, action="store", dest="config_file", | ||
help=("Specify the path to the buildout configuration " | ||
"file to be used.")) | ||
|
||
options, args = parser.parse_args() | ||
|
||
# if -c was provided, we push it back into args for buildout' main function | ||
if options.config_file is not None: | ||
args += ['-c', options.config_file] | ||
|
||
if options.version is not None: | ||
VERSION = '==%s' % options.version | ||
else: | ||
VERSION = '' | ||
|
||
USE_DISTRIBUTE = options.distribute | ||
args = args + ['bootstrap'] | ||
|
||
try: | ||
import pkg_resources | ||
import setuptools | ||
if not hasattr(pkg_resources, '_distribute'): | ||
raise ImportError | ||
except ImportError: | ||
ez = {} | ||
if USE_DISTRIBUTE: | ||
exec urllib2.urlopen('http://python-distribute.org/distribute_setup.py' | ||
).read() in ez | ||
ez['use_setuptools'](to_dir=tmpeggs, download_delay=0, no_fake=True) | ||
else: | ||
exec urllib2.urlopen('http://peak.telecommunity.com/dist/ez_setup.py' | ||
).read() in ez | ||
ez['use_setuptools'](to_dir=tmpeggs, download_delay=0) | ||
|
||
reload(sys.modules['pkg_resources']) | ||
import pkg_resources | ||
|
||
if sys.platform == 'win32': | ||
def quote(c): | ||
if ' ' in c: | ||
return '"%s"' % c # work around spawn lamosity on windows | ||
else: | ||
return c | ||
else: | ||
def quote (c): | ||
return c | ||
|
||
cmd = 'from setuptools.command.easy_install import main; main()' | ||
ws = pkg_resources.working_set | ||
|
||
if USE_DISTRIBUTE: | ||
requirement = 'distribute' | ||
else: | ||
requirement = 'setuptools' | ||
|
||
if is_jython: | ||
import subprocess | ||
|
||
assert subprocess.Popen([sys.executable] + ['-c', quote(cmd), '-mqNxd', | ||
quote(tmpeggs), 'zc.buildout' + VERSION], | ||
env=dict(os.environ, | ||
PYTHONPATH= | ||
ws.find(pkg_resources.Requirement.parse(requirement)).location | ||
), | ||
).wait() == 0 | ||
|
||
else: | ||
assert os.spawnle( | ||
os.P_WAIT, sys.executable, quote (sys.executable), | ||
'-c', quote (cmd), '-mqNxd', quote (tmpeggs), 'zc.buildout' + VERSION, | ||
dict(os.environ, | ||
PYTHONPATH= | ||
ws.find(pkg_resources.Requirement.parse(requirement)).location | ||
), | ||
) == 0 | ||
|
||
ws.add_entry(tmpeggs) | ||
ws.require('zc.buildout' + VERSION) | ||
import zc.buildout.buildout | ||
zc.buildout.buildout.main(args) | ||
shutil.rmtree(tmpeggs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
[buildout] | ||
parts = python django feedparser | ||
develop = . | ||
eggs = django-push | ||
|
||
[python] | ||
recipe = zc.recipe.egg | ||
interpreter = python | ||
eggs = ${buildout:eggs} | ||
|
||
[django] | ||
recipe = djangorecipe | ||
version = 1.2.1 | ||
project = django_push | ||
projectegg = django_push | ||
settings = test_settings | ||
test = django_push | ||
eggs = ${buildout:eggs} | ||
|
||
[feedparser] | ||
recipe = gocept.download | ||
url = http://pypi.python.org/packages/source/F/FeedParser/feedparser-4.1.tar.gz | ||
md5sum = 573a8df4d4305b37107040654f52b826 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# -*- coding: utf-8 -*- | ||
import os | ||
from setuptools import setup, find_packages | ||
|
||
def read(file_name): | ||
return open(os.path.join(os.path.dirname(__file__), file_name)).read() | ||
|
||
setup( | ||
name = 'django-push', | ||
version = '0.1', | ||
url = 'http://bitbucket.org/bruno/django-push', | ||
license = 'BSD', | ||
description = 'PubSubHubbub (PuSH) support for Django', | ||
long_description = read('README'), | ||
|
||
author = 'Bruno Renié', | ||
author_email = 'bruno@renie.fr', | ||
|
||
packages = find_packages('src'), | ||
package_dir = {'': 'src'}, | ||
|
||
install_requires = ['setuptools'], | ||
|
||
classifiers = [ | ||
## FIXME | ||
], | ||
) |
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import urllib | ||
import urllib2 | ||
|
||
|
||
def ping_hub(hub_url, feed_url): | ||
params = { | ||
'hub.mode': 'publish', | ||
'hub.url': feed_url, | ||
} | ||
data = urllib.urlencode(params) | ||
try: | ||
response = urllib2.urlopen(hub_url, data) | ||
except urllib2.HTTPError, e: | ||
if hasattr(e, 'code') and e.code == 204: | ||
continue | ||
raise |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import datetime | ||
import urllib | ||
import urllib2 | ||
|
||
from django.conf import settings | ||
from django.contrib.sites.models import Site | ||
from django.core.urlresolvers import reverse | ||
from django.db import models | ||
from django.utils.hashcompat import sha_constructor | ||
from django.utils.translation import ugettext_lazy as _ | ||
|
||
from django_push.subscriber.utils import get_hub | ||
|
||
LEASE_SECONDS = getattr(settings, 'PUSH_LEASE_SECONDS', None) | ||
|
||
|
||
class SubscriptionManager(models.Manager): | ||
|
||
def subscribe(self, topic, hub=None, lease_seconds=LEASE_SECONDS): | ||
if hub is None: | ||
hub = get_hub(topic) | ||
|
||
subscription, created = self.get_or_create(hub=hub, topic=topic) | ||
callback_url = reverse('subscriber_callback', args=[subscription.id]) | ||
callback = 'http://%s%s' % (Site.objects.get_current(), callback_url) | ||
|
||
params = { | ||
'mode': 'subscribe', | ||
'callback': callback, | ||
'topic': topic, | ||
'verify': ('async', 'sync'), | ||
'verify_token': subscription.generate_token('subscribe'), | ||
} | ||
if lease_seconds is not None: | ||
params['lease_seconds'] = lease_seconds | ||
# If not present, the lease is permanent | ||
response = self.subscription_request(hub, params) | ||
|
||
info = response.info | ||
if info.status == 204: | ||
subscription.verified = True | ||
elif info.status == 202: # deferred verification | ||
subscription.verified = False | ||
else: | ||
error = response.read() | ||
raise urllib2.HTTPError('Subscription error on %s: %s' % (topic, | ||
error)) | ||
subscription.save() | ||
return subscription | ||
|
||
def subscription_request(self, hub, params): | ||
def get_post_data(): | ||
for key, value in params.items(): | ||
key = 'hub.%s' % key | ||
if isinstance(value, (basestring, int)): | ||
yield key, str(value) | ||
else: | ||
for subvalue in value: | ||
yield key, str(subvalue) | ||
data = urllib.urlencode(list(get_post_data())) | ||
return urllib2.urlopen(hub, data) | ||
|
||
|
||
class Subscription(models.Model): | ||
callback = models.URLField(_('Callback'), max_length=1023) | ||
topic = models.URLField(_('Topic'), max_length=1023) | ||
verified = models.BooleanField(_('Verified'), default=False) | ||
verifify_token = models.CharField(_('Verify Token'), max_length=255) | ||
lease_expiration = models.DateTimeField(_('Lease expiration')) | ||
|
||
def generate_token(self, mode): | ||
digest = sha_constructor('%s%i%s' % (settings.SECRET_KEY, | ||
self.pk, mode)).hexdigest() | ||
self.verify_token = mode[:20] + digest | ||
self.save() | ||
return self.verify_token |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.dispatch import Signal | ||
|
||
updated = Signal(providing_args=['notification']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from django.test import TestCase | ||
|
||
|
||
class SubscriberTest(TestCase): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.conf.urls.defaults import * | ||
|
||
|
||
urlpatterns = patterns('django_push.subscriber.views', | ||
url(r'^(?P<pk>\d+)/$', 'callback', name='subscriber_callback'), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import feedparser | ||
|
||
|
||
def get_hub(topic): | ||
parsed = feedparser.parse(topic) | ||
for link in parse.feed.links: | ||
if link['rel'] == 'hub': | ||
return link['href'] | ||
raise TypeError, "Hub not found" |
Oops, something went wrong.