from terroroftinytown.services.base import BaseService, html_unescape
import re
from terroroftinytown.client.errors import UnexpectedNoResult
from terroroftinytown.services.status import URLStatus
class AlturlService(BaseService):
def process_unavailable(self, response):
if response.status_code != 410:
return BaseService.process_unavailable(self, response)
match = re.search(r'was forwarding to:
(.*)', response.text)
if not match:
if re.search(r'This shortURL address was REMOVED for SPAMMING', response.text):
return URLStatus.unavailable, None, None
if not match and 'REMOVED FOR SPAMMING' in response.text:
return URLStatus.unavailable, None, None
if not match:
raise UnexpectedNoResult(
"Could not find target URL on blocked page for {0}"
.format(self.current_shortcode))
url = html_unescape(match.group(1))
return URLStatus.ok, url, response.encoding