Skip to content

Commit 8cc7d88

Browse files
committed
Merged revisions 73073-73074,73089 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r73073 | benjamin.peterson | 2009-05-31 09:43:00 -0500 (Sun, 31 May 2009) | 1 line remove function import ........ r73074 | benjamin.peterson | 2009-05-31 10:00:27 -0500 (Sun, 31 May 2009) | 1 line __enter__ and __exit__ must be on the class ........ r73089 | andrew.kuchling | 2009-05-31 19:14:19 -0500 (Sun, 31 May 2009) | 1 line The class for regexes isn't called RegexObject any more; correct the text ........
1 parent be5f371 commit 8cc7d88

File tree

3 files changed

+27
-19
lines changed

3 files changed

+27
-19
lines changed

Doc/howto/regex.rst

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ matches with them.
257257
Compiling Regular Expressions
258258
-----------------------------
259259

260-
Regular expressions are compiled into :class:`RegexObject` instances, which have
260+
Regular expressions are compiled into pattern objects, which have
261261
methods for various operations such as searching for pattern matches or
262262
performing string substitutions. ::
263263

@@ -336,7 +336,7 @@ Performing Matches
336336
------------------
337337

338338
Once you have an object representing a compiled regular expression, what do you
339-
do with it? :class:`RegexObject` instances have several methods and attributes.
339+
do with it? Pattern objects have several methods and attributes.
340340
Only the most significant ones will be covered here; consult the :mod:`re` docs
341341
for a complete listing.
342342

@@ -427,8 +427,8 @@ Trying these methods will soon clarify their meaning::
427427
and :meth:`end` return the starting and ending index of the match. :meth:`span`
428428
returns both start and end indexes in a single tuple. Since the :meth:`match`
429429
method only checks if the RE matches at the start of a string, :meth:`start`
430-
will always be zero. However, the :meth:`search` method of :class:`RegexObject`
431-
instances scans through the string, so the match may not start at zero in that
430+
will always be zero. However, the :meth:`search` method of patterns
431+
scans through the string, so the match may not start at zero in that
432432
case. ::
433433

434434
>>> print(p.match('::: message'))
@@ -450,7 +450,7 @@ in a variable, and then check if it was ``None``. This usually looks like::
450450
else:
451451
print('No match')
452452

453-
Two :class:`RegexObject` methods return all of the matches for a pattern.
453+
Two pattern methods return all of the matches for a pattern.
454454
:meth:`findall` returns a list of matching strings::
455455

456456
>>> p = re.compile('\d+')
@@ -475,10 +475,10 @@ instances as an :term:`iterator`. [#]_ ::
475475
Module-Level Functions
476476
----------------------
477477

478-
You don't have to create a :class:`RegexObject` and call its methods; the
478+
You don't have to create a pattern object and call its methods; the
479479
:mod:`re` module also provides top-level functions called :func:`match`,
480480
:func:`search`, :func:`findall`, :func:`sub`, and so forth. These functions
481-
take the same arguments as the corresponding :class:`RegexObject` method, with
481+
take the same arguments as the corresponding pattern method, with
482482
the RE string added as the first argument, and still return either ``None`` or a
483483
:class:`MatchObject` instance. ::
484484

@@ -487,12 +487,12 @@ the RE string added as the first argument, and still return either ``None`` or a
487487
>>> re.match(r'From\s+', 'From amk Thu May 14 19:12:10 1998')
488488
<re.MatchObject instance at 80c5978>
489489

490-
Under the hood, these functions simply produce a :class:`RegexObject` for you
490+
Under the hood, these functions simply create a pattern object for you
491491
and call the appropriate method on it. They also store the compiled object in a
492492
cache, so future calls using the same RE are faster.
493493

494494
Should you use these module-level functions, or should you get the
495-
:class:`RegexObject` and call its methods yourself? That choice depends on how
495+
pattern and call its methods yourself? That choice depends on how
496496
frequently the RE will be used, and on your personal coding style. If the RE is
497497
being used at only one point in the code, then the module functions are probably
498498
more convenient. If a program contains a lot of regular expressions, or re-uses
@@ -1031,7 +1031,7 @@ Modifying Strings
10311031

10321032
Up to this point, we've simply performed searches against a static string.
10331033
Regular expressions are also commonly used to modify strings in various ways,
1034-
using the following :class:`RegexObject` methods:
1034+
using the following pattern methods:
10351035

10361036
+------------------+-----------------------------------------------+
10371037
| Method/Attribute | Purpose |
@@ -1051,7 +1051,7 @@ using the following :class:`RegexObject` methods:
10511051
Splitting Strings
10521052
-----------------
10531053

1054-
The :meth:`split` method of a :class:`RegexObject` splits a string apart
1054+
The :meth:`split` method of a pattern splits a string apart
10551055
wherever the RE matches, returning a list of the pieces. It's similar to the
10561056
:meth:`split` method of strings but provides much more generality in the
10571057
delimiters that you can split by; :meth:`split` only supports splitting by
@@ -1196,10 +1196,10 @@ hexadecimal::
11961196
'Call 0xffd2 for printing, 0xc000 for user code.'
11971197

11981198
When using the module-level :func:`re.sub` function, the pattern is passed as
1199-
the first argument. The pattern may be a string or a :class:`RegexObject`; if
1199+
the first argument. The pattern may be provided as an object or as a string; if
12001200
you need to specify regular expression flags, you must either use a
1201-
:class:`RegexObject` as the first parameter, or use embedded modifiers in the
1202-
pattern, e.g. ``sub("(?i)b+", "x", "bbbb BBBB")`` returns ``'x x'``.
1201+
pattern object as the first parameter, or use embedded modifiers in the
1202+
pattern string, e.g. ``sub("(?i)b+", "x", "bbbb BBBB")`` returns ``'x x'``.
12031203

12041204

12051205
Common Problems

Lib/multiprocessing/synchronize.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,12 @@ def _after_fork(obj):
5858
def _make_methods(self):
5959
self.acquire = self._semlock.acquire
6060
self.release = self._semlock.release
61-
self.__enter__ = self._semlock.__enter__
62-
self.__exit__ = self._semlock.__exit__
61+
62+
def __enter__(self):
63+
return self._semlock.__enter__()
64+
65+
def __exit__(self, *args):
66+
return self._semlock.__exit__(*args)
6367

6468
def __getstate__(self):
6569
assert_spawning(self)
@@ -181,11 +185,15 @@ def __setstate__(self, state):
181185
self._woken_count, self._wait_semaphore) = state
182186
self._make_methods()
183187

188+
def __enter__(self):
189+
return self._lock.__enter__()
190+
191+
def __exit__(self, *args):
192+
return self._lock.__exit__(*args)
193+
184194
def _make_methods(self):
185195
self.acquire = self._lock.acquire
186196
self.release = self._lock.release
187-
self.__enter__ = self._lock.__enter__
188-
self.__exit__ = self._lock.__exit__
189197

190198
def __repr__(self):
191199
try:

Lib/test/support.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import contextlib
77
import errno
88
import functools
9+
import gc
910
import socket
1011
import sys
1112
import os
@@ -630,7 +631,6 @@ def gc_collect():
630631
longer than expected. This function tries its best to force all garbage
631632
objects to disappear.
632633
"""
633-
import gc
634634
gc.collect()
635635
gc.collect()
636636
gc.collect()

0 commit comments

Comments
 (0)