Esempio n. 1
0
    def auth(self, username, password):
        '''Estableciendo credenciales'''
        self.username = username
        self.password = password

        try:
            self.token = self.__fetch_xauth_access_token(username, password)

            return (self.token.key, self.token.secret)
        except Exception, exc:
            self.log.debug("Auth error: %s" % (traceback.print_exc()))
            raise TurpialException(_('Authentication Error'))
Esempio n. 2
0
class IdenticaHTTP(TurpialHTTP):
    def __init__(self):
        TurpialHTTP.__init__(self, POST_ACTIONS)
        self.log = logging.getLogger('IdenticaHTTP')

    def build_token(self, auth):
        return FakeToken()

    def request(self, uri, args={}):
        try:
            rtn = self.do_request(uri, args)
            return rtn
        except urllib2.HTTPError, exc:
            self.log.debug(
                ("HTTPError for URL: %s\nparameters: (%s)\n"
                 "details: %s") % (uri, args, traceback.print_exc()))
            if (exc.code == 304):
                return []
            elif (exc.code == 400):
                raise TurpialException(
                    _('Sorry, you don\'t have more API'
                      'calls'))
            elif (exc.code == 401):
                raise TurpialException(_('Invalid credentials'))
            elif (exc.code == 403):
                rtn = exc.read()
                print 'Error 403:', rtn
                if rtn.find("Status is a duplicate.") > 0:
                    msg = _('Your status was sent. Don\'t try again')
                elif rtn.find("is already on your list.") > 0:
                    msg = _('%s already is a friend')
                else:
                    msg = _('Hey! You are over the limit of API calls')
                raise TurpialException(msg)
            elif (exc.code == 404):
                raise TurpialException(_('Err... invalid request'))
            elif (exc.code == 406):
                raise TurpialException(
                    _('You are searching a very weird thing'))
            elif (exc.code == 420):
                raise TurpialException(_('You are searching too much!'))
            elif (exc.code == 500):
                raise TurpialException(_('Oops! Something went wrong'))
            elif (exc.code == 502):
                raise TurpialException(_('Twitter is down. Try again later'))
            elif (exc.code == 503):
                raise TurpialException(_('Twitter is overcapacity'))
        except urllib2.URLError, exc:
            self.log.debug(
                "URLError for URL: %s\nparameters: (%s)\ndetails: %s" %
                (uri, args, traceback.print_exc()))
            raise TurpialException(_('Can\'t connect to Twitter'))
Esempio n. 3
0
 def request(self, uri, args={}):
     try:
         rtn = self.do_request(uri, args)
         return rtn
     except urllib2.HTTPError, exc:
         self.log.debug(
             "HTTPError for URL: %s\nparameters: (%s)\ndetails: %s" %
             (uri, args, traceback.print_exc()))
         if (exc.code == 304):
             return []
         elif (exc.code == 400):
             #X-RateLimit-Remaining
             raise TurpialException(
                 _('Sorry, you don\'t have more API'
                   'calls'))
         elif (exc.code == 401):
             raise TurpialException(_('Invalid credentials'))
         elif (exc.code == 403):
             rtn = exc.read()
             print 'Error 403:', rtn
             if rtn.find("Status is a duplicate.") > 0:
                 msg = _('Your status was sent. Don\'t try again')
             elif rtn.find("is already on your list.") > 0:
                 msg = _('%s already is a friend')
             elif rtn.find("already requested to follow") > 0:
                 msg = _('You\'ve already requested to follow %s')
             else:
                 msg = _('Hey! You are over the limit of API calls')
             raise TurpialException(msg)
         elif (exc.code == 404):
             raise TurpialException(_('Err... invalid request'))
         elif (exc.code == 406):
             raise TurpialException(
                 _('You are searching a very weird thing'))
         elif (exc.code == 420):
             raise TurpialException(_('You are searching too much!'))
         elif (exc.code == 500):
             raise TurpialException(_('Oops! Something went wrong'))
         elif (exc.code == 502):
             raise TurpialException(_('Twitter is down. Try again later'))
         elif (exc.code == 503):
             raise TurpialException(_('Twitter is overcapacity'))
Esempio n. 4
0
                elif rtn.find("already requested to follow") > 0:
                    msg = _('You\'ve already requested to follow %s')
                else:
                    msg = _('Hey! You are over the limit of API calls')
                raise TurpialException(msg)
            elif (exc.code == 404):
                raise TurpialException(_('Err... invalid request'))
            elif (exc.code == 406):
                raise TurpialException(
                    _('You are searching a very weird thing'))
            elif (exc.code == 420):
                raise TurpialException(_('You are searching too much!'))
            elif (exc.code == 500):
                raise TurpialException(_('Oops! Something went wrong'))
            elif (exc.code == 502):
                raise TurpialException(_('Twitter is down. Try again later'))
            elif (exc.code == 503):
                raise TurpialException(_('Twitter is overcapacity'))
        except urllib2.URLError, exc:
            self.log.debug(
                "URLError for URL: %s\nparameters: (%s)\ndetails: %s" %
                (uri, args, traceback.print_exc()))
            raise TurpialException(_('Can\'t connect to Twitter'))
        except ssl.SSLError:
            raise TurpialException(_("SSL certificate doesn't match"))
        except Exception, exc:
            self.log.debug(("Unknown error for URL:"
                            " %s\nparameters: (%s)\ndetails: %s") %
                           (uri, args, traceback.print_exc()))
            raise TurpialException(exc)
Esempio n. 5
0
            elif (exc.code == 404):
                raise TurpialException(_('Err... invalid request'))
            elif (exc.code == 406):
                raise TurpialException(
                    _('You are searching a very weird thing'))
            elif (exc.code == 420):
                raise TurpialException(_('You are searching too much!'))
            elif (exc.code == 500):
                raise TurpialException(_('Oops! Something went wrong'))
            elif (exc.code == 502):
                raise TurpialException(_('Twitter is down. Try again later'))
            elif (exc.code == 503):
                raise TurpialException(_('Twitter is overcapacity'))
        except urllib2.URLError, exc:
            self.log.debug(
                "URLError for URL: %s\nparameters: (%s)\ndetails: %s" %
                (uri, args, traceback.print_exc()))
            raise TurpialException(_('Can\'t connect to Twitter'))
        except Exception, exc:
            self.log.debug(
                "Unknown error for URL: %s\nparameters: (%s)\ndetails: %s" %
                (uri, args, traceback.print_exc()))
            raise TurpialException(exc)


class FakeToken:
    def __init__(self):
        self.key = ''
        self.secret = ''
        self.verifier = ''
Esempio n. 6
0
            elif (exc.code == 406):
                raise TurpialException(
                    _('You are searching a very weird thing'))
            elif (exc.code == 420):
                raise TurpialException(_('You are searching too much!'))
            elif (exc.code == 500):
                raise TurpialException(_('Oops! Something went wrong'))
            elif (exc.code == 502):
                raise TurpialException(_('Twitter is down. Try again later'))
            elif (exc.code == 503):
                raise TurpialException(_('Twitter is overcapacity'))
        except urllib2.URLError, exc:
            self.log.debug(
                "URLError for URL: %s\nparameters: (%s)\ndetails: %s" %
                (uri, args, traceback.print_exc()))
            raise TurpialException(_('Can\'t connect to Twitter'))
        except ssl.SSLError:
            raise TurpialException(_("SSL certificate doesn't match"))
        except Exception, exc:
            self.log.debug(
                "Unknown error for URL: %s\nparameters: (%s)\ndetails: %s" %
                (uri, args, traceback.print_exc()))
            raise TurpialException(exc)


class FakeToken:
    def __init__(self):
        self.key = ''
        self.secret = ''
        self.verifier = ''
Esempio n. 7
0
                else:
                    msg = _('Hey! You are over the limit of API calls')
                raise TurpialException(msg)
            elif (exc.code == 404):
                raise TurpialException(_('Err... invalid request'))
            elif (exc.code == 406):
                raise TurpialException(_('You are searching a very weird thing'))
            elif (exc.code == 420):
                raise TurpialException(_('You are searching too much!'))
            elif (exc.code == 500):
                raise TurpialException(_('Oops! Something went wrong'))
            elif (exc.code == 502):
                raise TurpialException(_('Twitter is down. Try again later'))
            elif (exc.code == 503):
                raise TurpialException(_('Twitter is overcapacity'))
        except urllib2.URLError, exc:
            self.log.debug(
                "URLError for URL: %s\nparameters: (%s)\ndetails: %s" % (
                    uri, args, traceback.print_exc()
                )
            )
            raise TurpialException(_('Can\'t connect to Twitter'))
        except Exception, exc:
            self.log.debug((
                "Unknown error for URL:"
                " %s\nparameters: (%s)\ndetails: %s") % (
                    uri, args, traceback.print_exc()
                )
            )
            raise TurpialException(exc)