Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2013-04-05 04:30:32 +0400
committerCampbell Barton <ideasman42@gmail.com>2013-04-05 04:30:32 +0400
commit98752a1f3025a138b5a2f70f60a2cca1e89d2f66 (patch)
tree9d6adf01f7fa74d7e995675ff466532167d8ba49 /source/blender
parentdee2f0c9ac8312ff71241d86591adb8f9b06c53a (diff)
py api additions needed for fixing [#34864].
- add rna property 'as_bytes' method so you can get a string property as python bytes (bypass encoding). - make bpy.path.abspath/relpath compatible with bytes. - add 'relpath' option to bpy_extras.image_utils.load_image(), so you can load an image relative to a path.
Diffstat (limited to 'source/blender')
-rw-r--r--source/blender/python/intern/bpy_rna.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c
index d6a82ce43ea..df66ef92316 100644
--- a/source/blender/python/intern/bpy_rna.c
+++ b/source/blender/python/intern/bpy_rna.c
@@ -3324,6 +3324,40 @@ static PyObject *pyrna_prop_path_from_id(BPy_PropertyRNA *self)
return ret;
}
+PyDoc_STRVAR(pyrna_prop_as_bytes_doc,
+".. method:: as_bytes()\n"
+"\n"
+" Returns this string property as a byte rather then a python string.\n"
+"\n"
+" :return: The string as bytes.\n"
+" :rtype: bytes\n"
+);
+static PyObject *pyrna_prop_as_bytes(BPy_PropertyRNA *self)
+{
+
+ if (RNA_property_type(self->prop) != PROP_STRING) {
+ PyErr_Format(PyExc_TypeError,
+ "%.200s.%.200s.as_bytes() must be a string",
+ RNA_struct_identifier(self->ptr.type), RNA_property_identifier(self->prop));
+ return NULL;
+ }
+ else {
+ PyObject *ret;
+ char buf_fixed[256], *buf;
+ int buf_len;
+
+ buf = RNA_property_string_get_alloc(&self->ptr, self->prop, buf_fixed, sizeof(buf_fixed), &buf_len);
+
+ ret = PyBytes_FromStringAndSize(buf, buf_len);
+
+ if (buf_fixed != buf) {
+ MEM_freeN(buf);
+ }
+
+ return ret;
+ }
+}
+
PyDoc_STRVAR(pyrna_struct_type_recast_doc,
".. method:: type_recast()\n"
"\n"
@@ -4685,6 +4719,7 @@ static struct PyMethodDef pyrna_struct_methods[] = {
static struct PyMethodDef pyrna_prop_methods[] = {
{"path_from_id", (PyCFunction)pyrna_prop_path_from_id, METH_NOARGS, pyrna_prop_path_from_id_doc},
+ {"as_bytes", (PyCFunction)pyrna_prop_as_bytes, METH_NOARGS, pyrna_prop_as_bytes_doc},
{"__dir__", (PyCFunction)pyrna_prop_dir, METH_NOARGS, NULL},
{NULL, NULL, 0, NULL}
};