* Add the :attr:`ipaddress.IPv4Address.ipv6_mapped` property, which returns the IPv4-mapped IPv6 address.
(Contributed by Charles Machalow in :gh:`109466`.)
+mmap
+----
+
+* The :class:`mmap.mmap` class now has an :meth:`~mmap.mmap.seekable` method
+ that can be used where it requires a file-like object with seekable and
+ the :meth:`~mmap.mmap.seek` method return the new absolute position.
+ (Contributed by Donghee Na and Sylvie Liberman in :gh:`111835`.)
+
opcode
------
self.assertEqual(end, PAGESIZE + 6)
# test seeking around (try to overflow the seek implementation)
- m.seek(0,0)
+ self.assertTrue(m.seekable())
+ self.assertEqual(m.seek(0, 0), 0)
self.assertEqual(m.tell(), 0)
- m.seek(42,1)
+ self.assertEqual(m.seek(42, 1), 42)
self.assertEqual(m.tell(), 42)
- m.seek(0,2)
+ self.assertEqual(m.seek(0, 2), len(m))
self.assertEqual(m.tell(), len(m))
# Try to seek to negative position...
# Ensuring that readonly mmap can't be write() to
try:
- m.seek(0,0)
+ m.seek(0, 0)
m.write(b'abc')
except TypeError:
pass
# Ensuring that readonly mmap can't be write_byte() to
try:
- m.seek(0,0)
+ m.seek(0, 0)
m.write_byte(b'd')
except TypeError:
pass
}
static PyObject *
-mmap_close_method(mmap_object *self, PyObject *unused)
+mmap_close_method(mmap_object *self, PyObject *Py_UNUSED(ignored))
{
if (self->exports > 0) {
PyErr_SetString(PyExc_BufferError, "cannot close "\
static PyObject *
mmap_read_byte_method(mmap_object *self,
- PyObject *unused)
+ PyObject *Py_UNUSED(ignored))
{
CHECK_VALID(NULL);
if (self->pos >= self->size) {
static PyObject *
mmap_read_line_method(mmap_object *self,
- PyObject *unused)
+ PyObject *Py_UNUSED(ignored))
{
Py_ssize_t remaining;
char *start, *eol;
static PyObject *
mmap_size_method(mmap_object *self,
- PyObject *unused)
+ PyObject *Py_UNUSED(ignored))
{
CHECK_VALID(NULL);
}
static PyObject *
-mmap_tell_method(mmap_object *self, PyObject *unused)
+mmap_tell_method(mmap_object *self, PyObject *Py_UNUSED(ignored))
{
CHECK_VALID(NULL);
return PyLong_FromSize_t(self->pos);
if (where > self->size || where < 0)
goto onoutofrange;
self->pos = where;
- Py_RETURN_NONE;
+ return PyLong_FromSsize_t(self->pos);
}
onoutofrange:
return NULL;
}
+static PyObject *
+mmap_seekable_method(mmap_object *self, PyObject *Py_UNUSED(ignored))
+{
+ Py_RETURN_TRUE;
+}
+
static PyObject *
mmap_move_method(mmap_object *self, PyObject *args)
{
#ifdef MS_WINDOWS
static PyObject *
-mmap__sizeof__method(mmap_object *self, void *unused)
+mmap__sizeof__method(mmap_object *self, void *Py_UNUSED(ignored))
{
size_t res = _PyObject_SIZE(Py_TYPE(self));
if (self->tagname) {
{"readline", (PyCFunction) mmap_read_line_method, METH_NOARGS},
{"resize", (PyCFunction) mmap_resize_method, METH_VARARGS},
{"seek", (PyCFunction) mmap_seek_method, METH_VARARGS},
+ {"seekable", (PyCFunction) mmap_seekable_method, METH_NOARGS},
{"size", (PyCFunction) mmap_size_method, METH_NOARGS},
{"tell", (PyCFunction) mmap_tell_method, METH_NOARGS},
{"write", (PyCFunction) mmap_write_method, METH_VARARGS},