def get_valid_graph_obj(obj, obj_type=None): """Returns a new graph object that is guaranteed to pass validate(). CAREFUL: this will *silently* strip out invalid pieces of the object. """ try: new_obj = graph_objs.get_class_instance_by_name(obj.__class__.__name__) except KeyError: try: new_obj = graph_objs.get_class_instance_by_name(obj_type) except KeyError: raise exceptions.PlotlyError( "'{0}' nor '{1}' are recognizable graph_objs.".format( obj.__class__.__name__, obj_type)) if isinstance(new_obj, list): new_obj += obj else: for key, val in list(obj.items()): new_obj[key] = val new_obj.force_clean() return new_obj
def get_valid_graph_obj(obj, obj_type=None): """Returns a new graph object that is guaranteed to pass validate(). CAREFUL: this will *silently* strip out invalid pieces of the object. """ try: new_obj = graph_objs.get_class_instance_by_name( obj.__class__.__name__) except KeyError: try: new_obj = graph_objs.get_class_instance_by_name(obj_type) except KeyError: raise exceptions.PlotlyError( "'{0}' nor '{1}' are recognizable graph_objs.". format(obj.__class__.__name__, obj_type)) if isinstance(new_obj, list): new_obj += obj else: for key, val in list(obj.items()): new_obj[key] = val new_obj.force_clean() return new_obj
def validate(obj, obj_type): """Validate a dictionary, list, or graph object as 'obj_type'. This will not alter the 'obj' referenced in the call signature. It will raise an error if the 'obj' reference could not be instantiated as a valid 'obj_type' graph object. """ try: obj_type = graph_objs.KEY_TO_NAME[obj_type] except KeyError: pass try: test_obj = graph_objs.get_class_instance_by_name(obj_type, obj) except KeyError: raise exceptions.PlotlyError( "'{0}' is not a recognizable graph_obj.".format(obj_type))
def validate(obj, obj_type): """Validate a dictionary, list, or graph object as 'obj_type'. This will not alter the 'obj' referenced in the call signature. It will raise an error if the 'obj' reference could not be instantiated as a valid 'obj_type' graph object. """ try: obj_type = graph_objs.KEY_TO_NAME[obj_type] except KeyError: pass try: test_obj = graph_objs.get_class_instance_by_name(obj_type, obj) except KeyError: raise exceptions.PlotlyError( "'{0}' is not a recognizable graph_obj.". format(obj_type))
def test_names_in_name_to_class(): for key in graph_objs.INFO.keys(): class_name = graph_objs.KEY_TO_NAME[key] graph_obj_class = graph_objs.get_class_instance_by_name(class_name)