diff options
| author | Adam Hupp <adam@hupp.org> | 2013-09-27 08:41:05 -0700 |
|---|---|---|
| committer | Adam Hupp <adam@hupp.org> | 2013-09-27 08:45:22 -0700 |
| commit | 20e713777b8a005bcb81ae7e29db8735a9dbc054 (patch) | |
| tree | b60abd04e1ed5ce13c35b9bca3f322deb4488d46 | |
| parent | ea8b2d5b7949463b161c2f7d1db6d71456940a56 (diff) | |
| download | python-magic-20e713777b8a005bcb81ae7e29db8735a9dbc054.tar.gz | |
Use python 2.4-compatible threading.currentThread() call
| -rw-r--r-- | magic.py | 4 | ||||
| -rw-r--r-- | test.py | 26 |
2 files changed, 17 insertions, 13 deletions
@@ -52,7 +52,7 @@ class Magic: magic_load(self.cookie, magic_file) - self.thread = threading.current_thread() + self.thread = threading.currentThread() def from_buffer(self, buf): """ @@ -73,7 +73,7 @@ class Magic: return magic_file(self.cookie, filename) def _thread_check(self): - if self.thread != threading.current_thread(): + if self.thread != threading.currentThread(): raise Exception('attempting to use libmagic on multiple threads will ' 'end in SEGV. Prefer to use the module functions ' 'from_file or from_buffer, or carefully manage direct ' @@ -7,16 +7,16 @@ from os import path testfile = [ - ("magic.pyc", b"python 2.4 byte-compiled", b"application/octet-stream"), - ("test.pdf", b"PDF document, version 1.2", b"application/pdf"), - ("test.gz", b'gzip compressed data, was "test", from Unix, last modified: ' - b'Sat Jun 28 18:32:52 2008', b"application/x-gzip"), - ("text.txt", b"ASCII text", b"text/plain"), + ("magic.pyc", "python 2.4 byte-compiled", "application/octet-stream"), + ("test.pdf", "PDF document, version 1.2", "application/pdf"), + ("test.gz", 'gzip compressed data, was "test", from Unix, last modified: ' + 'Sat Jun 28 18:32:52 2008', "application/x-gzip"), + ("text.txt", "ASCII text", "text/plain"), # is there no better way to encode a unicode literal across python2/3.[01]/3.3? - (b"\xce\xbb".decode('utf-8'), b"empty", b"application/x-empty") + ("\xce\xbb".decode('utf-8'), "empty", "application/x-empty") ] -testFileEncoding = [('text-iso8859-1.txt', b'iso-8859-1')] +testFileEncoding = [('text-iso8859-1.txt', 'iso-8859-1')] class TestMagic(unittest.TestCase): @@ -36,11 +36,15 @@ class TestMagic(unittest.TestCase): target = desc snippet = open(filename, 'rb').read(1024) - self.assertEqual(target, self.m.from_buffer(snippet)) - self.assertEqual(target, self.m.from_file(filename), filename) + + # do this rather than b"" literals since those aren't supported in 2.4 + target_bytes = target.encode('utf-8') + self.assertEqual(target_bytes, self.m.from_buffer(snippet)) + self.assertEqual(target_bytes, self.m.from_file(filename), filename) - self.assertEqual(target, magic.from_buffer(snippet, mime=self.mime)) - self.assertEqual(target, magic.from_file(filename, mime=self.mime), filename) + self.assertEqual(target_bytes, magic.from_buffer(snippet, mime=self.mime)) + self.assertEqual(target_bytes, magic.from_file(filename, mime=self.mime), + filename) def testErrors(self): |
