12 #define PY_SSIZE_T_CLEAN
27 #include "RNA_prototypes.h"
47 #include "../generic/py_capi_utils.h"
48 #include "../generic/python_utildefines.h"
51 #include "../generic/idprop_py_api.h"
52 #include "../generic/idprop_py_ui_api.h"
62 ".. function:: script_paths()\n"
64 " Return 2 paths to blender scripts directories.\n"
66 " :return: (system, user) strings will be empty when not found.\n"
67 " :rtype: tuple of strings\n");
70 PyObject *
ret = PyTuple_New(2);
77 PyTuple_SET_ITEM(
ret, 0, item);
81 PyTuple_SET_ITEM(
ret, 1, item);
90 PyObject *py_list = bpath_data->
user_data;
96 ".. function:: blend_paths(absolute=False, packed=False, local=False)\n"
98 " Returns a list of paths to external files referenced by the loaded .blend file.\n"
100 " :arg absolute: When true the paths returned are made absolute.\n"
101 " :type absolute: boolean\n"
102 " :arg packed: When true skip file paths for packed data.\n"
103 " :type packed: boolean\n"
104 " :arg local: When true skip linked library paths.\n"
105 " :type local: boolean\n"
106 " :return: path list.\n"
107 " :rtype: list of strings\n");
117 static const char *_keywords[] = {
"absolute",
"packed",
"local",
NULL};
118 static _PyArg_Parser _parser = {
127 if (!_PyArg_ParseTupleAndKeywordsFast(args,
149 list = PyList_New(0);
162 ".. function:: flip_name(name, strip_digits=False)\n"
164 " Flip a name between left/right sides, useful for \n"
165 " mirroring bone names.\n"
167 " :arg name: Bone name to flip.\n"
168 " :type name: string\n"
169 " :arg strip_digits: Whether to remove ``.###`` suffix.\n"
170 " :type strip_digits: bool\n"
171 " :return: The flipped name.\n"
172 " :rtype: string\n");
175 const char *name_src =
NULL;
176 Py_ssize_t name_src_len;
177 bool strip_digits =
false;
179 static const char *_keywords[] = {
"",
"strip_digits",
NULL};
180 static _PyArg_Parser _parser = {
188 if (!_PyArg_ParseTupleAndKeywordsFast(
189 args, kw, &_parser, &name_src, &name_src_len,
PyC_ParseBool, &strip_digits)) {
195 const size_t size = name_src_len + 2;
196 char *name_dst = PyMem_MALLOC(
size);
199 PyObject *
result = PyUnicode_FromStringAndSize(name_dst, name_dst_len);
201 PyMem_FREE(name_dst);
218 const char *subdir =
NULL;
222 static const char *_keywords[] = {
"type",
"path",
NULL};
223 static _PyArg_Parser _parser = {
243 ".. function:: system_resource(type, path=\"\")\n"
245 " Return a system resource path.\n"
247 " :arg type: string in ['DATAFILES', 'SCRIPTS', 'PYTHON'].\n"
248 " :type type: string\n"
249 " :arg path: Optional subdirectory.\n"
250 " :type path: string\n");
261 const char *subdir =
NULL;
265 static const char *_keywords[] = {
"type",
"path",
NULL};
266 static _PyArg_Parser _parser = {
284 bpy_resource_path_doc,
285 ".. function:: resource_path(type, major=bpy.app.version[0], minor=bpy.app.version[1])\n"
287 " Return the base path for storing system files.\n"
289 " :arg type: string in ['USER', 'LOCAL', 'SYSTEM'].\n"
290 " :type type: string\n"
291 " :arg major: major version, defaults to current.\n"
292 " :type major: int\n"
293 " :arg minor: minor version, defaults to current.\n"
294 " :type minor: string\n"
295 " :return: the resource path (not necessarily existing).\n"
296 " :rtype: string\n");
310 static const char *_keywords[] = {
"type",
"major",
"minor",
NULL};
311 static _PyArg_Parser _parser = {
320 if (!_PyArg_ParseTupleAndKeywordsFast(
332 ".. function:: _driver_secure_code_test(code)\n"
334 " Test if the script should be considered trusted.\n"
336 " :arg code: The code to test.\n"
337 " :type code: code\n"
338 " :arg namespace: The namespace of values which are allowed.\n"
339 " :type namespace: dict\n"
340 " :arg verbose: Print the reason for considering insecure to the ``stderr``.\n"
341 " :type verbose: bool\n"
342 " :return: True when the script is considered trusted.\n"
347 PyObject *py_namespace =
NULL;
349 static const char *_keywords[] = {
"code",
"namespace",
"verbose",
NULL};
350 static _PyArg_Parser _parser = {
355 ":driver_secure_code_test",
359 if (!_PyArg_ParseTupleAndKeywordsFast(args,
374 ".. function:: escape_identifier(string)\n"
376 " Simple string escaping function used for animation paths.\n"
378 " :arg string: text\n"
379 " :type string: string\n"
380 " :return: The escaped string.\n"
381 " :rtype: string\n");
384 Py_ssize_t value_str_len;
385 const char *value_str = PyUnicode_AsUTF8AndSize(value, &value_str_len);
387 if (value_str ==
NULL) {
388 PyErr_SetString(PyExc_TypeError,
"expected a string");
392 const size_t size = (value_str_len * 2) + 1;
393 char *value_escape_str = PyMem_MALLOC(
size);
394 const Py_ssize_t value_escape_str_len =
BLI_str_escape(value_escape_str, value_str,
size);
396 PyObject *value_escape;
397 if (value_escape_str_len == value_str_len) {
399 value_escape = value;
402 value_escape = PyUnicode_FromStringAndSize(value_escape_str, value_escape_str_len);
405 PyMem_FREE(value_escape_str);
411 ".. function:: unescape_identifier(string)\n"
413 " Simple string un-escape function used for animation paths.\n"
414 " This performs the reverse of `escape_identifier`.\n"
416 " :arg string: text\n"
417 " :type string: string\n"
418 " :return: The un-escaped string.\n"
419 " :rtype: string\n");
422 Py_ssize_t value_str_len;
423 const char *value_str = PyUnicode_AsUTF8AndSize(value, &value_str_len);
425 if (value_str ==
NULL) {
426 PyErr_SetString(PyExc_TypeError,
"expected a string");
430 const size_t size = value_str_len + 1;
431 char *value_unescape_str = PyMem_MALLOC(
size);
432 const Py_ssize_t value_unescape_str_len =
BLI_str_unescape(value_unescape_str, value_str,
size);
434 PyObject *value_unescape;
435 if (value_unescape_str_len == value_str_len) {
437 value_unescape = value;
440 value_unescape = PyUnicode_FromStringAndSize(value_unescape_str, value_unescape_str_len);
443 PyMem_FREE(value_unescape_str);
445 return value_unescape;
452 bpy_context_members_doc,
453 ".. function:: context_members()\n"
455 " :return: A dict where the key is the context and the value is a tuple of it's members.\n"
472 } context_members_all[] = {
485 for (
int context_index = 0; context_index <
ARRAY_SIZE(context_members_all); context_index++) {
486 const char *name = context_members_all[context_index].name;
487 const char **dir = context_members_all[context_index].dir;
489 for (i = 0; dir[i]; i++) {
492 PyObject *members = PyTuple_New(i);
493 for (i = 0; dir[i]; i++) {
494 PyTuple_SET_ITEM(members, i, PyUnicode_FromString(dir[i]));
496 PyDict_SetItemString(
result, name, members);
508 ".. function:: rna_enum_items_static()\n"
510 " :return: A dict where the key the name of the enum, the value is a tuple of "
511 ":class:`bpy.types.EnumPropertyItem`.\n"
512 " :rtype: dict of \n");
515 #define DEF_ENUM(id) {STRINGIFY(id), id},
523 for (
int i = 0; i <
ARRAY_SIZE(enum_info); i++) {
527 PyObject *value = PyTuple_New(items_count);
528 for (
int item_index = 0; item_index < items_count; item_index++) {
533 PyDict_SetItemString(
result, enum_info[i].
id, value);
540 {
"script_paths", (PyCFunction)
bpy_script_paths, METH_NOARGS, bpy_script_paths_doc},
543 METH_VARARGS | METH_KEYWORDS,
544 bpy_blend_paths_doc},
545 {
"flip_name", (PyCFunction)
bpy_flip_name, METH_VARARGS | METH_KEYWORDS, bpy_flip_name_doc},
549 METH_VARARGS | METH_KEYWORDS,
550 bpy_system_resource_doc},
553 METH_VARARGS | METH_KEYWORDS,
554 bpy_resource_path_doc},
555 {
"_driver_secure_code_test",
557 METH_VARARGS | METH_KEYWORDS,
558 bpy_driver_secure_code_test_doc},
560 {
"unescape_identifier",
563 bpy_unescape_identifier_doc},
564 {
"context_members", (PyCFunction)
bpy_context_members, METH_NOARGS, bpy_context_members_doc},
565 {
"rna_enum_items_static",
568 bpy_rna_enum_items_static_doc},
574 PyObject *
mod = PyImport_ImportModuleLevel(modname,
NULL,
NULL,
NULL, 0);
598 PyObject *sys_path = PySys_GetObject(
"path");
599 PyObject *py_modpath = PyUnicode_FromString(modpath);
600 PyList_Insert(sys_path, 0, py_modpath);
601 Py_DECREF(py_modpath);
604 printf(
"bpy: couldn't find 'scripts/modules', blender probably won't start.\n");
609 #ifdef WITH_FREESTYLE
613 mod = PyModule_New(
"_bpy");
616 PyDict_SetItemString(PyImport_GetModuleDict(),
"_bpy",
mod);
654 BLI_assert((m->ml_flags & (METH_CLASS | METH_STATIC)) == 0);
655 PyModule_AddObject(
mod, m->ml_name, (PyObject *)PyCFunction_New(m,
NULL));
659 PyModule_AddObject(
mod,
662 PyModule_AddObject(
mod,
666 PyModule_AddObject(
mod,
669 PyModule_AddObject(
mod,
const char * BKE_appdir_folder_id_user_notest(int folder_id, const char *subfolder)
const char * BKE_appdir_folder_id_version(int folder_id, int version, bool check_is_dir)
const char * BKE_appdir_folder_id(int folder_id, const char *subfolder)
@ BLENDER_RESOURCE_PATH_SYSTEM
@ BLENDER_RESOURCE_PATH_LOCAL
@ BLENDER_RESOURCE_PATH_USER
@ BLENDER_SYSTEM_DATAFILES
@ BKE_BPATH_FOREACH_PATH_SKIP_LINKED
@ BKE_BPATH_FOREACH_PATH_ABSOLUTE
@ BKE_BPATH_FOREACH_PATH_SKIP_PACKED
void BKE_bpath_foreach_path_main(BPathForeachPathData *bpath_data)
size_t BLI_str_unescape(char *__restrict dst, const char *__restrict src, size_t src_maxncpy) ATTR_NONNULL()
size_t size_t char size_t BLI_str_escape(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL()
size_t BLI_string_flip_side_name(char *r_name, const char *from_name, bool strip_number, size_t name_len)
PyObject * Freestyle_Init(void)
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
static PyObject * bpy_import_test(const char *modname)
PyDoc_STRVAR(bpy_script_paths_doc, ".. function:: script_paths()\n" "\n" " Return 2 paths to blender scripts directories.\n" "\n" " :return: (system, user) strings will be empty when not found.\n" " :rtype: tuple of strings\n")
void BPy_init_modules(struct bContext *C)
static PyObject * bpy_driver_secure_code_test(PyObject *UNUSED(self), PyObject *args, PyObject *kw)
static PyObject * bpy_escape_identifier(PyObject *UNUSED(self), PyObject *value)
static PyObject * bpy_script_paths(PyObject *UNUSED(self))
static PyMethodDef bpy_methods[]
PyObject * bpy_package_py
static PyObject * bpy_resource_path(PyObject *UNUSED(self), PyObject *args, PyObject *kw)
static PyObject * bpy_blend_paths(PyObject *UNUSED(self), PyObject *args, PyObject *kw)
static bool bpy_blend_foreach_path_cb(BPathForeachPathData *bpath_data, char *UNUSED(path_dst), const char *path_src)
static PyObject * bpy_rna_enum_items_static(PyObject *UNUSED(self))
static PyObject * bpy_flip_name(PyObject *UNUSED(self), PyObject *args, PyObject *kw)
static PyObject * bpy_user_resource(PyObject *UNUSED(self), PyObject *args, PyObject *kw)
static PyObject * bpy_system_resource(PyObject *UNUSED(self), PyObject *args, PyObject *kw)
static PyObject * bpy_unescape_identifier(PyObject *UNUSED(self), PyObject *value)
static PyObject * bpy_context_members(PyObject *UNUSED(self))
PyObject * BPY_app_struct(void)
bool BPY_driver_secure_bytecode_test(PyObject *expr_code, PyObject *namespace, const bool verbose)
int BPY_library_load_type_ready(void)
PyObject * BPY_msgbus_module(void)
PyObject * BPY_operator_module(void)
PyObject * BPY_rna_props(void)
PyMethodDef meth_bpy_owner_id_set
PyMethodDef meth_bpy_owner_id_get
PyObject * pyrna_struct_CreatePyObject(PointerRNA *ptr)
PyObject * BPY_rna_module(void)
PyMethodDef meth_bpy_unregister_class
PyMethodDef meth_bpy_register_class
PyObject * BPY_rna_types(void)
BPy_StructRNA * bpy_context_module
int BPY_rna_data_context_type_ready(void)
bool BPY_rna_gizmo_module(PyObject *mod_par)
void BPY_rna_types_extend_capi(void)
PyObject * BPY_utils_previews_module(void)
PyObject * BPY_utils_units(void)
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
btMatrix3x3 absolute() const
Return the matrix with all values non negative.
const char * buttons_context_dir[]
const char * file_context_dir[]
void IDProp_Init_Types(void)
void IDPropertyUIData_Init_Types()
const char * image_context_dir[]
const char * node_context_dir[]
int PyC_ParseStringEnum(PyObject *o, void *p)
PyObject * PyC_UnicodeFromByte(const char *str)
int PyC_ParseBool(PyObject *o, void *p)
void RNA_pointer_create(ID *id, StructRNA *type, void *data, PointerRNA *r_ptr)
unsigned int RNA_enum_items_count(const EnumPropertyItem *item)
const char * screen_context_dir[]
const char * clip_context_dir[]
const char * sequencer_context_dir[]
const char * text_context_dir[]
const char * view3d_context_dir[]
ccl_device_inline int mod(int x, int m)