Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
5c60bfcf
Kaydet (Commit)
5c60bfcf
authored
Ock 19, 2008
tarafından
Andrew M. Kuchling
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Patch #976880: add mmap .rfind() method, and 'end' paramter to .find().
Contributed by John Lenton.
üst
4be0bc64
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
88 additions
and
9 deletions
+88
-9
mmap.rst
Doc/library/mmap.rst
+13
-4
test_mmap.py
Lib/test/test_mmap.py
+36
-0
ACKS
Misc/ACKS
+1
-0
NEWS
Misc/NEWS
+4
-0
mmapmodule.c
Modules/mmapmodule.c
+34
-5
No files found.
Doc/library/mmap.rst
Dosyayı görüntüle @
5c60bfcf
...
@@ -139,11 +139,12 @@ Memory-mapped file objects support the following methods:
...
@@ -139,11 +139,12 @@ Memory-mapped file objects support the following methods:
an exception being raised.
an exception being raised.
.. method:: mmap.find(string[, start])
.. method:: mmap.find(string[, start
[, end]
])
Returns the lowest index in the object where the substring *string* is found.
Returns the lowest index in the object where the substring *string* is found,
Returns ``-1`` on failure. *start* is the index at which the search begins, and
such that *string* is contained in the range [*start*, *end*]. Optional
defaults to zero.
arguments *start* and *end* are interpreted as in slice notation.
Returns ``-1`` on failure.
.. method:: mmap.flush([offset, size])
.. method:: mmap.flush([offset, size])
...
@@ -188,6 +189,14 @@ Memory-mapped file objects support the following methods:
...
@@ -188,6 +189,14 @@ Memory-mapped file objects support the following methods:
:exc:`TypeError` exception.
:exc:`TypeError` exception.
.. method:: mmap.rfind(string[, start[, end]])
Returns the highest index in the object where the substring *string* is
found, such that *string* is contained in the range [*start*,
*end*]. Optional arguments *start* and *end* are interpreted as in slice
notation. Returns ``-1`` on failure.
.. method:: mmap.seek(pos[, whence])
.. method:: mmap.seek(pos[, whence])
Set the file's current position. *whence* argument is optional and defaults to
Set the file's current position. *whence* argument is optional and defaults to
...
...
Lib/test/test_mmap.py
Dosyayı görüntüle @
5c60bfcf
...
@@ -255,6 +255,42 @@ class MmapTests(unittest.TestCase):
...
@@ -255,6 +255,42 @@ class MmapTests(unittest.TestCase):
self
.
assertEqual
(
m
.
find
(
slice
+
'x'
),
-
1
)
self
.
assertEqual
(
m
.
find
(
slice
+
'x'
),
-
1
)
m
.
close
()
m
.
close
()
def
test_find_end
(
self
):
# test the new 'end' parameter works as expected
f
=
open
(
TESTFN
,
'w+'
)
data
=
'one two ones'
n
=
len
(
data
)
f
.
write
(
data
)
f
.
flush
()
m
=
mmap
.
mmap
(
f
.
fileno
(),
n
)
f
.
close
()
self
.
assertEqual
(
m
.
find
(
'one'
),
0
)
self
.
assertEqual
(
m
.
find
(
'ones'
),
8
)
self
.
assertEqual
(
m
.
find
(
'one'
,
0
,
-
1
),
0
)
self
.
assertEqual
(
m
.
find
(
'one'
,
1
),
8
)
self
.
assertEqual
(
m
.
find
(
'one'
,
1
,
-
1
),
8
)
self
.
assertEqual
(
m
.
find
(
'one'
,
1
,
-
2
),
-
1
)
def
test_rfind
(
self
):
# test the new 'end' parameter works as expected
f
=
open
(
TESTFN
,
'w+'
)
data
=
'one two ones'
n
=
len
(
data
)
f
.
write
(
data
)
f
.
flush
()
m
=
mmap
.
mmap
(
f
.
fileno
(),
n
)
f
.
close
()
self
.
assertEqual
(
m
.
rfind
(
'one'
),
8
)
self
.
assertEqual
(
m
.
rfind
(
'one '
),
0
)
self
.
assertEqual
(
m
.
rfind
(
'one'
,
0
,
-
1
),
8
)
self
.
assertEqual
(
m
.
rfind
(
'one'
,
0
,
-
2
),
0
)
self
.
assertEqual
(
m
.
rfind
(
'one'
,
1
,
-
1
),
8
)
self
.
assertEqual
(
m
.
rfind
(
'one'
,
1
,
-
2
),
-
1
)
def
test_double_close
(
self
):
def
test_double_close
(
self
):
# make sure a double close doesn't crash on Solaris (Bug# 665913)
# make sure a double close doesn't crash on Solaris (Bug# 665913)
f
=
open
(
TESTFN
,
'w+'
)
f
=
open
(
TESTFN
,
'w+'
)
...
...
Misc/ACKS
Dosyayı görüntüle @
5c60bfcf
...
@@ -395,6 +395,7 @@ Kip Lehman
...
@@ -395,6 +395,7 @@ Kip Lehman
Joerg Lehmann
Joerg Lehmann
Luke Kenneth Casson Leighton
Luke Kenneth Casson Leighton
Marc-Andre Lemburg
Marc-Andre Lemburg
John Lenton
Mark Levinson
Mark Levinson
William Lewis
William Lewis
Robert van Liere
Robert van Liere
...
...
Misc/NEWS
Dosyayı görüntüle @
5c60bfcf
...
@@ -1011,6 +1011,10 @@ Library
...
@@ -1011,6 +1011,10 @@ Library
Extension
Modules
Extension
Modules
-----------------
-----------------
-
Patch
976880
:
``
mmap
``
objects
now
have
an
``
rfind
``
method
that
works
as
expected
.
``
mmap
.
find
``
also
takes
an
optional
``
end
``
parameter
.
-
_winreg
's HKEY object has gained __enter__ and __exit__ methods to support
-
_winreg
's HKEY object has gained __enter__ and __exit__ methods to support
the context manager protocol. The _winreg module also gained a new function
the context manager protocol. The _winreg module also gained a new function
``ExpandEnvironmentStrings`` to expand REG_EXPAND_SZ keys.
``ExpandEnvironmentStrings`` to expand REG_EXPAND_SZ keys.
...
...
Modules/mmapmodule.c
Dosyayı görüntüle @
5c60bfcf
...
@@ -248,19 +248,22 @@ mmap_read_method(mmap_object *self,
...
@@ -248,19 +248,22 @@ mmap_read_method(mmap_object *self,
}
}
static
PyObject
*
static
PyObject
*
mmap_find_method
(
mmap_object
*
self
,
mmap_gfind
(
mmap_object
*
self
,
PyObject
*
args
)
PyObject
*
args
,
int
reverse
)
{
{
Py_ssize_t
start
=
self
->
pos
;
Py_ssize_t
start
=
self
->
pos
;
Py_ssize_t
end
=
self
->
size
;
char
*
needle
;
char
*
needle
;
Py_ssize_t
len
;
Py_ssize_t
len
;
CHECK_VALID
(
NULL
);
CHECK_VALID
(
NULL
);
if
(
!
PyArg_ParseTuple
(
args
,
"s#|n:find"
,
&
needle
,
&
len
,
&
start
))
{
if
(
!
PyArg_ParseTuple
(
args
,
reverse
?
"s#|nn:rfind"
:
"s#|nn:find"
,
&
needle
,
&
len
,
&
start
,
&
end
))
{
return
NULL
;
return
NULL
;
}
else
{
}
else
{
char
*
p
;
char
*
p
;
char
*
e
=
self
->
data
+
self
->
size
;
char
sign
=
reverse
?
-
1
:
1
;
if
(
start
<
0
)
if
(
start
<
0
)
start
+=
self
->
size
;
start
+=
self
->
size
;
...
@@ -269,7 +272,18 @@ mmap_find_method(mmap_object *self,
...
@@ -269,7 +272,18 @@ mmap_find_method(mmap_object *self,
else
if
((
size_t
)
start
>
self
->
size
)
else
if
((
size_t
)
start
>
self
->
size
)
start
=
self
->
size
;
start
=
self
->
size
;
for
(
p
=
self
->
data
+
start
;
p
+
len
<=
e
;
++
p
)
{
if
(
end
<
0
)
end
+=
self
->
size
;
if
(
end
<
0
)
end
=
0
;
else
if
((
size_t
)
end
>
self
->
size
)
end
=
self
->
size
;
start
+=
(
Py_ssize_t
)
self
->
data
;
end
+=
(
Py_ssize_t
)
self
->
data
;
for
(
p
=
(
char
*
)(
reverse
?
end
-
len
:
start
);
p
>=
(
char
*
)
start
&&
p
+
len
<=
(
char
*
)
end
;
p
+=
sign
)
{
Py_ssize_t
i
;
Py_ssize_t
i
;
for
(
i
=
0
;
i
<
len
&&
needle
[
i
]
==
p
[
i
];
++
i
)
for
(
i
=
0
;
i
<
len
&&
needle
[
i
]
==
p
[
i
];
++
i
)
/* nothing */
;
/* nothing */
;
...
@@ -281,6 +295,20 @@ mmap_find_method(mmap_object *self,
...
@@ -281,6 +295,20 @@ mmap_find_method(mmap_object *self,
}
}
}
}
static
PyObject
*
mmap_find_method
(
mmap_object
*
self
,
PyObject
*
args
)
{
return
mmap_gfind
(
self
,
args
,
0
);
}
static
PyObject
*
mmap_rfind_method
(
mmap_object
*
self
,
PyObject
*
args
)
{
return
mmap_gfind
(
self
,
args
,
1
);
}
static
int
static
int
is_writeable
(
mmap_object
*
self
)
is_writeable
(
mmap_object
*
self
)
{
{
...
@@ -593,6 +621,7 @@ mmap_move_method(mmap_object *self, PyObject *args)
...
@@ -593,6 +621,7 @@ mmap_move_method(mmap_object *self, PyObject *args)
static
struct
PyMethodDef
mmap_object_methods
[]
=
{
static
struct
PyMethodDef
mmap_object_methods
[]
=
{
{
"close"
,
(
PyCFunction
)
mmap_close_method
,
METH_NOARGS
},
{
"close"
,
(
PyCFunction
)
mmap_close_method
,
METH_NOARGS
},
{
"find"
,
(
PyCFunction
)
mmap_find_method
,
METH_VARARGS
},
{
"find"
,
(
PyCFunction
)
mmap_find_method
,
METH_VARARGS
},
{
"rfind"
,
(
PyCFunction
)
mmap_rfind_method
,
METH_VARARGS
},
{
"flush"
,
(
PyCFunction
)
mmap_flush_method
,
METH_VARARGS
},
{
"flush"
,
(
PyCFunction
)
mmap_flush_method
,
METH_VARARGS
},
{
"move"
,
(
PyCFunction
)
mmap_move_method
,
METH_VARARGS
},
{
"move"
,
(
PyCFunction
)
mmap_move_method
,
METH_VARARGS
},
{
"read"
,
(
PyCFunction
)
mmap_read_method
,
METH_VARARGS
},
{
"read"
,
(
PyCFunction
)
mmap_read_method
,
METH_VARARGS
},
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment