Commit 06eff14e authored by Johan Dahlin's avatar Johan Dahlin

Use an environment variable to ensure the module is only imported from

        * src/nautilus-python.c: (nautilus_python_init_python):
        * src/nautilusmodule.c: (initnautilus): Use an environment variable to
        ensure the module is only imported from nautilus-python itself.
        Fixes bug #161946
parent fa306d9b
2005-05-30 Johan Dahlin <johan@gnome.org>
* src/nautilus-python.c: (nautilus_python_init_python):
* src/nautilusmodule.c: (initnautilus): Use an environment variable to
ensure the module is only imported from nautilus-python itself.
Fixes bug #161946
2005-05-17 Johan Dahlin <jdahlin@async.com.br> 2005-05-17 Johan Dahlin <jdahlin@async.com.br>
* src/nautilus-python-object.c * src/nautilus-python-object.c
......
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */ /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
/* /*
* Copyright (C) 2004 Johan Dahlin * Copyright (C) 2004,2005 Johan Dahlin
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
...@@ -120,23 +120,31 @@ nautilus_python_init_python (void) ...@@ -120,23 +120,31 @@ nautilus_python_init_python (void)
Py_Initialize(); Py_Initialize();
PySys_SetArgv(1, argv); PySys_SetArgv(1, argv);
/* pygtk.require("2.0") */
pygtk = PyImport_ImportModule("pygtk"); pygtk = PyImport_ImportModule("pygtk");
mdict = PyModule_GetDict(pygtk); mdict = PyModule_GetDict(pygtk);
require = PyDict_GetItemString(mdict, "require"); require = PyDict_GetItemString(mdict, "require");
PyObject_CallObject(require, Py_BuildValue("(S)", PyString_FromString("2.0"))); PyObject_CallObject(require, Py_BuildValue("(S)", PyString_FromString("2.0")));
/* import gobject */
debug("init_pygobject"); debug("init_pygobject");
np_init_pygobject(); np_init_pygobject();
/* import gtk */
debug("init_pygtk"); debug("init_pygtk");
np_init_pygtk(); np_init_pygtk();
/* import gnomevfs */
debug("init_gnomevfs"); debug("init_gnomevfs");
np_init_pygnomevfs(); np_init_pygnomevfs();
/* gobject.threads_init() */
debug("pyg_enable_threads"); debug("pyg_enable_threads");
setenv("PYGTK_USE_GIL_STATE_API", "", 0); setenv("PYGTK_USE_GIL_STATE_API", "", 0);
pyg_enable_threads(); pyg_enable_threads();
/* gtk.pygtk_version < (2, 4, 0) */
gtk = PyImport_ImportModule("gtk"); gtk = PyImport_ImportModule("gtk");
mdict = PyModule_GetDict(gtk); mdict = PyModule_GetDict(gtk);
pygtk_version = PyDict_GetItemString(mdict, "pygtk_version"); pygtk_version = PyDict_GetItemString(mdict, "pygtk_version");
...@@ -150,6 +158,7 @@ nautilus_python_init_python (void) ...@@ -150,6 +158,7 @@ nautilus_python_init_python (void)
} }
Py_DECREF(pygtk_required_version); Py_DECREF(pygtk_required_version);
/* sys.path.insert(., ...) */
debug("sys.path.insert(0, ...)"); debug("sys.path.insert(0, ...)");
sys_path = PySys_GetObject("path"); sys_path = PySys_GetObject("path");
PyList_Insert(sys_path, 0, PyList_Insert(sys_path, 0,
...@@ -160,6 +169,8 @@ nautilus_python_init_python (void) ...@@ -160,6 +169,8 @@ nautilus_python_init_python (void)
PyList_Insert(sys_path, 2, PyList_Insert(sys_path, 2,
PyString_FromString(NAUTILUS_LIBDIR "/nautilus/extensions-1.0/python")); PyString_FromString(NAUTILUS_LIBDIR "/nautilus/extensions-1.0/python"));
/* import nautilus */
g_setenv("INSIDE_NAUTILUS_PYTHON", "", FALSE);
debug("import nautilus"); debug("import nautilus");
nautilus = PyImport_ImportModule("nautilus"); nautilus = PyImport_ImportModule("nautilus");
if (!nautilus) { if (!nautilus) {
...@@ -167,6 +178,7 @@ nautilus_python_init_python (void) ...@@ -167,6 +178,7 @@ nautilus_python_init_python (void)
return FALSE; return FALSE;
} }
/* Extract types and interfaces from nautilus */
mdict = PyModule_GetDict(nautilus); mdict = PyModule_GetDict(nautilus);
#define IMPORT(x, y) \ #define IMPORT(x, y) \
......
...@@ -26,8 +26,6 @@ ...@@ -26,8 +26,6 @@
/* include this first, before NO_IMPORT_PYGOBJECT is defined */ /* include this first, before NO_IMPORT_PYGOBJECT is defined */
#include <pygtk/pygtk.h> #include <pygtk/pygtk.h>
#include <libgnome/gnome-program.h>
void pynautilus_register_classes (PyObject *d); void pynautilus_register_classes (PyObject *d);
void pynautilus_add_constants(PyObject *module, const gchar *strip_prefix); void pynautilus_add_constants(PyObject *module, const gchar *strip_prefix);
...@@ -37,10 +35,8 @@ DL_EXPORT(void) ...@@ -37,10 +35,8 @@ DL_EXPORT(void)
initnautilus(void) initnautilus(void)
{ {
PyObject *m, *d; PyObject *m, *d;
GnomeProgram *program;
program = gnome_program_get(); if (!g_getenv("INSIDE_NAUTILUS_PYTHON")) {
if (!program || strcmp (gnome_program_get_app_id(program), "nautilus") != 0) {
Py_FatalError("This module can only be used from nautilus"); Py_FatalError("This module can only be used from nautilus");
return; return;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment