コード例 #1
0
ファイル: utils.py プロジェクト: foogle/twitalkerplus
def restore_short_id(short_id, jid):
  if short_id < MAX_SHORT_ID_LIST_NUM:
    id_list = IdList.get_by_jid(jid, _user.shard)
    id = id_list.short_id_list[short_id]
    if id:
      return int(id)
  return None
コード例 #2
0
 def func_bind(self, args, oauth_token=None):
     if len(args) == 1 and args[0].isalnum():
         jid = self._google_user.jid
         if oauth_token is None:
             twitter_user = TwitterUser.get_by_twitter_name(None, jid)
             if twitter_user is None:
                 return _('INVALID_PIN_CODE') % ''
             oauth_token = twitter_user.access_token_key
         token = oauth.Token(oauth_token)
         token.set_verifier(args[0].encode('UTF8'))
         consumer = oauth.Consumer(config.OAUTH_CONSUMER_KEY,
                                   config.OAUTH_CONSUMER_SECRET)
         client = oauth.Client(consumer, token)
         resp = client.request(twitter.ACCESS_TOKEN_URL, "POST")
         if not resp:
             return _('NETWORK_ERROR')
         access_token = dict(cgi.parse_qsl(resp))
         if 'oauth_token' not in access_token:
             return _('INVALID_PIN_CODE') % args[0]
         if oauth_token is None:
             twitter_user.delete()
         TwitterUser.add(jid, access_token['oauth_token'],
                         access_token['oauth_token_secret'],
                         access_token['screen_name'])
         if self._google_user.enabled_user == '':
             self._google_user.enabled_user = access_token['screen_name']
         if IdList.get_by_jid(jid, self._google_user.shard) is None:
             IdList.add(jid, self._google_user.shard)
         return _('SUCCESSFULLY_BIND') % access_token['screen_name']
     else:
         raise NotImplementedError
コード例 #3
0
ファイル: xmpp.py プロジェクト: galuano1/twitalkerplus
 def func_bind(self, args, oauth_token=None):
     if len(args) == 1 and args[0].isalnum():
         jid = self._google_user.jid
         if oauth_token is None:
             twitter_user = TwitterUser.get_by_twitter_name(None, jid)
             if twitter_user is None:
                 return _("INVALID_PIN_CODE") % ""
             oauth_token = twitter_user.access_token_key
         token = oauth.Token(oauth_token)
         token.set_verifier(args[0].encode("UTF8"))
         consumer = oauth.Consumer(config.OAUTH_CONSUMER_KEY, config.OAUTH_CONSUMER_SECRET)
         client = oauth.Client(consumer, token)
         resp = client.request(twitter.ACCESS_TOKEN_URL, "POST")
         if not resp:
             return _("NETWORK_ERROR")
         access_token = dict(cgi.parse_qsl(resp))
         if "oauth_token" not in access_token:
             return _("INVALID_PIN_CODE") % args[0]
         if oauth_token is None:
             twitter_user.delete()
         TwitterUser.add(
             jid, access_token["oauth_token"], access_token["oauth_token_secret"], access_token["screen_name"]
         )
         if self._google_user.enabled_user == "":
             self._google_user.enabled_user = access_token["screen_name"]
         if IdList.get_by_jid(jid, self._google_user.shard) is None:
             IdList.add(jid, self._google_user.shard)
         return _("SUCCESSFULLY_BIND") % access_token["screen_name"]
     else:
         raise NotImplementedError
コード例 #4
0
ファイル: xmpp.py プロジェクト: denyany/twitalkerplus
 def func_bind(self, args, oauth_token=None):
   if len(args) == 1 and args[0].isdigit():
     twitter_user = None
     if oauth_token is None:
       twitter_user = TwitterUser.get_by_twitter_name(None, self._google_user.jid)
       if twitter_user is None:
         return _('INVALID_PIN_CODE') % ''
       oauth_token = twitter_user.access_token_key
     token = oauth.Token(oauth_token)
     if type(args[0]) != unicode:
       args[0] = args[0].encode('UTF8')
     token.set_verifier(args[0])
     consumer = oauth.Consumer(config.OAUTH_CONSUMER_KEY, config.OAUTH_CONSUMER_SECRET)
     client = oauth.Client(consumer, token)
     resp = client.request(twitter.ACCESS_TOKEN_URL, "POST")
     if not resp:
       return _('NETWORK_ERROR')
     access_token = dict(cgi.parse_qsl(resp))
     if 'oauth_token' not in access_token:
       return _('INVALID_PIN_CODE') % args[0]
     if twitter_user is not None:
       twitter_user.delete()
     TwitterUser.add(self._google_user.jid, access_token['oauth_token'], access_token['oauth_token_secret'],
                     access_token['screen_name'])
     if self._google_user.enabled_user == '':
       self._google_user.enabled_user = access_token['screen_name']
     if IdList.get_by_jid(self._google_user.jid, self._google_user.shard) is None:
       IdList.add(self._google_user.jid, self._google_user.shard)
     return _('SUCCESSFULLY_BIND') % access_token['screen_name']
   else:
     raise NotImplementedError
コード例 #5
0
ファイル: utils.py プロジェクト: denyany/twitalkerplus
 def generate_short_id(self, id):
   if not db.WRITE_CAPABILITY:
     return None, None
   id = str(id)
   id_list = IdList.get_by_jid(self._jid, self._user.shard)
   if id in id_list.short_id_list:
     if not self.allow_duplicate:
       return None, None
     short_id = id_list.short_id_list.index(id)
   else:
     id_list.list_pointer += 1
     id_list.list_pointer %= MAX_SHORT_ID_LIST_NUM
     id_list.short_id_list[id_list.list_pointer] = id
     IdList.set(self._jid, id_list)
     short_id = id_list.list_pointer
   short_id_str = ''
   t = short_id + 1
   while t > 0:
     if t % 26:
       short_id_str = chr(t % 26 + 64) + short_id_str
       t //= 26
     else:
       short_id_str = 'Z' + short_id_str
       t = t // 26 - 1
   return short_id, short_id_str
コード例 #6
0
ファイル: utils.py プロジェクト: galuano1/twitalkerplus
def restore_short_id(short_id, jid):
    if short_id < MAX_SHORT_ID_LIST_NUM:
        id_list = IdList.get_by_jid(jid, _user.shard)
        id = id_list.short_id_list[short_id]
        if id:
            return int(id)
    return None
コード例 #7
0
ファイル: utils.py プロジェクト: foogle/twitalkerplus
def generate_short_id(id):
  if not db.WRITE_CAPABILITY:
    return None
  id = str(id)
  id_list = IdList.get_by_jid(_jid, _user.shard)
  if id in id_list.short_id_list:
    return id_list.short_id_list.index(id)
  else:
    id_list.list_pointer += 1
    id_list.list_pointer %= MAX_SHORT_ID_LIST_NUM
    id_list.short_id_list[id_list.list_pointer] = id
    IdList.set(_jid, id_list)
    return id_list.list_pointer
コード例 #8
0
ファイル: utils.py プロジェクト: galuano1/twitalkerplus
def generate_short_id(id):
    if not db.WRITE_CAPABILITY:
        return None
    id = str(id)
    id_list = IdList.get_by_jid(_jid, _user.shard)
    if id in id_list.short_id_list:
        return id_list.short_id_list.index(id)
    else:
        id_list.list_pointer += 1
        id_list.list_pointer %= MAX_SHORT_ID_LIST_NUM
        id_list.short_id_list[id_list.list_pointer] = id
        IdList.set(_jid, id_list)
        return id_list.list_pointer
コード例 #9
0
ファイル: utils.py プロジェクト: denyany/twitalkerplus
 def restore_short_id(self, short_id):
   short_id_regex = r'^(?:#)?([a-zA-Z]+|\d+)$'
   m = re.match(short_id_regex, str(short_id))
   if m is None:
     raise ValueError
   g = m.group(1)
   try:
     short_id = int(g)
   except ValueError:
     short_id = 0
     for x in g.lower():
       short_id = short_id * 26 + ord(x) - 96
     short_id -= 1
   if short_id < MAX_SHORT_ID_LIST_NUM:
     id_list = IdList.get_by_jid(self._jid, self._user.shard)
     id = id_list.short_id_list[short_id]
     if id:
       return int(id)
   else:
     return short_id
   return None