The Samba-Bugzilla – Attachment 580 Details for
Bug 1557
Add open and read calls to py_smb
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
add openand read to py_smb
samba-3.0.5rc1-py_smb-open-read.patch (text/plain), 3.29 KB, created by
Daniel Jarboe
on 2004-07-23 08:54:54 UTC
(
hide
)
Description:
add openand read to py_smb
Filename:
MIME Type:
Creator:
Daniel Jarboe
Created:
2004-07-23 08:54:54 UTC
Size:
3.29 KB
patch
obsolete
>--- source/python/py_smb.c.orig 2004-07-23 09:04:56.000000000 -0400 >+++ source/python/py_smb.c 2004-07-23 11:52:12.000000000 -0400 >@@ -178,6 +178,83 @@ > return PyInt_FromLong(result); > } > >+static PyObject *py_smb_open(PyObject *self, PyObject *args, PyObject *kw) >+{ >+ cli_state_object *cli = (cli_state_object *)self; >+ static char *kwlist[] = { "filename", "flags", >+ "share_mode", NULL }; >+ char *filename; >+ uint32 flags, share_mode = DENY_NONE; >+ int result; >+ >+ /* Parse parameters */ >+ >+ if (!PyArg_ParseTupleAndKeywords( >+ args, kw, "si|i", kwlist, &filename, &flags, &share_mode)) >+ return NULL; >+ >+ result = cli_open(cli->cli, filename, flags, share_mode); >+ >+ if (cli_is_error(cli->cli)) { >+ PyErr_SetString(PyExc_RuntimeError, "open failed"); >+ return NULL; >+ } >+ >+ /* Return FID */ >+ >+ return PyInt_FromLong(result); >+} >+ >+static PyObject *py_smb_read(PyObject *self, PyObject *args, PyObject *kw) >+{ >+ cli_state_object *cli = (cli_state_object *)self; >+ static char *kwlist[] = { "fnum", "offset", "size", NULL }; >+ int fnum, offset=0, size=0; >+ ssize_t result; >+ size_t fsize; >+ char *data; >+ PyObject *ret; >+ >+ /* Parse parameters */ >+ >+ if (!PyArg_ParseTupleAndKeywords( >+ args, kw, "i|ii", kwlist, &fnum, &offset, &size)) >+ return NULL; >+ >+ if (!cli_qfileinfo(cli->cli, fnum, NULL, &fsize, NULL, NULL, >+ NULL, NULL, NULL) && >+ !cli_getattrE(cli->cli, fnum, NULL, &fsize, NULL, NULL, NULL)) { >+ PyErr_SetString(PyExc_RuntimeError, "getattrib failed"); >+ return NULL; >+ } >+ >+ if (offset < 0) >+ offset = 0; >+ >+ if (size < 1 || size > fsize - offset) >+ size = fsize - offset; >+ >+ if (!(data = (char *) malloc((size_t) size))) { >+ PyErr_SetString(PyExc_RuntimeError, "malloc failed"); >+ return NULL; >+ } >+ >+ result = cli_read(cli->cli, fnum, data, (off_t) offset, (size_t) size); >+ >+ if (result==-1 || cli_is_error(cli->cli)) { >+ SAFE_FREE(data); >+ PyErr_SetString(PyExc_RuntimeError, "read failed"); >+ return NULL; >+ } >+ >+ /* Return a python string */ >+ >+ ret = Py_BuildValue("s#", data, result); >+ SAFE_FREE(data); >+ >+ return ret; >+} >+ > static PyObject *py_smb_close(PyObject *self, PyObject *args, > PyObject *kw) > { >@@ -322,6 +399,33 @@ > { "nt_create_andx", (PyCFunction)py_smb_nt_create_andx, > METH_VARARGS | METH_KEYWORDS, "NT Create&X" }, > >+ { "open", (PyCFunction)py_smb_open, >+ METH_VARARGS | METH_KEYWORDS, >+ "Open a file\n" >+"\n" >+"This function returns a fnum handle to an open file. The file is\n" >+"opened with flags and optional share mode. If unspecified, the\n" >+"default share mode is DENY_NONE\n" >+"\n" >+"Example:\n" >+"\n" >+">>> fnum=conn.open(filename, os.O_RDONLY)" }, >+ >+ { "read", (PyCFunction)py_smb_read, >+ METH_VARARGS | METH_KEYWORDS, >+ "Read from an open file\n" >+"\n" >+"This function returns a string read from an open file starting at\n" >+"offset for size bytes (until EOF is reached). If unspecified, the\n" >+"default offset is 0, and default size is the remainder of the file.\n" >+"\n" >+"Example:\n" >+"\n" >+">>> conn.read(fnum) # read entire file\n" >+">>> conn.read(fnum,5) # read entire file from offset 5\n" >+">>> conn.read(fnum,size=64) # read 64 bytes from start of file\n" >+">>> conn.read(fnum,4096,1024) # read 1024 bytes from offset 4096\n" }, >+ > { "close", (PyCFunction)py_smb_close, > METH_VARARGS | METH_KEYWORDS, "Close" }, >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 1557
:
579
| 580