summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2008-01-19 20:08:23 (GMT)
committerGeorg Brandl <georg@python.org>2008-01-19 20:08:23 (GMT)
commitfceab5a385f121029bfa7e855f7fd1aca1eb8c3f (patch)
tree91d552ec2d068287efc8b8f3769cd6865c3c0620 /Lib
parent2336bddd5dba559db950e8b5fa73257fc62d1fc3 (diff)
downloadcpython-fceab5a385f121029bfa7e855f7fd1aca1eb8c3f.zip
cpython-fceab5a385f121029bfa7e855f7fd1aca1eb8c3f.tar.gz
cpython-fceab5a385f121029bfa7e855f7fd1aca1eb8c3f.tar.bz2
Merged revisions 60080-60089,60091-60093 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r60080 | andrew.kuchling | 2008-01-19 17:26:13 +0100 (Sat, 19 Jan 2008) | 2 lines Patch #742598 from Michael Pomraning: add .timeout attribute to SocketServer that will call .handle_timeout() method when no requests are received within the timeout period. ........ r60081 | andrew.kuchling | 2008-01-19 17:34:09 +0100 (Sat, 19 Jan 2008) | 1 line Add item ........ r60082 | christian.heimes | 2008-01-19 17:39:27 +0100 (Sat, 19 Jan 2008) | 2 lines Disabled test_xmlrpc:test_404. It's causing lots of false alarms. I also disabled a test in test_ssl which requires network access to svn.python.org. This fixes a bug Skip has reported a while ago. ........ r60083 | georg.brandl | 2008-01-19 18:38:53 +0100 (Sat, 19 Jan 2008) | 2 lines Clarify thread.join() docs. #1873. ........ r60084 | georg.brandl | 2008-01-19 19:02:46 +0100 (Sat, 19 Jan 2008) | 2 lines #1782: don't leak in error case in PyModule_AddXxxConstant. Patch by Hrvoje Nik?\197?\161i?\196?\135. ........ r60085 | andrew.kuchling | 2008-01-19 19:08:52 +0100 (Sat, 19 Jan 2008) | 1 line Sort two names into position ........ r60086 | andrew.kuchling | 2008-01-19 19:18:41 +0100 (Sat, 19 Jan 2008) | 2 lines Patch #976880: add mmap .rfind() method, and 'end' paramter to .find(). Contributed by John Lenton. ........ r60087 | facundo.batista | 2008-01-19 19:38:19 +0100 (Sat, 19 Jan 2008) | 5 lines Fix #1693149. Now you can pass several modules separated by coma to trace.py in the same --ignore-module option. Thanks Raghuram Devarakonda. ........ r60088 | facundo.batista | 2008-01-19 19:45:46 +0100 (Sat, 19 Jan 2008) | 3 lines Comment in NEWS regarding the change in trace.py. ........ r60089 | skip.montanaro | 2008-01-19 19:47:24 +0100 (Sat, 19 Jan 2008) | 2 lines missing from r60088 checkin. ........ r60091 | andrew.kuchling | 2008-01-19 20:14:05 +0100 (Sat, 19 Jan 2008) | 1 line Add item ........ r60092 | georg.brandl | 2008-01-19 20:27:05 +0100 (Sat, 19 Jan 2008) | 4 lines Fix #1679: "0x" was taken as a valid integer literal. Fixes the tokenizer, tokenize.py and int() to reject this. Patches by Malte Helmert. ........ r60093 | georg.brandl | 2008-01-19 20:48:19 +0100 (Sat, 19 Jan 2008) | 3 lines Fix #1146: TextWrap vs words 1-character shorter than the width. Patch by Quentin Gallet-Gilles. ........
Diffstat (limited to 'Lib')
-rw-r--r--Lib/SocketServer.py45
-rw-r--r--Lib/test/test_builtin.py5
-rw-r--r--Lib/test/test_grammar.py2
-rw-r--r--Lib/test/test_mmap.py36
-rw-r--r--Lib/test/test_socket.py1
-rw-r--r--Lib/test/test_ssl.py22
-rw-r--r--Lib/test/test_textwrap.py13
-rw-r--r--Lib/test/test_xmlrpc.py3
-rw-r--r--Lib/textwrap.py7
-rw-r--r--Lib/tokenize.py6
-rw-r--r--Lib/trace.py8
11 files changed, 134 insertions, 14 deletions
diff --git a/Lib/SocketServer.py b/Lib/SocketServer.py
index 994a3c6..f62b7df 100644
--- a/Lib/SocketServer.py
+++ b/Lib/SocketServer.py
@@ -158,6 +158,7 @@ class BaseServer:
- server_bind()
- server_activate()
- get_request() -> request, client_address
+ - handle_timeout()
- verify_request(request, client_address)
- server_close()
- process_request(request, client_address)
@@ -171,6 +172,7 @@ class BaseServer:
Class variables that may be overridden by derived classes or
instances:
+ - timeout
- address_family
- socket_type
- allow_reuse_address
@@ -182,6 +184,8 @@ class BaseServer:
"""
+ timeout = None
+
def __init__(self, server_address, RequestHandlerClass):
"""Constructor. May be extended, do not override."""
self.server_address = server_address
@@ -204,8 +208,9 @@ class BaseServer:
# finishing a request is fairly arbitrary. Remember:
#
# - handle_request() is the top-level call. It calls
- # get_request(), verify_request() and process_request()
- # - get_request() is different for stream or datagram sockets
+ # await_request(), verify_request() and process_request()
+ # - get_request(), called by await_request(), is different for
+ # stream or datagram sockets
# - process_request() is the place that may fork a new process
# or create a new thread to finish the request
# - finish_request() instantiates the request handler class;
@@ -214,7 +219,7 @@ class BaseServer:
def handle_request(self):
"""Handle one request, possibly blocking."""
try:
- request, client_address = self.get_request()
+ request, client_address = self.await_request()
except socket.error:
return
if self.verify_request(request, client_address):
@@ -224,6 +229,28 @@ class BaseServer:
self.handle_error(request, client_address)
self.close_request(request)
+ def await_request(self):
+ """Call get_request or handle_timeout, observing self.timeout.
+
+ Returns value from get_request() or raises socket.timeout exception if
+ timeout was exceeded.
+ """
+ if self.timeout is not None:
+ # If timeout == 0, you're responsible for your own fd magic.
+ import select
+ fd_sets = select.select([self], [], [], self.timeout)
+ if not fd_sets[0]:
+ self.handle_timeout()
+ raise socket.timeout("Listening timed out")
+ return self.get_request()
+
+ def handle_timeout(self):
+ """Called if no new request arrives within self.timeout.
+
+ Overridden by ForkingMixIn.
+ """
+ pass
+
def verify_request(self, request, client_address):
"""Verify the request. May be overridden.
@@ -289,6 +316,7 @@ class TCPServer(BaseServer):
- server_bind()
- server_activate()
- get_request() -> request, client_address
+ - handle_timeout()
- verify_request(request, client_address)
- process_request(request, client_address)
- close_request(request)
@@ -301,6 +329,7 @@ class TCPServer(BaseServer):
Class variables that may be overridden by derived classes or
instances:
+ - timeout
- address_family
- socket_type
- request_queue_size (only for stream sockets)
@@ -405,11 +434,12 @@ class ForkingMixIn:
"""Mix-in class to handle each request in a new process."""
+ timeout = 300
active_children = None
max_children = 40
def collect_children(self):
- """Internal routine to wait for died children."""
+ """Internal routine to wait for children that have exited."""
while self.active_children:
if len(self.active_children) < self.max_children:
options = os.WNOHANG
@@ -424,6 +454,13 @@ class ForkingMixIn:
if not pid: break
self.active_children.remove(pid)
+ def handle_timeout(self):
+ """Wait for zombies after self.timeout seconds of inactivity.
+
+ May be extended, do not override.
+ """
+ self.collect_children()
+
def process_request(self, request, client_address):
"""Fork a new subprocess to process the request."""
self.collect_children()
diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py
index 4cf5916..2718bbf 100644
--- a/Lib/test/test_builtin.py
+++ b/Lib/test/test_builtin.py
@@ -743,6 +743,11 @@ class BuiltinTest(unittest.TestCase):
self.assertEqual(int('0O123', 8), 83)
self.assertEqual(int('0B100', 2), 4)
+ # Bug 1679: "0x" is not a valid hex literal
+ self.assertRaises(ValueError, int, "0x", 16)
+ self.assertRaises(ValueError, int, "0x", 0)
+
+
# SF bug 1334662: int(string, base) wrong answers
# Various representations of 2**32 evaluated to 0
# rather than 2**32 in previous versions
diff --git a/Lib/test/test_grammar.py b/Lib/test/test_grammar.py
index 7ab7557..0777307 100644
--- a/Lib/test/test_grammar.py
+++ b/Lib/test/test_grammar.py
@@ -32,6 +32,8 @@ class TokenTests(unittest.TestCase):
self.assertEquals(0o377, 255)
self.assertEquals(2147483647, 0o17777777777)
self.assertEquals(0b1001, 9)
+ # "0x" is not a valid literal
+ self.assertRaises(SyntaxError, eval, "0x")
from sys import maxsize
if maxsize == 2147483647:
self.assertEquals(-2147483647-1, -0o20000000000)
diff --git a/Lib/test/test_mmap.py b/Lib/test/test_mmap.py
index 3d30109..5bf7eb0 100644
--- a/Lib/test/test_mmap.py
+++ b/Lib/test/test_mmap.py
@@ -252,6 +252,42 @@ class MmapTests(unittest.TestCase):
self.assertEqual(m.find(slice + b'x'), -1)
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):
# make sure a double close doesn't crash on Solaris (Bug# 665913)
f = open(TESTFN, 'wb+')
diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py
index 23b7759..d3b870f 100644
--- a/Lib/test/test_socket.py
+++ b/Lib/test/test_socket.py
@@ -288,7 +288,6 @@ class GeneralModuleTests(unittest.TestCase):
def testRefCountGetNameInfo(self):
# Testing reference count for getnameinfo
- import sys
if hasattr(sys, "getrefcount"):
try:
# On some versions, this loses a reference
diff --git a/Lib/test/test_ssl.py b/Lib/test/test_ssl.py
index 81943a5..34bb31a 100644
--- a/Lib/test/test_ssl.py
+++ b/Lib/test/test_ssl.py
@@ -38,6 +38,27 @@ def handle_error(prefix):
class BasicTests(unittest.TestCase):
+ def testSSLconnect(self):
+ if not test_support.is_resource_enabled('network'):
+ return
+ s = ssl.wrap_socket(socket.socket(socket.AF_INET),
+ cert_reqs=ssl.CERT_NONE)
+ s.connect(("svn.python.org", 443))
+ c = s.getpeercert()
+ if c:
+ raise test_support.TestFailed("Peer cert %s shouldn't be here!")
+ s.close()
+
+ # this should fail because we have no verification certs
+ s = ssl.wrap_socket(socket.socket(socket.AF_INET),
+ cert_reqs=ssl.CERT_REQUIRED)
+ try:
+ s.connect(("svn.python.org", 443))
+ except ssl.SSLError:
+ pass
+ finally:
+ s.close()
+
def testCrucialConstants(self):
ssl.PROTOCOL_SSLv2
ssl.PROTOCOL_SSLv23
@@ -81,7 +102,6 @@ class BasicTests(unittest.TestCase):
class NetworkedTests(unittest.TestCase):
def testConnect(self):
-
s = ssl.wrap_socket(socket.socket(socket.AF_INET),
cert_reqs=ssl.CERT_NONE)
s.connect(("svn.python.org", 443))
diff --git a/Lib/test/test_textwrap.py b/Lib/test/test_textwrap.py
index b226c71..3f2239d 100644
--- a/Lib/test/test_textwrap.py
+++ b/Lib/test/test_textwrap.py
@@ -385,6 +385,19 @@ How *do* you spell that odd word, anyways?
' o'],
subsequent_indent = ' '*15)
+ # bug 1146. Prevent a long word to be wrongly wrapped when the
+ # preceding word is exactly one character shorter than the width
+ self.check_wrap(self.text, 12,
+ ['Did you say ',
+ '"supercalifr',
+ 'agilisticexp',
+ 'ialidocious?',
+ '" How *do*',
+ 'you spell',
+ 'that odd',
+ 'word,',
+ 'anyways?'])
+
def test_nobreak_long(self):
# Test with break_long_words disabled
self.wrapper.break_long_words = 0
diff --git a/Lib/test/test_xmlrpc.py b/Lib/test/test_xmlrpc.py
index ade6f84..16ef798 100644
--- a/Lib/test/test_xmlrpc.py
+++ b/Lib/test/test_xmlrpc.py
@@ -347,7 +347,8 @@ class SimpleServerTestCase(unittest.TestCase):
# protocol error; provide additional information in test output
self.fail("%s\n%s" % (e, e.headers))
- def test_404(self):
+ # [ch] The test 404 is causing lots of false alarms.
+ def XXXtest_404(self):
# send POST with httplib, it should return 404 header and
# 'Not Found' message.
conn = httplib.HTTPConnection('localhost', PORT)
diff --git a/Lib/textwrap.py b/Lib/textwrap.py
index e6e1b97..7e05c1a 100644
--- a/Lib/textwrap.py
+++ b/Lib/textwrap.py
@@ -159,7 +159,12 @@ class TextWrapper:
Handle a chunk of text (most likely a word, not whitespace) that
is too long to fit in any line.
"""
- space_left = max(width - cur_len, 1)
+ # Figure out when indent is larger than the specified width, and make
+ # sure at least one character is stripped off on every pass
+ if width < 1:
+ space_left = 1
+ else:
+ space_left = width - cur_len
# If we're allowed to break long words, then do so: put as much
# of the next chunk onto the current line as will fit.
diff --git a/Lib/tokenize.py b/Lib/tokenize.py
index 0d9a3fb..797b6e0 100644
--- a/Lib/tokenize.py
+++ b/Lib/tokenize.py
@@ -49,9 +49,9 @@ Comment = r'#[^\r\n]*'
Ignore = Whitespace + any(r'\\\r?\n' + Whitespace) + maybe(Comment)
Name = r'[a-zA-Z_]\w*'
-Hexnumber = r'0[xX][\da-fA-F]*'
-Binnumber = r'0[bB][01]*'
-Octnumber = r'0[oO][0-7]*'
+Hexnumber = r'0[xX][\da-fA-F]+'
+Binnumber = r'0[bB][01]+'
+Octnumber = r'0[oO][0-7]+'
Decnumber = r'(?:0+|[1-9]\d*)'
Intnumber = group(Hexnumber, Binnumber, Octnumber, Decnumber)
Exponent = r'[eE][-+]?\d+'
diff --git a/Lib/trace.py b/Lib/trace.py
index f6da026..c52c8a8 100644
--- a/Lib/trace.py
+++ b/Lib/trace.py
@@ -96,8 +96,9 @@ Modifiers:
(Can only be used with --count or --report.)
Filters, may be repeated multiple times:
---ignore-module=<mod> Ignore the given module and its submodules
- (if it is a package).
+--ignore-module=<mod> Ignore the given module(s) and its submodules
+ (if it is a package). Accepts comma separated
+ list of module names
--ignore-dir=<dir> Ignore files in the given directory (multiple
directories can be joined by os.pathsep).
""" % sys.argv[0])
@@ -725,7 +726,8 @@ def main(argv=None):
continue
if opt == "--ignore-module":
- ignore_modules.append(val)
+ for mod in val.split(","):
+ ignore_modules.append(mod.strip())
continue
if opt == "--ignore-dir":