# Path: blango/spider.py
# class Spider(BaseSpider):
#     def __init__(self, uri, data = ''):
#         super(Spider, self).__init__(uri)
#         self.data = data
# 
#     def pingback(self, source):
#         if not self._require_fetch():
#             return False
#         pburi = self.stream.headers.get('X-Pingback')
#         if not pburi:
#             r = re.compile('<link.*?rel="pingback".*?href="([^"]+)" ?/?>', re.I)
#             m = r.search(self.data)
#             if not m:
#                 return False
#             pburi = m.group(1)
#         server = ServerProxy(pburi)
#         try:
#             server.pingback.ping(source, self.uri)
#             return True
#         except Error, v:
#             return False
# 
#     def trackback(self, url, page_name='', title='', excerpt=''):
#         if not self._require_fetch():
#             print self.code
#             return False
# 
#         r = re.compile('trackback:ping="([^"]+)"')
#         m = r.search(self.data)
#         if not m:
#             return False
#         tburi = m.group(1)
#         t = Spider(tburi)
#         t.request.add_header('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8')
#         values = { 'title': title,
#             'excerpt': excerpt,
#             'url': url,
#             'blog_name': page_name }
#         data = urllib.urlencode(values)
#         t.request = urllib2.Request(tburi, data)
#         t.fetch()
#         return t.data.find('<error>0</error>') != -1
# 
#     def backlinks(self, back):
#         if not self._require_fetch():
#             return False
# 
#         r = re.compile('<a.*?href="%s".*>' % back)
#         return r.search(self.data) != None
# 
# def hostname_from_uri(uri, http=True):
#     if not is_absolute_link(uri):
#         return None
# 
#     if http:
#         return '/'.join(uri.split('/')[:3])
# 
#     return uri.split('/')[2]
# 
# def is_absolute_link(link):
#     return link.startswith('http://') or link.startswith('https://')
# 
# Path: blango/paginator.py
# class QuerySetPaginator(Paginator):
#     """
#     Like Paginator, but works on QuerySets.
#     """
#     def _get_count(self):
#         if self._count is None:
#             self._count = self.object_list.count()
#         return self._count
#     count = property(_get_count)


from datetime import date
from xml.etree import cElementTree
from django.shortcuts import get_object_or_404
from django.http import HttpResponse, HttpResponseRedirect
from django.views.generic.simple import direct_to_template
from django.utils.translation import ugettext as _
from blango.spider import Spider, hostname_from_uri, is_absolute_link
from blango.paginator import QuerySetPaginator
from blango.models import *
from blango.forms import *
                if child.tag == 'string':
                    self.params.append(child.text)
                if child.tag in ('int', 'i4'):
                    self.params.append(int(child.text))
                if child.tag == 'boolean':
                    self.params.append(child.text == '1')
                if child.tag == 'double':
                    self.params.append(float(chold.text))
                # Missing types, but for now, only strings are needed
            return method()
        else:
            return XmlRpcDispatcher.fault(1, 'Invalid method')

    def pingback_ping(self):
        source = self.params[0]
        target = self.params[1]
        slug = target.split('/')[-2]
        try:
            entry = Entry.objects.get(slug=slug)
            if not entry.allow_comments:
                raise Entry.DoesNotExist
        except Entry.DoesNotExist:
            return XmlRpcDispatcher.fault(33, 'The specified URI cannot be used as target')

        try:
            Comment.objects.get(entry=entry, type__in=['P', 'T'], author_uri=source)
            return XmlRpcDispatcher.fault(48, 'The pingback has already been registered')
        except Comment.DoesNotExist:
            pass


# Path: blango/spider.py
# class Spider(BaseSpider):
#     def __init__(self, uri, data = ''):
#         super(Spider, self).__init__(uri)
#         self.data = data
# 
#     def pingback(self, source):
#         if not self._require_fetch():
#             return False
#         pburi = self.stream.headers.get('X-Pingback')
#         if not pburi:
#             r = re.compile('<link.*?rel="pingback".*?href="([^"]+)" ?/?>', re.I)
#             m = r.search(self.data)
#             if not m:
#                 return False
#             pburi = m.group(1)
#         server = ServerProxy(pburi)
#         try:
#             server.pingback.ping(source, self.uri)
#             return True
#         except Error, v:
#             return False
# 
#     def trackback(self, url, page_name='', title='', excerpt=''):
#         if not self._require_fetch():
#             print self.code
#             return False
# 
#         r = re.compile('trackback:ping="([^"]+)"')
#         m = r.search(self.data)
#         if not m:
#             return False
#         tburi = m.group(1)
#         t = Spider(tburi)
#         t.request.add_header('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8')
#         values = { 'title': title,
#             'excerpt': excerpt,
#             'url': url,
#             'blog_name': page_name }
#         data = urllib.urlencode(values)
#         t.request = urllib2.Request(tburi, data)
#         t.fetch()
#         return t.data.find('<error>0</error>') != -1
# 
#     def backlinks(self, back):
#         if not self._require_fetch():
#             return False
# 
#         r = re.compile('<a.*?href="%s".*>' % back)
#         return r.search(self.data) != None
# 
# def hostname_from_uri(uri, http=True):
#     if not is_absolute_link(uri):
#         return None
# 
#     if http:
#         return '/'.join(uri.split('/')[:3])
# 
#     return uri.split('/')[2]
# 
# def is_absolute_link(link):
#     return link.startswith('http://') or link.startswith('https://')
# 
# Path: blango/paginator.py
# class QuerySetPaginator(Paginator):
#     """
#     Like Paginator, but works on QuerySets.
#     """
#     def _get_count(self):
#         if self._count is None:
#             self._count = self.object_list.count()
#         return self._count
#     count = property(_get_count)


# Path: blango/views.py
from datetime import date
from xml.etree import cElementTree
from django.shortcuts import get_object_or_404
from django.http import HttpResponse, HttpResponseRedirect
from django.views.generic.simple import direct_to_template
from django.utils.translation import ugettext as _
from blango.spider import Spider, hostname_from_uri, is_absolute_link
from blango.paginator import QuerySetPaginator
from blango.models import *
from blango.forms import *

                if child.tag == 'string':
                    self.params.append(child.text)
                if child.tag in ('int', 'i4'):
                    self.params.append(int(child.text))
                if child.tag == 'boolean':
                    self.params.append(child.text == '1')
                if child.tag == 'double':
                    self.params.append(float(chold.text))
                # Missing types, but for now, only strings are needed
            return method()
        else:
            return XmlRpcDispatcher.fault(1, 'Invalid method')

    def pingback_ping(self):
        source = self.params[0]
        target = self.params[1]
        slug = target.split('/')[-2]
        try:
            entry = Entry.objects.get(slug=slug)
            if not entry.allow_comments:
                raise Entry.DoesNotExist
        except Entry.DoesNotExist:
            return XmlRpcDispatcher.fault(33, 'The specified URI cannot be used as target')

        try:
            Comment.objects.get(entry=entry, type__in=['P', 'T'], author_uri=source)
            return XmlRpcDispatcher.fault(48, 'The pingback has already been registered')
        except Comment.DoesNotExist:
            pass


        s = Spider(source)