Changeset 808 for trunk/python


Ignore:
Timestamp:
Oct 29, 2007, 1:16:24 PM (17 years ago)
Author:
dkearney
Message:

allow the user to create a new empty rappture library object in c++ and python bindings. this is useful when you want to create new xml files.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/python/Rappture/PyRpLibrary.cc

    r795 r808  
    9595    int retVal = 1;
    9696
    97     if (!PyArg_ParseTuple(args, "O", &inObj)) {
     97    if (!PyArg_ParseTuple(args, "|O", &inObj)) {
    9898        PyErr_Format(PyExc_TypeError,
    99             "library() takes 1 argument, a file name or a Rappture Library Object");
     99            "library() takes at most 1 argument, a file name or a Rappture Library Object");
    100100        return -1;
    101101    }
    102102
    103     if (PyString_Check(inObj)) {
    104         filename = PyString_AsString(inObj);
    105         if (filename == NULL) {
    106             PyErr_Format(PyExc_ValueError,"a file name is required");
    107         }
    108         self->lib = new RpLibrary(std::string(filename));
    109     }
    110     else if (RpLibraryObject_IsValid(inObj)) {
    111         self->lib = new RpLibrary( *(RpLibraryObject_AsLibrary(inObj)) );
    112     }
    113     else if (RpLibraryObject_Check(inObj)) {
     103    if (inObj != NULL) {
     104        if (PyString_Check(inObj)) {
     105            filename = PyString_AsString(inObj);
     106            if (filename == NULL) {
     107                PyErr_Format(PyExc_ValueError,"a file name is required");
     108            }
     109            self->lib = new RpLibrary(std::string(filename));
     110        }
     111        else if (RpLibraryObject_IsValid(inObj)) {
     112            self->lib = new RpLibrary( *(RpLibraryObject_AsLibrary(inObj)) );
     113        }
     114        else if (RpLibraryObject_Check(inObj)) {
     115            self->lib = new RpLibrary();
     116        }
     117        else {
     118            PyErr_Format(PyExc_TypeError,"unrecognized object type");
     119            return -1;
     120        }
     121    }
     122    else {
    114123        self->lib = new RpLibrary();
    115     }
    116     else {
    117         PyErr_Format(PyExc_TypeError,"unrecognized object type");
    118         return -1;
    119124    }
    120125
Note: See TracChangeset for help on using the changeset viewer.