--- setup.py.py23	2009-02-26 19:49:41.000000000 +0100
+++ setup.py	2009-03-03 12:28:11.000000000 +0100
@@ -21,7 +21,7 @@
 # License along with this library; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 #
-import sys, os, subprocess
+import sys, os
 from warnings import warn
 from setuptools import setup, Extension
 
@@ -44,16 +44,17 @@ compile_args = []
 warnflags = ['-Wall', '-Wextra', '-pedantic', '-Wswitch-enum', '-Wswitch-default']
 compile_args.extend(warnflags)
 link_args = []
-if not subprocess.Popen('touch gnu99-test.c; gcc -std=gnu99 -E gnu99-test.c > /dev/null; rm -f gnu99-test.c',
-		shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, close_fds=True).stdout.read():
+if not os.popen('touch gnu99-test.c; gcc -std=gnu99 -E gnu99-test.c > /dev/null; rm -f gnu99-test.c').read():
     compile_args.append('-std=gnu99')
 
-pc_cflags = subprocess.Popen("pkg-config --cflags liblzma", shell=True, stdout=subprocess.PIPE, close_fds=True).stdout.readline().strip()
+pc_cflags = os.popen("pkg-config --cflags liblzma").readline().strip()
 if(pc_cflags):
 	compile_args.extend(pc_cflags.split(' '))
-pc_libs = subprocess.Popen("pkg-config --libs liblzma", shell=True, stdout=subprocess.PIPE, close_fds=True).stdout.readline().strip()
+pc_libs = os.popen("pkg-config --libs liblzma").readline().strip()
 if(pc_libs):
 	link_args.extend(pc_libs.split(' '))
+else:
+	link_args.append('-llzma')
 
 extens=[Extension('lzma', c_files, extra_compile_args=compile_args, extra_link_args=link_args, define_macros=version_define)]
 
=== modified file 'src/liblzma.c'
--- src/liblzma.c	2010-04-13 21:05:20 +0000
+++ src/liblzma.c	2010-08-05 12:40:10 +0000
@@ -20,7 +20,9 @@
 LZMA_compress(__attribute__((unused)) PyObject *self, PyObject *args, PyObject *kwargs)
 {
 	PyObject *ret = NULL, *options_dict = NULL;
+#if USE_PYBUFFER
 	Py_buffer pdata;
+#endif
 	uint8_t *data;
 	Py_ssize_t datasize, bufsize;
 	lzma_ret lzuerror;
@@ -31,16 +33,24 @@
 
     	static char *kwlist[] = {"input", "options", NULL};
 
+#if USE_PYBUFFER
 	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s*|O:compress", kwlist,
 			       	&pdata, &options_dict))
 		return NULL;
+#else
+	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s#|O:compress", kwlist,
+			       	(char **) &data, &datasize, &options_dict))
+		return NULL;
+#endif
 
 	filters[0].options = &options;
 	if(!init_lzma_options("compress", options_dict, filters))
 		return NULL;
 
+#if USE_PYBUFFER
 	data = pdata.buf;
 	datasize = pdata.len;
+#endif
 
 	lzma_stream tmp = LZMA_STREAM_INIT;
 	*lzus = tmp;
@@ -95,14 +105,18 @@
 			_PyString_Resize(&ret, (Py_ssize_t)lzus->total_out);
 	}
 
+#if USE_PYBUFFER
 	PyBuffer_Release(&pdata);
+#endif
 	return ret;
 
  error:
 	if(lzuerror != LZMA_MEM_ERROR && lzuerror != LZMA_PROG_ERROR)
 		lzma_end(lzus);
 	Py_XDECREF(ret);
+#if USE_PYBUFFER
 	PyBuffer_Release(&pdata);
+#endif
 	return NULL;
 }
 
@@ -120,7 +134,9 @@
 LZMA_decompress(__attribute__((unused)) PyObject *self, PyObject *args, PyObject *kwargs)
 {
 	PyObject *ret = NULL;
+#if USE_PYBUFFER
 	Py_buffer pdata;
+#endif
 	uint8_t *data;
 	Py_ssize_t datasize, bufsize = SMALLCHUNK;
 	uint64_t memlimit = -1;
@@ -130,20 +146,30 @@
 
 	static char *kwlist[] = {"input", "bufsize", "memlimit", NULL};
 
+#if USE_PYBUFFER
 	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s*|lK:decompress", kwlist,
 			  &pdata, &bufsize, &memlimit))
 		return NULL;
 	data = pdata.buf;
 	datasize = pdata.len;
+#else
+	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s#|lK:decompress", kwlist,
+			  (char **) &data, &datasize, &memlimit))
+		return NULL;
+#endif
 
 	if (datasize == 0) {
+#if USE_PYBUFFER
 		PyBuffer_Release(&pdata);
+#endif
 		return PyString_FromString("");
 	}
 
 	ret = PyString_FromStringAndSize(NULL, bufsize);
 	if (!ret) {
+#if USE_PYBUFFER
 		PyBuffer_Release(&pdata);
+#endif
 		return NULL;
 	}
 
@@ -180,7 +206,9 @@
 
 	_PyString_Resize(&ret, (Py_ssize_t)lzus->total_out);
 	lzma_end(lzus);
+#if USE_PYBUFFER
 	PyBuffer_Release(&pdata);
+#endif
 
 	return ret;
 	
@@ -188,7 +216,9 @@
 	if(lzuerror != LZMA_MEM_ERROR && lzuerror != LZMA_PROG_ERROR)
 		lzma_end(lzus);	
 	Py_XDECREF(ret);
+#if USE_PYBUFFER
 	PyBuffer_Release(&pdata);
+#endif
 	return NULL;
 }
 

=== modified file 'src/liblzma.h'
--- src/liblzma.h	2010-02-20 23:08:09 +0000
+++ src/liblzma.h	2010-08-05 12:59:26 +0000
@@ -6,6 +6,24 @@
  */
 #define PY_SSIZE_T_CLEAN 1
 #include <Python.h>
+#if PY_VERSION_HEX >= 0x020600F0
+#define USE_PYBUFFER 1
+#define USE_USECOUNT 1
+#else
+#define Py_TYPE(op)	(op)->ob_type
+#define PyOS_stricmp	strcasecmp
+#define USE_PYBUFFER 0
+#define USE_USECOUNT 0
+#endif
+#if PY_VERSION_HEX < 0x020500F0
+typedef int Py_ssize_t;
+#endif
+#if PY_VERSION_HEX < 0x020400F0
+#define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None
+#define Py_CLEAR(op) do { if (op) { PyObject *tmp = (PyObject *)(op); \
+                                    (op) = NULL; Py_DECREF(tmp); } } while(0)
+#define PyDict_Contains(p, key) (PyDict_GetItem(p, key) != NULL)
+#endif
 #include <stdio.h>
 #include <stdlib.h>
 #if defined (__APPLE__) || defined(__FreeBSD__) || \

=== modified file 'src/liblzma_compressobj.c'
--- src/liblzma_compressobj.c	2010-04-13 20:26:35 +0000
+++ src/liblzma_compressobj.c	2010-08-05 12:40:10 +0000
@@ -14,7 +14,9 @@
 static PyObject *
 LZMAComp_compress(LZMACompObject *self, PyObject *args)
 {
+#if USE_PYBUFFER
 	Py_buffer pdata;
+#endif
 	Py_ssize_t datasize, bufsize = SMALLCHUNK;
     	uint8_t *data;
     	uint64_t totalout;
@@ -23,10 +25,15 @@
 	lzma_ret lzuerror;
 
 	INITCHECK
+#if USE_PYBUFFER
 	if (!PyArg_ParseTuple(args, "s*:compress", &pdata))
 		return NULL;
 	data = pdata.buf;
 	datasize = pdata.len;
+#else
+	if (!PyArg_ParseTuple(args, "s#:compress", (char **) &data, &datasize))
+		return NULL;
+#endif
 
 	ACQUIRE_LOCK(self);
 	if (!self->running) {
@@ -65,12 +72,16 @@
 	_PyString_Resize(&ret, (Py_ssize_t)lzus->total_out - (Py_ssize_t)totalout);
 
 	RELEASE_LOCK(self);
+#if USE_PYBUFFER
 	PyBuffer_Release(&pdata);
+#endif
 	return ret;
 
  error:
 	RELEASE_LOCK(self);
+#if USE_PYBUFFER
 	PyBuffer_Release(&pdata);
+#endif
 	Py_XDECREF(ret);
 	return NULL;
 }
@@ -364,5 +375,7 @@
 	0,						/*tp_subclasses*/
 	0,						/*tp_weaklist*/
 	0,						/*tp_del*/
+#if PY_VERSION_HEX >= 0x020600F0 /* Added in version 2.6 */
 	0						/*tp_version_tag*/
+#endif
 };

=== modified file 'src/liblzma_decompressobj.c'
--- src/liblzma_decompressobj.c	2010-01-13 08:28:17 +0000
+++ src/liblzma_decompressobj.c	2010-08-05 12:40:10 +0000
@@ -16,7 +16,9 @@
 static PyObject *
 LZMADecomp_decompress(LZMADecompObject *self, PyObject *args, PyObject *kwargs)
 {
+#if USE_PYBUFFER
 	Py_buffer pdata;
+#endif
 	Py_ssize_t datasize, oldbufsize, bufsize = SMALLCHUNK;
     	uint8_t *data;
     	uint64_t start_total_out;
@@ -26,11 +28,17 @@
 	static char *kwlist[] = {"data", "max_length", NULL};
    
 	INITCHECK
+#if USE_PYBUFFER
 	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s*|l:decompress", kwlist,
 			  &pdata, &self->max_length))
 		return NULL;
 	data = pdata.buf;
 	datasize = pdata.len;
+#else
+	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s#|l:decompress", kwlist,
+			  (char **) &data, &datasize, &self->max_length))
+		return NULL;
+#endif
 
 	ACQUIRE_LOCK(self);
 	if (!self->running) {
@@ -121,12 +129,16 @@
 	_PyString_Resize(&ret, (Py_ssize_t)lzus->total_out - (Py_ssize_t)start_total_out);
 
 	RELEASE_LOCK(self);
+#if USE_PYBUFFER
 	PyBuffer_Release(&pdata);
+#endif
 	return ret;
 
  error:
 	RELEASE_LOCK(self);
+#if USE_PYBUFFER
 	PyBuffer_Release(&pdata);
+#endif
 	Py_XDECREF(ret);
 	return NULL;
 }
@@ -339,7 +351,7 @@
 	lzma_stream *lzus = &self->lzus;	
 	lzma_ret lzuerror;
 
-	static char *kwlist[] = {"input", "max_length", "memlimit", NULL};
+	static char *kwlist[] = {"max_length", "memlimit", NULL};
 
 	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|lK:LZMADecompressor", kwlist,
 				&self->max_length, &self->memlimit))
@@ -434,5 +446,7 @@
 	0,						/*tp_subclasses*/
 	0,						/*tp_weaklist*/
 	0,						/*tp_del*/
+#if PY_VERSION_HEX >= 0x020600F0 /* Added in version 2.6 */
 	0						/*tp_version_tag*/
+#endif
 };

=== modified file 'src/liblzma_fileobj.c'
--- src/liblzma_fileobj.c	2010-01-13 08:28:17 +0000
+++ src/liblzma_fileobj.c	2010-08-05 12:40:10 +0000
@@ -314,15 +314,22 @@
 LZMAFile_write(LZMAFileObject *self, PyObject *args)
 {
 	PyObject *ret = NULL;
+#if USE_PYBUFFER
 	Py_buffer pbuf;
+#endif
 	char *buf;
 	Py_ssize_t len;
 	lzma_ret lzuerror;
 
+#if USE_PYBUFFER
 	if (!PyArg_ParseTuple(args, "s*:write", &pbuf))
 		return NULL;
 	buf = pbuf.buf;
 	len = pbuf.len;
+#else
+	if (!PyArg_ParseTuple(args, "s#:write", &buf, &len))
+		return NULL;
+#endif
 
 	ACQUIRE_LOCK(self);
 	switch (self->mode) {
@@ -358,7 +365,9 @@
 	ret = Py_None;
 
 cleanup:
+#if USE_PYBUFFER
 	PyBuffer_Release(&pbuf);
+#endif
 	RELEASE_LOCK(self);
 	return ret;
 }
@@ -596,7 +605,9 @@
 		/* we cannot move back, so rewind the stream */
 		lzma_close_real(&lzuerror, self->fp);
 		if (self->fp) {
+#if USE_USECOUNT
 			PyFile_DecUseCount((PyFileObject *)self->file);
+#endif
 			self->fp = NULL;
 		}
 		if (lzuerror != LZMA_OK) {
@@ -611,8 +622,10 @@
 		self->pos = 0;
 		self->fp = lzma_open_real(&lzuerror, self->filters, PyFile_AsFile(self->file), self->memlimit);
 
+#if USE_USECOUNT
 		if (self->fp)
 			PyFile_IncUseCount((PyFileObject *)self->file);
+#endif
 		if (lzuerror != LZMA_OK) {
 			Util_CatchLZMAError(lzuerror, &self->fp->strm, self->fp->encoding);
 			goto cleanup;
@@ -704,7 +717,9 @@
 	ACQUIRE_LOCK(self);
 	lzma_close_real(&lzuerror, self->fp);
 	if (self->fp) {
+#if USE_USECOUNT
 		PyFile_DecUseCount((PyFileObject *)self->file);
+#endif
 		self->fp = NULL;
 	}
 	self->mode = MODE_CLOSED;
@@ -931,7 +946,9 @@
 		Util_CatchLZMAError(lzuerror, &self->fp->strm, self->fp->encoding);
 		goto error;
 	}
+#if USE_USECOUNT
 	PyFile_IncUseCount((PyFileObject *)self->file);
+#endif
 
 	self->mode = self->filters[0].options ? MODE_WRITE : MODE_READ;
 
@@ -958,7 +975,9 @@
 #endif
 	lzma_close_real(&lzuerror, self->fp);
 	if (self->fp) {
+#if USE_USECOUNT
 		PyFile_DecUseCount((PyFileObject *)self->file);
+#endif
 		self->fp = NULL;
 	}
 	Util_DropReadAhead(self);
@@ -1073,5 +1092,7 @@
 	0,					/*tp_subclasses*/
 	0,					/*tp_weaklist*/
 	0,					/*tp_del*/
+#if PY_VERSION_HEX >= 0x020600F0 /* Added in version 2.6 */
 	0					/*tp_version_tag*/
+#endif
 };

=== modified file 'src/liblzma_options.c'
--- src/liblzma_options.c	2010-05-28 20:13:21 +0000
+++ src/liblzma_options.c	2010-08-05 12:59:26 +0000
@@ -246,6 +246,7 @@
 	LZMAOptionsObject *self = (LZMAOptionsObject*)PyType_GenericAlloc(type, nitems);
 	PyObject *levelopts, *levelString, *mf_list;
 
+#if PY_VERSION_HEX >= 0x020400F0
 	self->format = PyTuple_Pack(2, PyString_FromString("xz"), PyString_FromString("alone"));
 	format = self->format;
 	self->check = PyTuple_Pack(3, PyString_FromString("crc32"), PyString_FromString("crc64"),
@@ -264,6 +265,26 @@
 	self->mode_dict = PyDict_New();
 	self->nice_len = PyTuple_Pack(2, PyInt_FromLong((ulong)LZMA_NICE_LEN_MIN),
 		       	PyInt_FromLong((ulong)LZMA_NICE_LEN_MAX));
+#else
+    self->format = Py_BuildValue("(OO)", PyString_FromString("xz"), PyString_FromString("alone"));
+	format = self->format;
+	self->check = Py_BuildValue("(OOO)", PyString_FromString("crc32"), PyString_FromString("crc64"),
+			PyString_FromString("sha256"));
+	check = self->check;
+	self->level = Py_BuildValue("(OO)", PyInt_FromLong((ulong)LZMA_BEST_SPEED),
+			PyInt_FromLong((ulong)LZMA_BEST_COMPRESSION));
+	self->dict_size = Py_BuildValue("(OO)", PyInt_FromLong((ulong)LZMA_DICT_SIZE_MIN),
+			PyInt_FromLong((ulong)LZMA_DICT_SIZE_MAX));
+	self->lc = Py_BuildValue("(OO)", PyInt_FromLong((ulong)LZMA_LCLP_MIN),
+			PyInt_FromLong((ulong)LZMA_LCLP_MAX));
+	self->lp = Py_BuildValue("(OO)", PyInt_FromLong((ulong)LZMA_LCLP_MIN),
+			PyInt_FromLong((ulong)LZMA_LCLP_MAX));
+	self->pb = Py_BuildValue("(OO)", PyInt_FromLong((ulong)LZMA_PB_MIN),
+			PyInt_FromLong((ulong)LZMA_PB_MAX));
+	self->mode_dict = PyDict_New();
+	self->nice_len = Py_BuildValue("(OO)", PyInt_FromLong((ulong)LZMA_NICE_LEN_MIN),
+		       	PyInt_FromLong((ulong)LZMA_NICE_LEN_MAX));
+#endif
 	self->mf_dict = PyDict_New();
 	self->depth = PyInt_FromLong(0);
 
@@ -307,7 +328,11 @@
 		lzma_lzma_preset(&options, levelNum);
 		lzma_filter filter = { LZMA_FILTER_LZMA2, &options };
 		PyObject *options_dict = LZMA_options_get(filter);
+#if PY_VERSION_HEX >= 0x020400F0
 		PyObject *settingsString = PyString_Format(levelopts, PyTuple_Pack(9,
+#else
+		PyObject *settingsString = PyString_Format(levelopts, Py_BuildValue("(OOOOOOOOO)",
+#endif
 					PyInt_FromLong(levelNum),
 					PyDict_GetItem(options_dict, PyString_FromString("lc")),
 					PyDict_GetItem(options_dict, PyString_FromString("lp")),
@@ -460,5 +485,7 @@
 	0,					/*tp_subclasses*/
 	0,					/*tp_weaklist*/
 	0,					/*tp_del*/
+#if PY_VERSION_HEX >= 0x020600F0 /* Added in version 2.6 */
 	0					/*tp_version_tag*/
+#endif
 };

=== modified file 'src/liblzma_util.c'
--- src/liblzma_util.c	2010-01-13 08:28:17 +0000
+++ src/liblzma_util.c	2010-08-05 12:59:26 +0000
@@ -13,7 +13,11 @@
 			break;
 
 		case LZMA_NO_CHECK:
+#if PY_VERSION_HEX >= 0x020500F0
 			PyErr_WarnEx(LZMAError, "stream has no integrity check", 1);
+#else
+			PyErr_Warn(LZMAError, "stream has no integrity check");
+#endif
 			break;
 
 		case LZMA_UNSUPPORTED_CHECK:

=== modified file 'tests/test_liblzma.py'
--- tests/test_liblzma.py	2010-04-13 20:29:41 +0000
+++ tests/test_liblzma.py	2010-08-05 12:59:26 +0000
@@ -29,7 +29,10 @@
 import os
 from test.test_support import TESTFN
 
-from hashlib import md5
+try:
+    from hashlib import md5
+except ImportError:
+    from md5 import md5
 from binascii import unhexlify, hexlify
 from cStringIO import StringIO
 from StringIO import StringIO as PyStringIO
@@ -606,7 +609,7 @@
     # checksum test cases
     def test_crc32start(self):
         self.assertEqual(lzma.crc32(""), lzma.crc32("", 0))
-        self.assert_(lzma.crc32("abc", 0xffffffff))
+        self.assert_(lzma.crc32("abc", 0xffffffffL))
 
     def test_crc32empty(self):
         self.assertEqual(lzma.crc32("", 0), 0)
@@ -627,7 +630,7 @@
     # These crc64 tests needs to be reviewed..
     def test_crc64start(self):
         self.assertEqual(lzma.crc64(""), lzma.crc64("", 0))
-        self.assert_(lzma.crc64("abc", 0xffffffff))
+        self.assert_(lzma.crc64("abc", 0xffffffffL))
 
     def test_crc64empty(self):
         self.assertEqual(lzma.crc64("", 0), 0)

