Esempio n. 1
0
 def _make_request(self, method, data):
     result = fetch(
         self.method_map[method] % {'api-key': self.key, 'domain': self.domain},
         data,
         headers={
             'Content-type': 'application/x-www-form-urlencoded',
         },
         timeout=5,
     )
     return result
Esempio n. 2
0
def ping(source_uri, target_uri, id):
    try:
        try:
            Pingback.objects.get(
                source_url=source_uri,
                target_url=target_uri,
                incoming=True
            )
            return 48
        except Pingback.DoesNotExist:
            pass

        domain = Site.objects.get_current().domain
        scheme, server, path, query, fragment = urlsplit(target_uri)

        try:
            post = Post.objects.get(pk=id)
        except Post.DoesNotExist:
            return 33

        if post.get_absolute_url() != path + query:
            return 33

        try:
            doc = fetch(source_uri).content
        except (urllib2.HTTPError, urllib2.URLError, socket.timeout), e:
            return 16

        parser = utils.SourceParser(doc)
        paragraph = parser.get_paragraph(target_uri)
        if paragraph is None:
            return 17

        pingback = Pingback.objects.create(
            source_url=source_uri,
            target_url=target_uri,
            incoming=True,
            title=parser.get_title(),
            paragraph=paragraph,
            status='Pingback from %s to %s registered. Keep the web talking! :-)' % (source_uri, target_uri),
            post=post,
            finished=True
        )

        signals.pingback_recieved.send(
            sender=post.__class__,
            instance=post,
            pingback=pingback
        )

        return pingback.status
Esempio n. 3
0
    def handle_noargs(self, **options):
        for source in Source.objects.all():
            response = fetch(source.url, headers={'Accept': ', '.join(get_accept())})

            if response.status_code != '200':
                logger.error('Cannot fetch whitelist from %s. Got: %s' % (source.url, response.status_code))
                continue

            source.identities.all().delete()

            parser, mimetype = get_parser(response.headers['content-type'])
            if parser:
                for id in parser(response.content):
                    Identity.objects.create(openid=id, source=source)
Esempio n. 4
0
def get_rpc_gateway(target_uri):
    try:
        response = fetch(target_uri)
        return response.headers.get('X-Pingback', '') or search_link(response.content[:512 * 1024])
    except (IOError, ValueError), e:
        return None