Exemple #1
0
    def execute_ping(instance):
        """Ping blog directories

        Arguments::

        - `instance` - object, which is the source for pingbacks
        - `content_attr` - name of attribute, which contains content with links,
        must be HTML. Can be callable.
        - `url_attr` - name of attribute, which contains url of object. Can be
        callable.
        """
        domain = Site.objects.get_current().domain
        content = callab(getattr(instance, content_attr))
        blog_name = settings.BLOG_NAME
        blog_url = 'http://%s/' % domain
        object_url = 'http://%s%s' % (domain,
                                      callab(getattr(instance, url_attr)))
        # TODO: cleanup generation of RSS feed and use it here instead of ATOM feed
        # because ATOM feed is not supported well by some ugly sites
        feed_url = 'http://%s%s' % (domain, reverse('atom_feed', args=['blog'
                                                                       ]))

        #TODO: execute this code in the thread
        for directory_url in settings.DIRECTORY_URLS:
            ping = DirectoryPing(object=instance, url=directory_url)
            try:
                server = ServerProxy(directory_url)
                try:
                    q = server.weblogUpdates.extendedPing(
                        blog_name, blog_url, object_url, feed_url)
                #TODO: Find out name of exception :-)
                except Exception, ex:
                    q = server.weblogUpdates.ping(blog_name, blog_url,
                                                  object_url)
                if q.get('flerror'):
                    ping.success = False
                else:
                    ping.success = True
            except (IOError, ValueError, Fault), e:
                pass
Exemple #2
0
    def execute_ping(instance):
        """Ping blog directories

        Arguments::

        - `instance` - object, which is the source for pingbacks
        - `content_attr` - name of attribute, which contains content with links,
        must be HTML. Can be callable.
        - `url_attr` - name of attribute, which contains url of object. Can be
        callable.
        """
        domain = Site.objects.get_current().domain
        content = callab(getattr(instance, content_attr))
        blog_name = settings.BLOG_NAME
        blog_url = 'http://%s/' % domain
        object_url = 'http://%s%s' % (domain, callab(getattr(instance, url_attr)))
        # TODO: cleanup generation of RSS feed and use it here instead of ATOM feed
        # because ATOM feed is not supported well by some ugly sites
        feed_url = 'http://%s%s' % (domain, reverse('atom_feed', args=['blog']))

        #TODO: execute this code in the thread
        for directory_url in settings.DIRECTORY_URLS:
            ping = DirectoryPing(object=instance, url=directory_url)
            try:
                server = ServerProxy(directory_url)
                try:
                    q = server.weblogUpdates.extendedPing(blog_name, blog_url, object_url, feed_url)
                #TODO: Find out name of exception :-)
                except Exception, ex:
                    q = server.weblogUpdates.ping(blog_name, blog_url, object_url)
                if q.get('flerror'):
                    ping.success = False
                else:
                    ping.success = True
            except (IOError, ValueError, Fault), e:
                pass
Exemple #3
0
    def execute_dirs_ping(instance, **kwargs):
        log = logging.getLogger('pingback')
        log.debug('pinging directories')

        if not filtr(instance):
            return
        site = getattr(instance, 'site', Site.objects.get_current())
        if content_attr is None:
            content = content_func(instance)
        else:
            content = maybe_call(getattr(instance, content_attr))
        protocol = getattr(settings, 'SITE_PROTOCOL', 'http')
        url = maybe_call(getattr(instance, url_attr))
        feed_url = feed_url_fun(instance)
        domain = site.domain
        feed_url = '%s://%s%s' % (protocol, domain, feed_url)
        blog_url = '%s://%s/' % (protocol, domain)
        url = urljoin(blog_url, url)

        #TODO: execute this code in the thread
        for directory_url in settings.DIRECTORY_URLS:
            log.debug('pinging directory %r' % directory_url)

            ping = DirectoryPing(object=instance, url=directory_url)
            try:
                server = ServerProxy(directory_url)
                try:
                    q = server.weblogUpdates.extendedPing(
                        site.name, blog_url, url, feed_url)
                #TODO: Find out name of exception :-)
                except Exception, ex:
                    try:
                        q = server.weblogUpdates.ping(site.name, blog_url, url)
                    except ProtocolError, e:
                        log.exception(
                            'protocol error during directory ping %r' %
                            directory_url)
                        ping.success = False
                        ping.save()
                        return execute_dirs_ping
                if q.get('flerror'):
                    ping.success = False
                    log.error('flerror: %s' % q.get('message', 'no message'))
                else:
                    ping.success = True
Exemple #4
0
    def execute_dirs_ping(instance, **kwargs):
        log = logging.getLogger('pingback')
        log.debug('pinging directories')

        if not filtr(instance):
            return
        site = getattr(instance, 'site', Site.objects.get_current())
        if content_attr is None:
            content = content_func(instance)
        else:
            content = maybe_call(getattr(instance, content_attr))
        protocol = getattr(settings, 'SITE_PROTOCOL', 'http')
        url = maybe_call(getattr(instance, url_attr))
        feed_url = feed_url_fun(instance)
        domain = site.domain
        feed_url = '%s://%s%s' % (protocol, domain, feed_url)
        blog_url = '%s://%s/' % (protocol, domain)
        url = urljoin(blog_url, url)

        #TODO: execute this code in the thread
        for directory_url in settings.DIRECTORY_URLS:
            log.debug('pinging directory %r' % directory_url)

            ping = DirectoryPing(object=instance, url=directory_url)
            try:
                server = ServerProxy(directory_url)
                try:
                    q = server.weblogUpdates.extendedPing(site.name, blog_url, url, feed_url)
                #TODO: Find out name of exception :-)
                except Exception, ex:
                    try:
                        q = server.weblogUpdates.ping(site.name, blog_url, url)
                    except ProtocolError, e:
                        log.exception('protocol error during directory ping %r' % directory_url)
                        ping.success = False
                        ping.save()
                        return execute_dirs_ping
                if q.get('flerror'):
                    ping.success = False
                    log.error('flerror: %s' % q.get('message', 'no message'))
                else:
                    ping.success = True