return lines
def truncate(self, size=None):
- _complain_ifclosed(self.closed)
+ _complain_ifclosed(self.closed)
if size is None:
size = self.pos
elif size < 0:
# be able to tell what timezone has daylight savings
if time.tzname[0] == time.tzname[1] and \
time.daylight:
- break
+ break
else:
tz = value
break
# Append the source distribution include and library directories,
# this allows distutils on windows to work in the source tree
self.include_dirs.append(os.path.join(sys.exec_prefix, 'PC'))
- self.library_dirs.append(os.path.join(sys.exec_prefix, 'PCBuild'))
+ self.library_dirs.append(os.path.join(sys.exec_prefix, 'PC', 'VC6'))
+ #self.library_dirs.append(os.path.join(sys.exec_prefix, 'PCBuild'))
# OS/2 (EMX) doesn't support Debug vs Release builds, but has the
# import libraries in its "Config" subdirectory
if self.__response and self.__response.isclosed():
self.__response = None
-
+
# in certain cases, we cannot issue another request on this connection.
# this occurs when:
# 1) we are in the process of sending a request. (_CS_REQ_STARTED)
# If headers already contains a host header, then define the
# optional skip_host argument to putrequest(). The check is
# harder because field names are case insensitive.
- if 'host' in [k.lower() for k in headers]:
+ if 'host' in [k.lower() for k in headers]:
self.putrequest(method, url, skip_host=1)
else:
self.putrequest(method, url)
# compatibility).
if width >= maxwidth:
- return int(istart + self._randbelow(width))
+ return int(istart + self._randbelow(width))
return int(istart + int(self.random()*width))
if step == 1:
raise ValueError, "empty range for randrange() (%d,%d, %d)" % (istart, istop, width)
return subpattern
def _parse_sub_cond(source, state, condgroup):
- item_yes = _parse(source, state)
+ item_yes = _parse(source, state)
if source.match("|"):
- item_no = _parse(source, state)
+ item_no = _parse(source, state)
if source.match("|"):
raise error, "conditional backref with more than two branches"
else:
else:
loops = LOOPS
main(loops)
-
applesingle.decode(test_support.TESTFN, TESTFN2)
self.compareData(False, dataforkdata)
self.compareData(True, resourceforkdata)
-
+
def test_applesingle_resonly(self):
try:
os.unlink(TESTFN2)
ord(">"): u">",
ord('"'): u""",
}
-
+
for n in (1, 10, 100, 1000):
text = u'abc<def>ghi'*n
text.translate(charmap)
tstring = test_multibytecodec_support.load_teststring('gbk')
codectests = (
# invalid bytes
- ("abc\x80\x80\xc1\xc4", "strict", None),
- ("abc\xc8", "strict", None),
+ ("abc\x80\x80\xc1\xc4", "strict", None),
+ ("abc\xc8", "strict", None),
("abc\x80\x80\xc1\xc4", "replace", u"abc\ufffd\u804a"),
("abc\x80\x80\xc1\xc4\xc8", "replace", u"abc\ufffd\u804a\ufffd"),
("abc\x80\x80\xc1\xc4", "ignore", u"abc\u804a"),
if __name__ == "__main__":
test_main()
-
if __name__ == "__main__":
test_main()
-
if __name__ == "__main__":
test_main()
-
if __name__ == "__main__":
test_main()
-
test_multibytecodec_support.register_skip_expected(TestGB2312Map, TestGBKMap)
if __name__ == "__main__":
test_main()
-
TestSJISX0213Map)
if __name__ == "__main__":
test_main()
-
TestEUCKRMap, TestJOHABMap)
if __name__ == "__main__":
test_main()
-
test_multibytecodec_support.register_skip_expected(TestBIG5Map, TestCP950Map)
if __name__ == "__main__":
test_main()
-
]:
if ascii.unctrl(ch) != expected:
print 'curses.unctrl fails on character', repr(ch)
-
+
def main(stdscr):
finally:
curses.resetty()
-
+
if __name__ == '__main__':
curses.wrapper(main)
unit_tests()
# this makes a crash more likely:
import gc; gc.collect()
vereq(hasattr(c, 'attr'), False)
-
+
def test_main():
weakref_segfault() # Must be first, somehow
Doctests = doctest.DocTestSuite(difflib)
test_support.run_unittest(TestSFbugs, Doctests)
-
new = marshal.load(file(test_support.TESTFN, "rb"))
self.assertEqual(b, new)
self.assertEqual(type(b), type(new))
-
+
class FloatTestCase(unittest.TestCase):
def test_floats(self):
# Test a few floats
marshal.load(file(test_support.TESTFN, "rb"))
self.assertEqual(s, new)
os.unlink(test_support.TESTFN)
-
+
class ExceptionTestCase(unittest.TestCase):
def test_exceptions(self):
new = marshal.loads(marshal.dumps(StopIteration))
marshal.load(file(test_support.TESTFN, "rb"))
self.assertEqual(self.d, new)
os.unlink(test_support.TESTFN)
-
+
def test_list(self):
lst = self.d.items()
new = marshal.loads(marshal.dumps(lst))
marshal.load(file(test_support.TESTFN, "rb"))
self.assertEqual(t, new)
os.unlink(test_support.TESTFN)
-
+
class BugsTestCase(unittest.TestCase):
def test_bug_5888452(self):
# Simple-minded check for SF 588452: Debug build crashes
eq('abc', '900150983cd24fb0d6963f7d28e17f72')
eq('message digest', 'f96b697d7cb7938d525a2f31aaf161d0')
eq('abcdefghijklmnopqrstuvwxyz', 'c3fcd3d76192e4007dfb496cca67e13b')
- eq('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789',
+ eq('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789',
'd174ab98d277d9f5a5611c2c9f419d9f')
- eq('12345678901234567890123456789012345678901234567890123456789012345678901234567890',
+ eq('12345678901234567890123456789012345678901234567890123456789012345678901234567890',
'57edf4a22be3c955ac49da2e2107b67a')
def test_hexdigest(self):
if __name__ == "__main__":
test_main()
-
break
else:
sys.modules[case.__module__].skip_expected = False
-
path = os.path.join(base, 'dir1', os.curdir, 'dir2', 'dir3', 'dir4',
'dir5', 'dir6')
os.makedirs(path)
-
-
-
+
+
+
def tearDown(self):
path = os.path.join(test_support.TESTFN, 'dir1', 'dir2', 'dir3',
'dir4', 'dir5', 'dir6')
20003)
self.assertEqual(re.match('.*?cd', 20000*'abc'+'de').end(0), 60001)
# non-simple '*?' still used to hit the recursion limit, before the
- # non-recursive scheme was implemented.
+ # non-recursive scheme was implemented.
self.assertEqual(re.search('(a|b)*?c', 10000*'ab'+'cd').end(0), 20001)
def test_bug_612074(self):
def __init__(self, value):
self.value = value
def __hash__(self):
- return self.value
+ return self.value
def __deepcopy__(self, memo=None):
return Tracer(self.value + 1)
t = Tracer(10)
if __name__ == "__main__":
test_main(verbose=True)
-
-
# which have special Unicode support in posixmodule.
if (not hasattr(sys, "getwindowsversion") or
sys.getwindowsversion()[3] < 2): # 0=win32s or 1=9x/ME
- TESTFN_UNICODE_UNENCODEABLE = None
+ TESTFN_UNICODE_UNENCODEABLE = None
else:
# Japanese characters (I think - from bug 846133)
TESTFN_UNICODE_UNENCODEABLE = u"@test-\u5171\u6709\u3055\u308c\u308b"
class TestUnicodeFiles(unittest.TestCase):
# The 'do_' functions are the actual tests. They generally assume the
# file already exists etc.
-
+
# Do all the tests we can given only a single filename. The file should
# exist.
def _do_single(self, filename):
# basename should appear in listdir.
path, base = os.path.split(os.path.abspath(filename))
self.failUnless(base in os.listdir(path))
-
+
# Do as many "equivalancy' tests as we can - ie, check that although we
# have different types for the filename, they refer to the same file.
def _do_equivilent(self, filename1, filename2):
self._do_single(filename)
finally:
os.unlink(filename)
-
+
def _test_equivalent(self, filename1, filename2):
remove_if_exists(filename1)
self.failUnless(not os.path.exists(filename2))
isinstance(args[1], MockResponse))
+def sanepathname2url(path):
+ import urllib
+ urlpath = urllib.pathname2url(path)
+ if os.name == "nt" and urlpath.startswith("///"):
+ urlpath = urlpath[2:]
+ # XXX don't ask me about the mac...
+ return urlpath
+
class HandlerTests(unittest.TestCase):
def test_ftp(self):
h = urllib2.FileHandler()
o = h.parent = MockOpener()
- #from test_support import TESTFN
- TESTFN = "test.txt"
+ TESTFN = test_support.TESTFN
+ urlpath = sanepathname2url(os.path.abspath(TESTFN))
towrite = "hello, world\n"
for url in [
- "file://localhost%s/%s" % (os.getcwd(), TESTFN),
- "file://%s/%s" % (os.getcwd(), TESTFN),
- "file://%s%s/%s" % (socket.gethostbyname('localhost'),
- os.getcwd(), TESTFN),
- "file://%s%s/%s" % (socket.gethostbyname(socket.gethostname()),
- os.getcwd(), TESTFN),
- # XXX Windows / Mac format(s), ... ?
+ "file://localhost%s" % urlpath,
+ "file://%s" % urlpath,
+ "file://%s%s" % (socket.gethostbyname('localhost'), urlpath),
+ "file://%s%s" % (socket.gethostbyname(socket.gethostname()),
+ urlpath),
]:
- f = open(TESTFN, "w")
+ f = open(TESTFN, "wb")
try:
try:
f.write(towrite)
r = h.file_open(Request(url))
try:
data = r.read()
- read_time = time.time()
headers = r.info()
newurl = r.geturl()
finally:
r.close()
+ stats = os.stat(TESTFN)
+ modified = rfc822.formatdate(stats.st_mtime)
finally:
os.remove(TESTFN)
self.assertEqual(data, towrite)
self.assertEqual(headers["Content-type"], "text/plain")
self.assertEqual(headers["Content-length"], "13")
- # Fudge Last-modified string comparison by one second to
- # prevent spurious failure on crossing a second boundary while
- # executing this test.
- unfudged = rfc822.formatdate(read_time)
- fudged = rfc822.formatdate(read_time-1)
- self.assert_(headers["Last-modified"] in [unfudged, fudged])
+ self.assertEqual(headers["Last-modified"], modified)
for url in [
- "file://localhost:80%s/%s" % (os.getcwd(), TESTFN),
+ "file://localhost:80%s" % urlpath,
# XXXX bug: these fail with socket.gaierror, should be URLError
## "file://%s:80%s/%s" % (socket.gethostbyname('localhost'),
## os.getcwd(), TESTFN),
## (os.getcwd(), TESTFN),
]:
try:
- f = open(TESTFN, "w")
+ f = open(TESTFN, "wb")
try:
f.write(towrite)
finally:
return ''.join(format_exception(etype, value, tb, limit))
finally:
etype = value = tb = None
-
+
def print_last(limit=None, file=None):
"""This is a shorthand for 'print_exception(sys.last_type,
def add_parent(self, parent):
self.parent = parent
-
+
def close(self):
# Only exists for backwards compatibility
pass
-
+
def __lt__(self, other):
if not hasattr(other, "handler_order"):
# Try to preserve the old behavior of having custom classes
# prompting for the information. Crap. This isn't great
# but it's better than the current 'repeat until recursion
# depth exceeded' approach <wink>
- raise HTTPError(req.get_full_url(), 401, "digest auth failed",
+ raise HTTPError(req.get_full_url(), 401, "digest auth failed",
headers, None)
else:
self.retried += 1
else:
# XXX handle auth-int.
pass
-
+
# XXX should the partial digests be encoded too?
base = 'username="%s", realm="%s", nonce="%s", uri="%s", ' \
def http_error_401(self, req, fp, code, msg, headers):
host = urlparse.urlparse(req.get_full_url())[1]
- retry = self.http_error_auth_reqed('www-authenticate',
+ retry = self.http_error_auth_reqed('www-authenticate',
host, req, headers)
self.reset_retry_count()
return retry
def http_error_407(self, req, fp, code, msg, headers):
host = req.get_host()
- retry = self.http_error_auth_reqed('proxy-authenticate',
+ retry = self.http_error_auth_reqed('proxy-authenticate',
host, req, headers)
self.reset_retry_count()
return retry
raise URLError(err)
# Pick apart the HTTPResponse object to get the various pieces
- # of the
+ # of the
resp = addinfourl(r.fp, r.msg, req.get_full_url())
resp.code = r.status
resp.msg = r.reason
{
PyListObject *op;
size_t nbytes;
+ int allocated_size = roundupsize(size);
+
if (size < 0) {
PyErr_BadInternalCall();
return NULL;
}
- nbytes = size * sizeof(PyObject *);
+ nbytes = allocated_size * sizeof(PyObject *);
/* Check for overflow */
- if (nbytes / sizeof(PyObject *) != (size_t)size) {
+ if (nbytes / sizeof(PyObject *) != (size_t)allocated_size) {
return PyErr_NoMemory();
}
op = PyObject_GC_New(PyListObject, &PyList_Type);
if (op->ob_item == NULL) {
return PyErr_NoMemory();
}
- memset(op->ob_item, 0, sizeof(*op->ob_item) * size);
+ memset(op->ob_item, 0, sizeof(*op->ob_item) * allocated_size);
}
op->ob_size = size;
_PyObject_GC_TRACK(op);
return -1;
}
items = self->ob_item;
- NRESIZE(items, PyObject *, self->ob_size+1);
+ if (roundupsize(self->ob_size) - 1 == self->ob_size || items == NULL)
+ NRESIZE(items, PyObject *, self->ob_size+1);
if (items == NULL) {
PyErr_NoMemory();
return -1;
saved_ob_size = self->ob_size;
saved_ob_item = self->ob_item;
self->ob_size = 0;
- self->ob_item = empty_ob_item = PyMem_NEW(PyObject *, 0);
+/* self->ob_item = empty_ob_item = PyMem_NEW(PyObject *, 0); */
+ self->ob_item = empty_ob_item = PyMem_NEW(PyObject *, roundupsize(0));
if (keyfunc != NULL) {
for (i=0 ; i < saved_ob_size ; i++) {