Esempio n. 1
0
static PyObject *PyView_modify(PyView *o, PyObject *_args) {
  try {
    PWOSequence args(_args);
    if (!PyProperty_Check((PyObject *)args[0]))
      Fail(PyExc_TypeError, "First arg must be a property");

    c4_BytesProp& prop = *(c4_BytesProp*)(c4_Property*)(PyProperty*)(PyObject*)args[0];

    int index = PWONumber(args[1]);
    if (index < 0 || index >= o->GetSize())
      Fail(PyExc_IndexError, "Index out of range");

    c4_RowRef row = o->GetAt(index);

    PWOString buffer (args[2]);
    c4_Bytes data ((void*)(const char*)buffer, buffer.len());

    long offset = PWONumber(args[3]);
    int diff = args.len() == 4 ? 0 : (int) PWONumber(args[4]);

    if (!prop(row).Modify(data, offset, diff))
      Fail(PyExc_TypeError, "Failed to modify memo field");

    Py_INCREF(Py_None);
    return Py_None;
  }
  catch (...) { return 0; }
}
Esempio n. 2
0
void PyView::addProperties(const PWOSequence& lst) {
  for (int i=0; i<lst.len(); i++) {
    if (PyProperty_Check((PyObject* )lst[i])) {
      AddProperty(*(PyProperty*)(PyObject* )lst[i]);
    }
  }
}
Esempio n. 3
0
static PyObject *PyStorage_new(PyObject *o, PyObject *_args) {
  try {
    PWOSequence args(_args);
    PyStorage *ps = 0;
    switch (args.len()) {
      case 0:
        ps = new PyStorage;
        break;
      case 1:
        if (!PyFile_Check((PyObject*)args[0])) {
          if (PyString_Check((PyObject*)args[0]))
            Fail(PyExc_TypeError, "rw parameter missing");
          else
            Fail(PyExc_TypeError, "argument not an open file");
          break;
        }
        ps = new PyStorage(*new c4_FileStrategy(PyFile_AsFile(args[0])), true);
        break;
      case 4:
         { // Rrrrrr...
          if (!PyStorage_Check((PyObject*)args[0]))
            Fail(PyExc_TypeError, "First arg must be a storage object");
          c4_Storage &storage = *(PyStorage*)(PyObject*)args[0];
          if (!PyView_Check((PyObject*)args[1]))
            Fail(PyExc_TypeError, "Second arg must be a view object");
          c4_View &view = *(PyView*)(PyObject*)args[1];
          if (!PyProperty_Check((PyObject*)args[2]))
            Fail(PyExc_TypeError, "Third arg must be a property object");
          c4_BytesProp &prop = *(c4_BytesProp*)(c4_Property*)(PyProperty*)
            (PyObject*)args[2];
          int row = PWONumber(args[3]);

          ps = new PyStorage(*new SiasStrategy(storage, view, prop, row), true);
          break;
        }
      case 2:
         {
          char *fnm;
          int mode;
          if (!PyArg_ParseTuple(args, "esi", "utf_8", &fnm, &mode))
            Fail(PyExc_TypeError, "bad argument type");
          ps = new PyStorage(fnm, mode);
          PyMem_Free(fnm);
          if (!ps->Strategy().IsValid()) {
            delete ps;
            ps = 0;
            Fail(PyExc_IOError, "can't open storage file");
          }
          break;
        }
      default:
        Fail(PyExc_ValueError, "storage() takes at most 4 arguments");
    }
    return ps;
  } catch (...) {
    return 0;
  }
}
Esempio n. 4
0
static PyObject* PyView_addproperty(PyView *o, PyObject* _args) {
  try {
    PWOSequence args(_args);
    PWOBase prop(args[0]);
    if (!PyProperty_Check((PyObject* )prop))
      Fail(PyExc_TypeError, "Not a Property object");
    PWONumber rslt(o->AddProperty(*(PyProperty *)(PyObject* )prop));
    return rslt.disOwn();
  }
  catch (...) { return 0; }
}
Esempio n. 5
0
static PyObject *PyView_itemsize(PyView *o, PyObject *_args) {
  try {
    PWOSequence args(_args);
    if (!PyProperty_Check((PyObject *)args[0]))
      Fail(PyExc_TypeError, "First arg must be a property");

    c4_BytesProp& prop = *(c4_BytesProp*)(c4_Property*)(PyProperty*)(PyObject*)args[0];
    int index = args.len() == 1 ? 0 : (int) PWONumber(args[1]);
    if (index < 0 || index >= o->GetSize())
      Fail(PyExc_IndexError, "Index out of range");

    return PWONumber(prop(o->GetAt(index)).GetSize()).disOwn();
  }
  catch (...) { return 0; }
}
Esempio n. 6
0
static PyObject *PyView_access(PyView *o, PyObject *_args) {
  try {
    PWOSequence args(_args);
    if (!PyProperty_Check((PyObject *)args[0]))
      Fail(PyExc_TypeError, "First arg must be a property");

    c4_BytesProp& prop = *(c4_BytesProp*)(c4_Property*)(PyProperty*)(PyObject*)args[0];

    int index = PyInt_AsLong(args[1]);
    if (index < 0 || index >= o->GetSize())
      Fail(PyExc_IndexError, "Index out of range");

    c4_RowRef row = o->GetAt(index);

    long offset = PyInt_AsLong(args[2]);
    int length = args.len() == 3 ? 0 : PyInt_AsLong(args[3]);
    if (length <= 0)
    {
      length = prop(row).GetSize() - offset;
      if (length < 0)
        length = 0;
    }

    PyObject* buffer = PyString_FromStringAndSize(0, length);
    int o = 0;

    while (o < length)
    {
      c4_Bytes buf = prop(row).Access(offset + o, length - o);
      int n = buf.Size();
      if (n == 0)
        break;
      memcpy(PyString_AS_STRING(buffer) + o, buf.Contents(), n);
      o += n;
    }

    if (o < length)
      _PyString_Resize(&buffer, o);

    return buffer;
  }
  catch (...) { return 0; }
}
Esempio n. 7
0
static PyObject* PyView_flatten(PyView *o, PyObject *_args, PyObject *_kwargs) {
  try {
    PWOSequence args(_args);
    PWOMapping kwargs;
    if (_kwargs)
        kwargs = PWOBase(_kwargs);
    if (!PyProperty_Check((PyObject*)args[0])) 
      Fail(PyExc_TypeError, "First arg must be a property object identifying the subview");
    const c4_Property& subview = *(PyProperty *)(PyObject* )args[0];
    bool outer = false;
    if (args.len() > 1) {
      PWONumber flag(args[1]);
      if ((int)flag > 0)
        outer = true;
    }
    if (kwargs.hasKey("outer")) {
      if (int(PWONumber(kwargs["outer"])))
        outer = true;
    }
    return new PyView (o->JoinProp((const c4_ViewProp&) subview, outer), 0, o->computeState(ROVIEWER));
  }
  catch (...) { return 0; }
}