Revision: 39698
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=39698
Author:   campbellbarton
Date:     2011-08-25 17:01:33 +0000 (Thu, 25 Aug 2011)
Log Message:
-----------
bpy-rna - simplify enum string/set parsing.

Modified Paths:
--------------
    trunk/blender/source/blender/python/intern/bpy_rna.c

Modified: trunk/blender/source/blender/python/intern/bpy_rna.c
===================================================================
--- trunk/blender/source/blender/python/intern/bpy_rna.c        2011-08-25 
16:47:47 UTC (rev 39697)
+++ trunk/blender/source/blender/python/intern/bpy_rna.c        2011-08-25 
17:01:33 UTC (rev 39698)
@@ -1117,6 +1117,7 @@
        return 1;
 }
 
+/* 'value' _must_ be a set type, error check before calling */
 int pyrna_set_to_enum_bitfield(EnumPropertyItem *items, PyObject *value, int 
*r_value, const char *error_prefix)
 {
        /* set of enum items, concatenate all values with OR */
@@ -1138,8 +1139,10 @@
                                     error_prefix, Py_TYPE(key)->tp_name);
                        return -1;
                }
-               if(pyrna_enum_value_from_id(items, param, &ret, error_prefix) < 
0)
+
+               if(pyrna_enum_value_from_id(items, param, &ret, error_prefix) < 
0) {
                        return -1;
+               }
 
                flag |= ret;
        }
@@ -1156,6 +1159,14 @@
 
        *r_value= 0;
 
+       if (!PyAnySet_Check(value)) {
+               PyErr_Format(PyExc_TypeError,
+                            "%.200s, %.200s.%.200s expected a set, not a 
%.200s",
+                            error_prefix, RNA_struct_identifier(ptr->type),
+                            RNA_property_identifier(prop), 
Py_TYPE(value)->tp_name);
+               return -1;
+       }
+
        RNA_property_enum_items(BPy_GetContext(), ptr, prop, &item, NULL, 
&free);
 
        if(item) {
@@ -1529,34 +1540,19 @@
                {
                        int val= 0;
 
-                       if (PyUnicode_Check(value)) {
-                               if (!pyrna_string_to_enum(value, ptr, prop, 
&val, error_prefix))
+                       /* type checkins is done by each function */
+                       if(RNA_property_flag(prop) & PROP_ENUM_FLAG) {
+                               /* set of enum items, concatenate all values 
with OR */
+                               if(pyrna_prop_to_enum_bitfield(ptr, prop, 
value, &val, error_prefix) < 0) {
                                        return -1;
-                       }
-                       else if (PyAnySet_Check(value)) {
-                               if(RNA_property_flag(prop) & PROP_ENUM_FLAG) {
-                                       /* set of enum items, concatenate all 
values with OR */
-                                       if(pyrna_prop_to_enum_bitfield(ptr, 
prop, value, &val, error_prefix) < 0)
-                                               return -1;
                                }
-                               else {
-                                       PyErr_Format(PyExc_TypeError,
-                                                    "%.200s, %.200s.%.200s is 
not a bitflag enum type",
-                                                    error_prefix, 
RNA_struct_identifier(ptr->type),
-                                                    
RNA_property_identifier(prop));
+                       }
+                       else {
+                               /* simple enum string */
+                               if (!pyrna_string_to_enum(value, ptr, prop, 
&val, error_prefix) < 0) {
                                        return -1;
                                }
                        }
-                       else {
-                               const char *enum_str= pyrna_enum_as_string(ptr, 
prop);
-                               PyErr_Format(PyExc_TypeError,
-                                            "%.200s %.200s.%.200s expected a 
string enum or a set of strings in (%.2000s), not %.200s",
-                                            error_prefix, 
RNA_struct_identifier(ptr->type),
-                                            RNA_property_identifier(prop), 
enum_str,
-                                            Py_TYPE(value)->tp_name);
-                               MEM_freeN((void *)enum_str);
-                               return -1;
-                       }
 
                        if(data)        *((int*)data)= val;
                        else            RNA_property_enum_set(ptr, prop, val);

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to