<commit_before># -*- coding: utf-8 -*-

import spatialite, logtool

#################### Dropbox,flickr etc. credential storage management #############
"""  Wrapper functions around SQL command use for reading/writing/seaching access
credentials for different providers.

The result is normal a list of tuples e.g. [(foo,bar)] for one row and (None,) for no rows.

NOTE: req_key (in dropbox lingo) is "userid" for pcapi
"""

log = logtool.getLogger("tokens", "pcapi")

def dump_tokens():
   res = spatialite.execute("""
       SELECT * FROM tokens;
       """)
   # 2D list of lists
   return res

def save_access_tokens(userid, req_secret, acc_key, acc_secret):
   res = spatialite.execute("""
       INSERT OR IGNORE INTO tokens(userid,reqsec,accsec,acckey) VALUES (?,?,?,?)
       """, (userid,req_secret, acc_key, acc_secret))
   return res==[]

def get_access_pair(userid):
    """ return ( acc_key, acc_secret ) for provided userid or None """
    res = spatialite.execute("""
       SELECT accsec, acckey from tokens WHERE userid=?
       """, (userid,))
    return res[0] if res else None

def delete_token(userid):
    """ delete token with provided userid """
    res = spatialite.execute("""
       DELETE FROM tokens WHERE userid=?
       """, (userid,) )
    return res==[]

### temporary values #####

def get_request_pair(userid):
    """ return ( userid, req_secret ) pair for provided userid or None """
    res = spatialite.execute("""
       SELECT userid, reqsec from temp_request WHERE userid=?
       """, (userid,))
    return res[0] if res else None

def save_unverified_request( userid, req_secret ):
    """ save unverified request keys """
    res = spatialite.execute("""
        INSERT OR IGNORE INTO temp_request(userid,reqsec) VALUES (?,?)
        """, (userid,req_secret))
    return res==[]


def delete_unverified_request(userid):
    res = spatialite.execute("""
        DELETE FROM temp_request WHERE userid=?
        """, (userid,))
    return res == []


def prune_temp_request():
    """ delete temporary requests tables. Should be called at app startup """
    res = spatialite.execute("""
        DELETE FROM temp_request(userid,reqsec) VALUES
        """)
    return res==[]
<commit_msg>Add comment to the delete_unverified_request<commit_after># -*- coding: utf-8 -*-

import spatialite, logtool

#################### Dropbox,flickr etc. credential storage management #############
"""  Wrapper functions around SQL command use for reading/writing/seaching access
credentials for different providers.

The result is normal a list of tuples e.g. [(foo,bar)] for one row and (None,) for no rows.

NOTE: req_key (in dropbox lingo) is "userid" for pcapi
"""

log = logtool.getLogger("tokens", "pcapi")

def dump_tokens():
   res = spatialite.execute("""
       SELECT * FROM tokens;
       """)
   # 2D list of lists
   return res

def save_access_tokens(userid, req_secret, acc_key, acc_secret):
   res = spatialite.execute("""
       INSERT OR IGNORE INTO tokens(userid,reqsec,accsec,acckey) VALUES (?,?,?,?)
       """, (userid,req_secret, acc_key, acc_secret))
   return res==[]

def get_access_pair(userid):
    """ return ( acc_key, acc_secret ) for provided userid or None """
    res = spatialite.execute("""
       SELECT accsec, acckey from tokens WHERE userid=?
       """, (userid,))
    return res[0] if res else None

def delete_token(userid):
    """ delete token with provided userid """
    res = spatialite.execute("""
       DELETE FROM tokens WHERE userid=?
       """, (userid,) )
    return res==[]

### temporary values #####

def get_request_pair(userid):
    """ return ( userid, req_secret ) pair for provided userid or None """
    res = spatialite.execute("""
       SELECT userid, reqsec from temp_request WHERE userid=?
       """, (userid,))
    return res[0] if res else None

def save_unverified_request( userid, req_secret ):
    """ save unverified request keys """
    res = spatialite.execute("""
        INSERT OR IGNORE INTO temp_request(userid,reqsec) VALUES (?,?)
        """, (userid,req_secret))
    return res==[]


def delete_unverified_request(userid):
    """ Delete an user temporary request returns always True """
    res = spatialite.execute("""
        DELETE FROM temp_request WHERE userid=?
        """, (userid,))
    return res == []


def prune_temp_request():
    """ delete temporary requests tables. Should be called at app startup """
    res = spatialite.execute("""
        DELETE FROM temp_request(userid,reqsec) VALUES
        """)
    return res==[]

{'fraction_non_alphanumeric': 0.1431079894644425, 'fraction_numerical': 0.001755926251097454, 'mean_word_length': 3.516352824578791, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3908412', 'n_tokens_mistral': 1419, 'n_tokens_neox': 1372, 'n_words': 428}