149
152
Connection_init (Connection *self, PyObject *args, PyObject *kwds)
151
static char *kwlist[] = { NULL };
153
if (!PyArg_ParseTupleAndKeywords (args, kwds, "", kwlist))
156
debugprintf ("-> Connection_init()\n");
154
const char *host = cupsServer ();
155
int port = ippPort ();
156
int encryption = (http_encryption_t) cupsEncryption ();
157
static char *kwlist[] = { "host", "port", "encryption", NULL };
159
if (!PyArg_ParseTupleAndKeywords (args, kwds, "|sii", kwlist,
160
&host, &port, &encryption))
163
debugprintf ("-> Connection_init(host=%s)\n", host);
164
self->host = strdup (host);
166
debugprintf ("<- Connection_init() = -1\n");
158
170
Py_BEGIN_ALLOW_THREADS;
159
171
debugprintf ("httpConnectEncrypt(...)\n");
160
self->http = httpConnectEncrypt (cupsServer (),
172
self->http = httpConnectEncrypt (host, port, (http_encryption_t) encryption);
163
173
Py_END_ALLOW_THREADS;
165
175
if (!self->http) {
1356
1374
static PyObject *
1357
Connection_putFile (Connection *self, PyObject *args)
1375
Connection_putFile (Connection *self, PyObject *args, PyObject *kwds)
1359
const char *resource, *filename;
1377
static char *kwlist[] = { "resource", "filename", "fd", "file", NULL };
1378
const char *resource, *filename = NULL;
1380
PyObject *fileobj = NULL;
1360
1381
http_status_t status;
1362
if (!PyArg_ParseTuple (args, "ss", &resource, &filename))
1365
debugprintf ("-> Connection_putFile(%s, %s)\n", resource, filename);
1366
debugprintf ("cupsPutFile()\n");
1367
status = cupsPutFile (self->http, resource, filename);
1383
if (!PyArg_ParseTupleAndKeywords (args, kwds, "s|siO", kwlist,
1384
&resource, &filename, &fd, &fileobj))
1387
if ((fd > -1 && (filename || fileobj)) ||
1388
(filename && fileobj)) {
1389
PyErr_SetString (PyExc_RuntimeError,
1390
"Only one destination type may be specified");
1395
FILE *f = PyFile_AsFile (fileobj);
1400
debugprintf ("-> Connection_putFile(%s, %s)\n", resource, filename);
1401
debugprintf ("cupsPutFile()\n");
1402
status = cupsPutFile (self->http, resource, filename);
1404
debugprintf ("-> Connection_putFile(%s, %d)\n", resource, fd);
1405
debugprintf ("cupsPutFd()\n");
1406
status = cupsPutFd (self->http, resource, fd);
1368
1409
if (status != HTTP_OK && status != HTTP_CREATED) {
1369
1410
set_http_error (status);
1370
1411
debugprintf ("<- Connection_putFile() (error)\n");
2221
2262
PyObject *uriobj = NULL;
2264
PyObject *requested_attrs = NULL;
2265
char **attrs = NULL; /* initialised to calm compiler */
2266
size_t n_attrs = 0; /* initialised to calm compiler */
2223
2267
ipp_t *request, *answer;
2224
2268
ipp_attribute_t *attr;
2225
2269
char consuri[HTTP_MAX_URI];
2227
static char *kwlist[] = { "name", "uri", NULL };
2271
static char *kwlist[] = { "name", "uri", "requested_attributes", NULL };
2229
if (!PyArg_ParseTupleAndKeywords (args, kwds, "|OO", kwlist,
2273
if (!PyArg_ParseTupleAndKeywords (args, kwds, "|OOO", kwlist,
2274
&nameobj, &uriobj, &requested_attrs))
2233
2277
if (nameobj && uriobj) {
2295
if (requested_attrs) {
2298
if (!PyList_Check (requested_attrs)) {
2299
PyErr_SetString (PyExc_TypeError, "List required");
2303
n_attrs = PyList_Size (requested_attrs);
2304
attrs = malloc ((n_attrs + 1) * sizeof (char *));
2305
for (i = 0; i < n_attrs; i++) {
2306
PyObject *val = PyList_GetItem (requested_attrs, i); // borrowed ref
2307
if (!PyString_Check (val)) {
2308
PyErr_SetString (PyExc_TypeError, "String required");
2319
attrs[i] = strdup (PyString_AsString (val));
2321
attrs[n_attrs] = NULL;
2251
2324
debugprintf ("-> Connection_getPrinterAttributes(%s)\n",
2252
2325
nameobj ? name : uri);
2327
if (requested_attrs) {
2329
debugprintf ("Requested attributes:\n");
2330
for (i = 0; attrs[i] != NULL; i++)
2331
debugprintf (" %s\n", attrs[i]);
2254
2335
snprintf (consuri, sizeof (consuri), "ipp://localhost/printers/%s", name);
2259
2340
request = ippNewRequest (IPP_GET_PRINTER_ATTRIBUTES);
2260
2341
ippAddString (request, IPP_TAG_OPERATION, IPP_TAG_URI,
2261
2342
"printer-uri", NULL, uri);
2343
if (requested_attrs)
2344
ippAddStrings (request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
2345
"requested-attributes", n_attrs, NULL,
2346
(const char **) attrs);
2262
2347
debugprintf ("trying request with uri %s\n", uri);
2263
2348
answer = cupsDoRequest (self->http, request, "/");
2264
2349
if (answer && answer->request.status.status_code == IPP_NOT_POSSIBLE) {
3611
3703
"getJobAttributes(jobid) -> None\n\n"
3612
3704
"Fetch job attributes.\n"
3613
3705
"@type jobid: integer\n"
3614
"@param jobid_jobs: job ID\n"
3706
"@param jobid: job ID\n"
3615
3707
"@return: a dict representing job attributes.\n"
3616
3708
"@raise IPPError: IPP problem" },
3679
3771
"@raise HTTPError: HTTP problem" },
3682
(PyCFunction) Connection_putFile, METH_VARARGS,
3683
"putFile(resource, filename) -> None\n\n"
3774
(PyCFunction) Connection_putFile, METH_VARARGS | METH_KEYWORDS,
3775
"putFile(resource, filename=None, fd=-1, file=None) -> None\n\n"
3684
3776
"This is for uploading new configuration files for the CUPS \n"
3685
3777
"server. Note: L{adminSetServerSettings} is a way of \n"
3686
3778
"adjusting server settings without needing to parse the \n"
3689
3781
"@param resource: resource name\n"
3690
3782
"@type filename: string\n"
3691
3783
"@param filename: name of local file to upload\n"
3785
"@param fd: file descriptor of local file\n"
3786
"@type file: file\n"
3787
"@param file: Python file object for local file\n"
3692
3788
"@raise HTTPError: HTTP problem"},
3694
3790
{ "addPrinter",
3850
3946
{ "getPrinterAttributes",
3851
3947
(PyCFunction) Connection_getPrinterAttributes,
3852
3948
METH_VARARGS | METH_KEYWORDS,
3853
"getPrinterAttributes() -> dict\n"
3949
"getPrinterAttributes(name=None, uri=None, requested_attributes=None) -> dict\n"
3854
3950
"Fetch the attributes for a printer, specified either by name or by \n"
3855
3951
"uri but not both.\n\n"
3856
3952
"@type name: string\n"
3857
3953
"@param name: queue name\n"
3858
3954
"@type uri: string\n"
3859
3955
"@param uri: queue URI\n"
3956
"@type requested_attributes: string list\n"
3957
"@param requested_attributes: list of requested attribute names\n"
3860
3958
"@return: a dict, indexed by attribute, of printer attributes\n"
3861
3959
"for the specified printer.\n\n"
3862
3960
"Attributes:\n"
4055
4153
{ "renewSubscription",
4056
4154
(PyCFunction) Connection_renewSubscription, METH_VARARGS | METH_KEYWORDS,
4057
"renewSubscription(id) -> None\n\n"
4155
"renewSubscription(id, lease_duration=-1) -> None\n\n"
4058
4156
"Renew a subscription.\n\n"
4059
4157
"@type id: integer\n"
4060
4158
"@param id: subscription ID\n"
4124
4222
" A connection to the CUPS server. Before it is created the \n"
4125
4223
" connection server and username should be set using \n"
4126
4224
" L{cups.setServer} and L{cups.setUser}; otherwise the defaults will \n"
4127
" be used. When a Connection object is instantiated it results in a "
4128
" call to the libcups function httpConnectEncrypt()."
4225
" be used. When a Connection object is instantiated it results in a \n"
4226
" call to the libcups function httpConnectEncrypt().\n\n"
4227
" The constructor takes optional arguments host, port, and encryption, \n"
4228
" which default to the values of L{cups.getServer}(), \n"
4229
" L{cups.getPort}(), and L{cups.getEncryption}().\n"
4129
4230
"", /* tp_doc */
4130
4231
0, /* tp_traverse */
4131
4232
0, /* tp_clear */
4185
4286
self->ob_type->tp_free ((PyObject *) self);
4290
Dest_repr (Dest *self)
4292
return PyString_FromFormat ("<cups.Dest %s%s%s%s>",
4294
self->instance ? "/" : "",
4295
self->instance ? self->instance : "",
4296
self->is_default ? " (default)" : "");
4189
4300
// Dest // ATTRIBUTES