<commit_before>import urllib2
import feedparser
from datetime import timedelta
from hashlib import sha1

import requests

from django.db import models
from django.conf import settings
from django.core.urlresolvers import reverse, NoReverseMatch
from django.utils.timezone import now

from djpubsubhubbub import signals
from djpubsubhubbub.config import Config

DEFAULT_LEASE_SECONDS = 2592000  # 30 days in seconds


class SubscriptionManager(models.Manager):

    def do_action(self, topic, hub=None, callback=None, lease_seconds=None,
                  mode='subscribe', verify='sync', debug=False):
        config = Config()
        if hub is None:
            hub = self._get_hub(topic)

        if hub is None:
            raise TypeError(
                'hub cannot be None if the feed does not provide it')

        if lease_seconds is None:
            lease_seconds = getattr(settings, 'PUBSUBHUBBUB_LEASE_SECONDS',
                                    DEFAULT_LEASE_SECONDS)

        subscription, created = self.get_or_create(
            hub=hub, topic=topic)
        signals.pre_subscribe.send(sender=subscription, created=created)
        subscription.set_expiration(lease_seconds, run_save=False)
        token = subscription.generate_token(mode)
        headers = config.get_extra_hub_headers(topic, hub)

        if callback is None:
            try:
                callback_path = reverse('pubsubhubbub_callback',
                                        args=(subscription.pk,))
            except NoReverseMatch:
                raise TypeError(
                    'callback cannot be None if there is not a reversible URL')
            else:
                callback = 'https://%s%s' % (
                    config.get_default_callback_host(topic, hub),
                    callback_path
                )

        response = self._send_request(hub, {
            'mode': mode,
            'callback': callback,
            'topic': topic,
            'verify': verify,
            'verify_token': token,
            'lease_seconds': lease_seconds,
        }, headers, debug)

        if response.status_code not in [204, 202]:
            # 204 is sync verification
            # 202 is async verification
            error = response.text
            raise urllib2.URLError(
                'error with mode "%s" to %s on %s:\n%s' %
                (mode, topic, hub, error)
            )

        return subscription
<commit_msg>Add print debugging statements<commit_after>import urllib2
import feedparser
from datetime import timedelta
from hashlib import sha1

import requests

from django.db import models
from django.conf import settings
from django.core.urlresolvers import reverse, NoReverseMatch
from django.utils.timezone import now

from djpubsubhubbub import signals
from djpubsubhubbub.config import Config

DEFAULT_LEASE_SECONDS = 2592000  # 30 days in seconds


class SubscriptionManager(models.Manager):

    def do_action(self, topic, hub=None, callback=None, lease_seconds=None,
                  mode='subscribe', verify='sync', debug=False):
        config = Config()
        if hub is None:
            hub = self._get_hub(topic)

        if hub is None:
            raise TypeError(
                'hub cannot be None if the feed does not provide it')

        if lease_seconds is None:
            lease_seconds = getattr(settings, 'PUBSUBHUBBUB_LEASE_SECONDS',
                                    DEFAULT_LEASE_SECONDS)

        subscription, created = self.get_or_create(
            hub=hub, topic=topic)
        signals.pre_subscribe.send(sender=subscription, created=created)
        subscription.set_expiration(lease_seconds, run_save=False)
        token = subscription.generate_token(mode)
        headers = config.get_extra_hub_headers(topic, hub)

        if callback is None:
            try:
                callback_path = reverse('pubsubhubbub_callback',
                                        args=(subscription.pk,))
            except NoReverseMatch:
                raise TypeError(
                    'callback cannot be None if there is not a reversible URL')
            else:
                callback = 'https://%s%s' % (
                    config.get_default_callback_host(topic, hub),
                    callback_path
                )

        response = self._send_request(hub, {
            'mode': mode,
            'callback': callback,
            'topic': topic,
            'verify': verify,
            'verify_token': token,
            'lease_seconds': lease_seconds,
        }, headers, debug)

        print response.status_code
        print response
        print callback

        if response.status_code not in [204, 202]:
            # 204 is sync verification
            # 202 is async verification
            error = response.text
            raise urllib2.URLError(
                'error with mode "%s" to %s on %s:\n%s' %
                (mode, topic, hub, error)
            )

        return subscription

{'fraction_non_alphanumeric': 0.07329738366287197, 'fraction_numerical': 0.009586578789694428, 'mean_word_length': 1.925233644859813, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2265898', 'n_tokens_mistral': 1354, 'n_tokens_neox': 1277, 'n_words': 373}