Exemplo n.º 1
0
    def process_redirect(self, response):
        status, link, encoding = BaseService.process_redirect(self, response)

        if link.startswith('/') and link.endswith('/'):
            url = self.params['url_template'].format(shortcode=self.current_shortcode) + '/'
            response = self.fetch_url(url, 'head')

            status, link, encoding = BaseService.process_redirect(self, response)

        if link in ('https://myspace.com/404', 'http://myspace.com/404'):
            return URLStatus.not_found, None, None

        else:
            return status, link, encoding
Exemplo n.º 2
0
    def process_redirect(self, response):
        if response.status_code == 302:
            if 'location' not in response.headers:
                raise UnexpectedNoResult()

            url = urlparse.urlparse(response.headers['location'])

            if url.scheme != "http" or url.netloc != "bit.ly" or url.path != "/a/warning":
                raise UnexpectedNoResult("Unexpected Location header after HTTP status 302")

            if sys.version_info[0] == 2:
                query = urlparse.parse_qs(url.query.encode('latin-1'))
            else:
                query = urlparse.parse_qs(url.query)

            if not ("url" in query and len(query["url"]) == 1) or not ("hash" in query and len(query["hash"]) == 1):
                raise UnexpectedNoResult("Unexpected Location header after HTTP status 302")
            if query["hash"][0] != self.current_shortcode:
                raise UnexpectedNoResult("Hash mismatch for HTTP status 302")

            if sys.version_info[0] == 2:
                unshortened_url = query["url"][0].decode('latin-1')
            else:
                unshortened_url = query["url"][0]

            return (URLStatus.ok, unshortened_url, None)

        else:
            return BaseService.process_redirect(self, response)
Exemplo n.º 3
0
    def process_redirect(self, response):
        status, url, encoding = BaseService.process_redirect(self, response)

        if url == 'http://yatuc.com':
            return URLStatus.not_found, None, None
        else:
            return status, url, encoding
Exemplo n.º 4
0
    def process_redirect(self, response):
        status, url, encoding = BaseService.process_redirect(self, response)

        if status == URLStatus.ok:
            if url == 'http://www.godaddy.com/default.aspx?isc=xcowebgd':
                return URLStatus.not_found, None, None

        return status, url, encoding
Exemplo n.º 5
0
    def process_redirect(self, response):
        status, url, encoding = BaseService.process_redirect(self, response)

        if url.startswith('http://totally.awe.sm/') and \
                url.endswith(self.current_shortcode):
            return URLStatus.not_found, None, None
        else:
            return status, url, encoding
Exemplo n.º 6
0
    def process_redirect(self, response):
        try:
            url_status, link, encoding = BaseService.process_redirect(self, response)
        except UnexpectedNoResult:
            if "Location" not in response.headers:
                return URLStatus.not_found, None, None
            else:
                raise

        if link == "/site/getprivate?snip=" + self.current_shortcode:
            return URLStatus.unavailable, None, None
        else:
            return url_status, link, encoding
Exemplo n.º 7
0
    def process_redirect(self, response):
        try:
            url_status, link, encoding = BaseService.process_redirect(
                self, response)
        except UnexpectedNoResult:
            if 'Location' not in response.headers:
                return URLStatus.not_found, None, None
            else:
                raise

        if link == "/site/getprivate?snip=" + self.current_shortcode:
            return URLStatus.unavailable, None, None
        else:
            return url_status, link, encoding
Exemplo n.º 8
0
    def process_redirect(self, response):
        if response.status_code == 200:
            return self._fetch_200(response)
        else:
            if 'Location' in response.headers and response.status_code == 301:
                tiny = response.headers.get("X-tiny")

                if tiny and tiny[:3] == "aff":
                    return self._preview(self.current_shortcode,
                                         response.headers['Location'])

            try:
                return BaseService.process_redirect(self, response)
            except UnexpectedNoResult:
                return (URLStatus.unavailable, None, None)
Exemplo n.º 9
0
    def process_redirect(self, response):
        if response.status_code == 200:
            return self._fetch_200(response)
        else:
            if 'Location' in response.headers and response.status_code == 301:
                tiny = response.headers.get("X-tiny")

                if tiny and tiny[:3] == "aff":
                    return self._preview(
                        self.current_shortcode, response.headers['Location']
                    )

            try:
                return BaseService.process_redirect(self, response)
            except UnexpectedNoResult:
                return (URLStatus.unavailable, None, None)
Exemplo n.º 10
0
 def process_redirect(self, response):
     try:
         return BaseService.process_redirect(self, response)
     except UnexpectedNoResult:
         return (URLStatus.not_found, None, None)