Skip to content

Commit

Permalink
[project @ 2006-03-28 14:43:14 by twaugh]
Browse files Browse the repository at this point in the history
2006-03-28  Tim Waugh  <[email protected]>

        * cupsppd.c, cupsppd.h, cupsmodule.c: Added Attribute object,
          and PPD.attributes attribute.

Original author: twaugh
Date: 2006-03-28 14:43:14+00:00

git-svn-id: svn+ssh://svn.fedorahosted.org/svn/pycups/pycups@109 e7545f15-59ab-4934-8816-61942c173d0f
  • Loading branch information
mmcgrath committed Jul 5, 2007
1 parent dd29dae commit 5e27692
Show file tree
Hide file tree
Showing 4 changed files with 185 additions and 0 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2006-03-28 Tim Waugh <[email protected]>

* cupsppd.c, cupsppd.h, cupsmodule.c: Added Attribute object,
and PPD.attributes attribute.

2006-03-24 Tim Waugh <[email protected]>

* Makefile: Version 1.9.5.
Expand Down
8 changes: 8 additions & 0 deletions cupsmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,14 @@ initcups (void)
PyModule_AddObject (m, "Constraint",
(PyObject *)&cups_ConstraintType);

// Attribute type
cups_AttributeType.tp_new = PyType_GenericNew;
if (PyType_Ready (&cups_AttributeType) < 0)
return;

PyModule_AddObject (m, "Attribute",
(PyObject *)&cups_AttributeType);

// Constants

#define INT_CONSTANT(name) \
Expand Down
171 changes: 171 additions & 0 deletions cupsppd.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ typedef struct
PPD *ppd;
} Group;

typedef struct
{
PyObject_HEAD
ppd_attr_t *attribute;
PPD *ppd;
} Attribute;

/////////////////////////
// Encoding conversion //
/////////////////////////
Expand Down Expand Up @@ -436,6 +443,28 @@ PPD_getConstraints (PPD *self, void *closure)
return ret;
}

static PyObject *
PPD_getAttributes (PPD *self, void *closure)
{
PyObject *ret = PyList_New (0);
int i;
for (i = 0; i < self->ppd->num_attrs; i++) {
PyObject *args = Py_BuildValue ("()");
PyObject *kwlist = Py_BuildValue ("{}");
Attribute *as = (Attribute *) PyType_GenericNew (&cups_AttributeType,
args, kwlist);
ppd_attr_t *a = self->ppd->attrs[i];
Py_DECREF (args);
Py_DECREF (kwlist);
as->attribute = a;
as->ppd = self;
Py_INCREF (self);
PyList_Append (ret, (PyObject *) as);
}

return ret;
}

static PyObject *
PPD_getOptionGroups (PPD *self, void *closure)
{
Expand Down Expand Up @@ -467,6 +496,10 @@ PyGetSetDef PPD_getseters[] =
(getter) PPD_getConstraints, (setter) NULL,
"List of constraints", NULL },

{ "attributes",
(getter) PPD_getAttributes, (setter) NULL,
"List of attributes", NULL },

{ "optionGroups",
(getter) PPD_getOptionGroups, (setter) NULL,
"List of PPD option groups" },
Expand Down Expand Up @@ -1049,3 +1082,141 @@ PyTypeObject cups_ConstraintType =
0, /* tp_alloc */
Constraint_new, /* tp_new */
};

///////////////
// Attribute //
///////////////

static PyObject *
Attribute_new (PyTypeObject *type, PyObject *args, PyObject *kwds)
{
Attribute *self;
self = (Attribute *) type->tp_alloc (type, 0);
return (PyObject *) self;
}

static int
Attribute_init (Attribute *self, PyObject *args, PyObject *kwds)
{
self->attribute = NULL;
return 0;
}

static void
Attribute_dealloc (Attribute *self)
{
Py_XDECREF (self->ppd);
self->ob_type->tp_free ((PyObject *) self);
}

///////////////
// Attribute // ATTRIBUTES
///////////////

static PyObject *
Attribute_getName (Attribute *self, void *closure)
{
if (!self->attribute) {
Py_INCREF (Py_None);
return Py_None;
}

return make_PyUnicode_from_ppd_string (self->ppd, self->attribute->name);
}

static PyObject *
Attribute_getSpec (Attribute *self, void *closure)
{
if (!self->attribute) {
Py_INCREF (Py_None);
return Py_None;
}

return make_PyUnicode_from_ppd_string (self->ppd, self->attribute->spec);
}

static PyObject *
Attribute_getText (Attribute *self, void *closure)
{
if (!self->attribute) {
Py_INCREF (Py_None);
return Py_None;
}

return make_PyUnicode_from_ppd_string (self->ppd, self->attribute->text);
}

static PyObject *
Attribute_getValue (Attribute *self, void *closure)
{
if (!self->attribute) {
Py_INCREF (Py_None);
return Py_None;
}

return make_PyUnicode_from_ppd_string (self->ppd, self->attribute->value);
}

PyGetSetDef Attribute_getseters[] =
{
{ "name",
(getter) Attribute_getName, (setter) NULL,
"name", NULL },

{ "spec",
(getter) Attribute_getSpec, (setter) NULL,
"spec", NULL },

{ "text",
(getter) Attribute_getText, (setter) NULL,
"text", NULL },

{ "value",
(getter) Attribute_getValue, (setter) NULL,
"value", NULL },

{ NULL }
};

PyTypeObject cups_AttributeType =
{
PyObject_HEAD_INIT(NULL)
0, /*ob_size*/
"cups.Attribute", /*tp_name*/
sizeof(Attribute), /*tp_basicsize*/
0, /*tp_itemsize*/
(destructor)Attribute_dealloc, /*tp_dealloc*/
0, /*tp_print*/
0, /*tp_getattr*/
0, /*tp_setattr*/
0, /*tp_compare*/
0, /*tp_repr*/
0, /*tp_as_number*/
0, /*tp_as_sequence*/
0, /*tp_as_mapping*/
0, /*tp_hash */
0, /*tp_call*/
0, /*tp_str*/
0, /*tp_getattro*/
0, /*tp_setattro*/
0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT, /*tp_flags*/
"PPD attribute", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
0, /* tp_methods */
0, /* tp_members */
Attribute_getseters, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
(initproc)Attribute_init, /* tp_init */
0, /* tp_alloc */
Attribute_new, /* tp_new */
};
1 change: 1 addition & 0 deletions cupsppd.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ extern PyTypeObject cups_PPDType;
extern PyTypeObject cups_OptionType;
extern PyTypeObject cups_GroupType;
extern PyTypeObject cups_ConstraintType;
extern PyTypeObject cups_AttributeType;

typedef struct
{
Expand Down

0 comments on commit 5e27692

Please sign in to comment.