<commit_before>/*
 * Comment by Kang. This lib dose not support non_interactive mode
 */
#include <glib.h>
#include <dbus/dbus.h>
#include <gnome-keyring.h>

#include "Python.h"
#include "keyring_util.h"

static PyObject*
gnome_keyring_password_get(PyObject *self, PyObject *args)
{
    const char *realmstring;
    const char *username;
    const char *password;
    int non_interactive = 0;

    if (!PyArg_ParseTuple(args, "ss|i", &realmstring, &username, 
            &non_interactive)){
        PyErr_Clear();
        PyErr_SetString(PyExc_TypeError, 
                "password_get() must be called as (servicename,username)");
        return NULL;
    }
    if (non_interactive || (! dbus_bus_get(DBUS_BUS_SESSION,NULL)) || 
            (!gnome_keyring_is_available())){
        PyErr_Clear();
        PyErr_SetString(PyExc_OSError, "Can's access the keyring now");
        return NULL;
    }

    GnomeKeyringResult result;
    GList *items;

    result = gnome_keyring_find_network_password_sync(username, realmstring, 
                                           NULL, NULL, NULL, NULL, 0, &items);

    int status = 0;
    if (result == GNOME_KEYRING_RESULT_OK){
        if (items && items->data){
            GnomeKeyringNetworkPasswordData *item;
            item = (GnomeKeyringNetworkPasswordData *)items->data;
            if (item->password){
                size_t len = strlen(item->password);
                if (len > 0){
                    password = string_dump(item->password, len);
                }
                status = 1;
            }
            gnome_keyring_network_password_list_free(items);
    }
    }  

    if (!status){
        PyErr_Clear();
        PyErr_SetString(PyExc_OSError, "Can't fech password from system");
        return NULL;
    }
    
    return Py_BuildValue("s",password); 
}
static PyObject*
gnome_keyring_password_set(PyObject *self, PyObject *args)
{
    const char *realmstring;
    const char *username;
    const char *password;
    int  non_interactive = 0;

    if (!PyArg_ParseTuple(args, "sss|i", &realmstring, &username, &password, 
            &non_interactive)){
        PyErr_Clear();
        PyErr_SetString(PyExc_TypeError,
            "password_set() must be called as (servicename,username,password)");
        return NULL;
    }
    if (non_interactive || (! dbus_bus_get(DBUS_BUS_SESSION,NULL)) || 
            (!gnome_keyring_is_available())){
        PyErr_Clear();
        PyErr_SetString(PyExc_OSError,
            "Can's access the keyring now");
        return NULL;
    }


    GnomeKeyringResult result;
    guint32 item_id;<commit_msg>Remove the non_interactive mode from the GnomeKeyring backend.<commit_after>/*
 * Comment by Kang. This lib dose not support non_interactive mode
 */
#include <glib.h>
#include <dbus/dbus.h>
#include <gnome-keyring.h>

#include "Python.h"
#include "keyring_util.h"

static PyObject*
gnome_keyring_password_get(PyObject *self, PyObject *args)
{
    const char *realmstring;
    const char *username;
    const char *password;

    if (!PyArg_ParseTuple(args, "ss", &realmstring, &username)){
        PyErr_Clear();
        PyErr_SetString(PyExc_TypeError, 
                "password_get() must be called as (servicename,username)");
        return NULL;
    }
    if ((! dbus_bus_get(DBUS_BUS_SESSION,NULL)) || 
            (!gnome_keyring_is_available())){
        PyErr_Clear();
        PyErr_SetString(PyExc_OSError, "Can's access the keyring now");
        return NULL;
    }

    GnomeKeyringResult result;
    GList *items;

    result = gnome_keyring_find_network_password_sync(username, realmstring, 
                                           NULL, NULL, NULL, NULL, 0, &items);

    int status = 0;
    if (result == GNOME_KEYRING_RESULT_OK){
        if (items && items->data){
            GnomeKeyringNetworkPasswordData *item;
            item = (GnomeKeyringNetworkPasswordData *)items->data;
            if (item->password){
                size_t len = strlen(item->password);
                if (len > 0){
                    password = string_dump(item->password, len);
                }
                status = 1;
            }
            gnome_keyring_network_password_list_free(items);
    }
    }  

    if (!status){
        PyErr_Clear();
        PyErr_SetString(PyExc_OSError, "Can't fech password from system");
        return NULL;
    }
    
    return Py_BuildValue("s",password); 
}
static PyObject*
gnome_keyring_password_set(PyObject *self, PyObject *args)
{
    const char *realmstring;
    const char *username;
    const char *password;

    if (!PyArg_ParseTuple(args, "sss", &realmstring, &username, &password)){
        PyErr_Clear();
        PyErr_SetString(PyExc_TypeError,
            "password_set() must be called as (servicename,username,password)");
        return NULL;
    }
    if ((! dbus_bus_get(DBUS_BUS_SESSION,NULL)) || 
            (!gnome_keyring_is_available())){
        PyErr_Clear();
        PyErr_SetString(PyExc_OSError,
            "Can's access the keyring now");
        return NULL;
    }


    GnomeKeyringResult result;
    guint32 item_id;
{'fraction_non_alphanumeric': 0.10744929797191888, 'fraction_numerical': 0.002730109204368175, 'mean_word_length': 2.460863697705803, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7637407', 'n_tokens_mistral': 1658, 'n_tokens_neox': 1579, 'n_words': 344}