Ejemplo n.º 1
0
 def on_loaded(self):
     try:
         raise BrowserUnavailable(
             self.parser.select(self.document.getroot(),
                                'div#message_error_hs', 1).text.strip())
     except BrokenPageError:
         raise BrowserUnavailable()
Ejemplo n.º 2
0
    def login(self):
        assert isinstance(self.username, basestring)
        assert isinstance(self.password, basestring)
        if not self.password.isdigit():
            raise BrowserIncorrectPassword()

        if not self.is_on_page(LoginPage):
            self.location('https://' + self.DOMAIN_LOGIN + '/index.html',
                          no_login=True)

        self.page.login(self.username, self.password)

        if self.is_on_page(LoginPage):
            raise BrowserIncorrectPassword()

        if self.is_on_page(BadLoginPage):
            error = self.page.get_error()
            if error is None:
                raise BrowserIncorrectPassword()
            elif error.startswith('Votre session a'):
                raise BrowserUnavailable('Session has expired')
            elif error.startswith('Le service est momentan'):
                raise BrowserUnavailable(error)
            else:
                raise BrowserIncorrectPassword(error)
Ejemplo n.º 3
0
 def on_loaded(self):
     for td in self.document.getroot().cssselect('td.LibelleErreur'):
         if td.text is None:
             continue
         msg = td.text.strip()
         if 'indisponible' in msg:
             raise BrowserUnavailable(msg)
Ejemplo n.º 4
0
 def on_loaded(self):
     # Check for an error
     for div in self.document.getiterator('div'):
         if div.attrib.get('class',
                           '') == 'dv' and div.getchildren()[0].tag in (
                               'img') and div.getchildren()[0].attrib.get(
                                   'alt', '') == 'Attention':
             # Try to find a detailed error message
             if div.getchildren()[1].tag == 'span':
                 raise BrowserUnavailable(div.find('span').find('b').text)
             elif div.getchildren()[1].tag == 'b':
                 # I haven't encountered this variation in the wild,
                 # but I wouldn't be surprised if it existed
                 # given the similar differences between regions.
                 raise BrowserUnavailable(div.find('b').find('span').text)
             raise BrowserUnavailable()
Ejemplo n.º 5
0
    def on_loaded(self):
        errors = [
            self.parser.tocleanstring(div) for div in self.parser.select(
                self.document.getroot(), 'div.poetry')
        ]

        if errors:
            raise BrowserUnavailable(', '.join(errors))
Ejemplo n.º 6
0
    def get_video(self, url, video=None):
        requires_account = False
        redir_url = None

        # FIXME: this is quite ugly
        # but is required to handle cases like 1013422@gdcvault
        self.set_handle_redirect(False)
        try:
            self.open_novisit(url)
            #headers = req.info()
        except HTTPError as e:
            if e.getcode() == 302 and hasattr(e, 'hdrs'):
                if e.hdrs['Location'] in ['/', '/login']:
                    requires_account = True
                else:
                    # 1015865 redirects to a file with an eacute in the name
                    redir_url = unicode(e.hdrs['Location'], encoding='utf-8')
        self.set_handle_redirect(True)

        if requires_account:
            raise BrowserUnavailable('Requires account')

        if redir_url:
            if video is None:
                m = re.match(
                    'http://[w\.]*gdcvault.com/play/(?P<id>[\d]+)/?.*', url)
                if m:
                    video = GDCVaultVideo(int(m.group(1)))
                else:
                    raise BrowserUnavailable(
                        'Cannot find ID on page with redirection')
            video.url = redir_url
            video.set_empty_fields(NotAvailable)
            # best effort for now
            return video

        self.location(url)
        # redirects to /login means the video is not public
        if not self.is_on_page(VideoPage):
            raise BrowserUnavailable('Requires account')
        return self.page.get_video(video)
Ejemplo n.º 7
0
    def is_logged(self):
        if not self.page or self.is_on_page(LoginPage):
            return False

        error = self.page.get_error()
        if error is None:
            return True

        if error.startswith('Le service est momentan'):
            raise BrowserUnavailable(error)

        return False
Ejemplo n.º 8
0
    def login(self, login, passwd):
        msgb = self.document.xpath(".//*[@id='message_client']/text()")
        msga = ''.join(msgb)
        msg = msga.strip("\n")

        if "maintenance" in msg:
            raise BrowserUnavailable(msg)

        self.browser.select_form(name="acces_identification")
        self.browser['login'] = login.encode('utf-8')
        self.browser['passwd'] = passwd.encode('utf-8')
        self.browser.submit(nologin=True)
Ejemplo n.º 9
0
    def get_location(self, ipaddr):
        with self.browser:

            content = self.browser.readurl(
                'http://www.geolocip.com/?s[ip]=%s&commit=locate+IP!' %
                str(ipaddr))

            if content is None:
                raise BrowserUnavailable()

            tab = {}
            last_line = ''
            line = ''
            for line in content.split('\n'):
                if len(line.split('<dd>')) > 1:
                    key = last_line.split('<dt>')[1].split('</dt>')[0][0:-2]
                    value = line.split('<dd>')[1].split('</dd>')[0]
                    tab[key] = value
                last_line = line
            iploc = IpLocation(ipaddr)
            iploc.city = u'%s' % tab['City']
            iploc.region = u'%s' % tab['Region']
            iploc.zipcode = u'%s' % tab['Postal code']
            iploc.country = u'%s' % tab['Country name']
            if tab['Latitude'] != '':
                iploc.lt = float(tab['Latitude'])
            else:
                iploc.lt = 0.0
            if tab['Longitude'] != '':
                iploc.lg = float(tab['Longitude'])
            else:
                iploc.lg = 0.0
            #iploc.host = 'NA'
            #iploc.tld = 'NA'
            #iploc.isp = 'NA'

            return iploc
Ejemplo n.º 10
0
 def on_loaded(self):
     # We land sometimes on this page, it's better to raise an unavailable browser
     # than an Incorrect Password
     raise BrowserUnavailable('Promo Page')
Ejemplo n.º 11
0
 def on_loaded(self):
     raise BrowserUnavailable()