summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2004-05-31 03:09:25 (GMT)
committerRaymond Hettinger <python@rcn.com>2004-05-31 03:09:25 (GMT)
commit027bb633b6899a0847d81cb35cbccdff5a468766 (patch)
tree4d6694b894394f6dd73ed6eb7c8c47c1909f056d /Lib
parentcb87bc8e7ee3a2ffd83dd1b12fcfa1c01aa740aa (diff)
downloadcpython-027bb633b6899a0847d81cb35cbccdff5a468766.zip
cpython-027bb633b6899a0847d81cb35cbccdff5a468766.tar.gz
cpython-027bb633b6899a0847d81cb35cbccdff5a468766.tar.bz2
Add weakref support to sockets and re pattern objects.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/socket.py3
-rw-r--r--Lib/test/test_re.py8
-rw-r--r--Lib/test/test_socket.py14
3 files changed, 24 insertions, 1 deletions
diff --git a/Lib/socket.py b/Lib/socket.py
index 39d5119..e97ce59 100644
--- a/Lib/socket.py
+++ b/Lib/socket.py
@@ -147,7 +147,8 @@ class _socketobject(object):
__doc__ = _realsocket.__doc__
- __slots__ = ["_sock", "send", "recv", "sendto", "recvfrom"]
+ __slots__ = ["_sock", "send", "recv", "sendto", "recvfrom",
+ "__weakref__"]
def __init__(self, family=AF_INET, type=SOCK_STREAM, proto=0, _sock=None):
if _sock is None:
diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py
index 2363ce5..c7afdc5 100644
--- a/Lib/test/test_re.py
+++ b/Lib/test/test_re.py
@@ -5,6 +5,7 @@ from test.test_support import verbose, run_unittest
import re
from sre import Scanner
import sys, os, traceback
+from weakref import proxy
# Misc tests from Tim Peters' re.doc
@@ -15,6 +16,13 @@ import sys, os, traceback
import unittest
class ReTests(unittest.TestCase):
+
+ def test_weakref(self):
+ s = 'QabbbcR'
+ x = re.compile('ab+c')
+ y = proxy(x)
+ self.assertEqual(x.findall('QabbbcR'), y.findall('QabbbcR'))
+
def test_search_star_plus(self):
self.assertEqual(re.search('x*', 'axx').span(0), (0, 0))
self.assertEqual(re.search('x*', 'axx').span(), (0, 0))
diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py
index f7bf041..6e2f80c 100644
--- a/Lib/test/test_socket.py
+++ b/Lib/test/test_socket.py
@@ -9,6 +9,7 @@ import time
import thread, threading
import Queue
import sys
+from weakref import proxy
PORT = 50007
HOST = 'localhost'
@@ -191,6 +192,19 @@ class SocketConnectedTest(ThreadedTCPSocketTest):
class GeneralModuleTests(unittest.TestCase):
+ def test_weakref(self):
+ s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ p = proxy(s)
+ self.assertEqual(p.fileno(), s.fileno())
+ s.close()
+ s = None
+ try:
+ p.fileno()
+ except ReferenceError:
+ pass
+ else:
+ self.fail('Socket proxy still exists')
+
def testSocketError(self):
# Testing socket module exceptions
def raise_error(*args, **kwargs):