From 6b76e11fbdc9752b4a59968e2ca63978b82f990c Mon Sep 17 00:00:00 2001 From: Giampaolo Rodola Date: Tue, 10 Jan 2012 23:27:51 +0000 Subject: reindent + little refactoring --- LICENSE | 4 ++-- sendfilemodule.c | 14 +++++++------- setup.py | 1 - test/test_sendfile.py | 33 ++++++++++++++++----------------- 4 files changed, 25 insertions(+), 27 deletions(-) diff --git a/LICENSE b/LICENSE index de62c54..6e3ae9a 100644 --- a/LICENSE +++ b/LICENSE @@ -4,10 +4,10 @@ This software is distributed under the MIT license reproduced below: Original author: Copyright (C) 2005-2008 Ben Woolley -AIX support code: +AIX support code by: Copyright (C) 2008-2009 Niklas Edmundsson -Current maintainer: +Rewritten from scratch and maintained by: Copyright (C) 2009-2012 Giampaolo Rodola' Permission to use, copy, modify, and distribute this software and diff --git a/sendfilemodule.c b/sendfilemodule.c index 7453565..d46ef7a 100644 --- a/sendfilemodule.c +++ b/sendfilemodule.c @@ -13,8 +13,8 @@ * The AIX support code is: * Copyright (C) 2008,2009 Niklas Edmundsson * - * Currently maintained by Giampaolo Rodola' - * Copyright (C) 2011,2012 + * Rewritten from scratch and maintained by Giampaolo Rodola' + * Copyright (C) 2009,2012 * * * The MIT License @@ -189,7 +189,7 @@ method_sendfile(PyObject *self, PyObject *args) if (!PyArg_ParseTuple(args, "iiLk|s#s#", &out_fd, &in_fd, &offset, &nbytes, &hdr, &hdrsize, - &trail, &trailsize)) + &trail, &trailsize)) return NULL; if(hdr != NULL) { @@ -205,8 +205,8 @@ method_sendfile(PyObject *self, PyObject *args) sf_iobuf.trailer_length = trailsize; } else { - sf_iobuf.trailer_data = NULL; - sf_iobuf.trailer_length = 0; + sf_iobuf.trailer_data = NULL; + sf_iobuf.trailer_length = 0; } sf_iobuf.file_descriptor = in_fd; sf_iobuf.file_offset = offset; @@ -214,9 +214,9 @@ method_sendfile(PyObject *self, PyObject *args) Py_BEGIN_ALLOW_THREADS; do { - sf_iobuf.bytes_sent = 0; /* Really needed? */ + sf_iobuf.bytes_sent = 0; /* Really needed? */ rc = send_file(&out_fd, &sf_iobuf, SF_DONT_CACHE); - sts += sf_iobuf.bytes_sent; + sts += sf_iobuf.bytes_sent; } while( rc == 1 || (rc == -1 && errno == EINTR) ); Py_END_ALLOW_THREADS; diff --git a/setup.py b/setup.py index b69a511..39f83e6 100644 --- a/setup.py +++ b/setup.py @@ -26,7 +26,6 @@ def main(): version=version, description='A Python interface to sendfile(2)', long_description=open('README', 'r').read(), - url='http://code.google.com/p/pysendfile/', author='Giampaolo Rodola', author_email='g.rodola@gmail.com', download_url=download_url, diff --git a/test/test_sendfile.py b/test/test_sendfile.py index a379c4c..65c5d33 100644 --- a/test/test_sendfile.py +++ b/test/test_sendfile.py @@ -47,6 +47,20 @@ def safe_remove(file): except OSError: pass +def has_large_file_support(): + # taken from Python's Lib/test/test_largefile.py + with open(TESTFN, 'wb', buffering=0) as f: + try: + f.seek(BIGFILE_SIZE) + # seeking is not enough of a test: you must write and flush too + f.write(_bytes('x')) + f.flush() + except (IOError, OverflowError): + return False + else: + return True + + class Handler(asynchat.async_chat): ac_in_buffer_size = BUFFER_LEN ac_out_buffer_size = BUFFER_LEN @@ -197,6 +211,7 @@ class TestSendfile(unittest.TestCase): self.client.close() if self.server.running: self.server.stop() + self.server = None # allow garbage collection def test_send_whole_file(self): # normal send @@ -501,21 +516,6 @@ def test_main(): atexit.register(cleanup) - def has_large_file_support(): - # taken from Python's Lib/test/test_largefile.py - f = open(TESTFN, 'wb', buffering=0) - try: - f.seek(BIGFILE_SIZE) - # seeking is not enough of a test: you must write and flush too - f.write(_bytes('x')) - f.flush() - except (IOError, OverflowError): - f.close() - return False - else: - f.close() - return True - test_suite = unittest.TestSuite() test_suite.addTest(unittest.makeSuite(TestSendfile)) if has_large_file_support(): @@ -523,8 +523,7 @@ def test_main(): #test_suite.addTest(unittest.makeSuite(TestLargeFile)) pass else: - atexit.register(warnings.warn, "couldn't run large file test because " - "filesystem does not have largefile support.", RuntimeWarning) + atexit.register(warnings.warn, "large files unsupported", RuntimeWarning) cleanup() with open(TESTFN, "wb") as f: f.write(DATA) -- cgit v1.2.1