diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index cd68817..0000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,103 +0,0 @@ -# Changelog - -All notable changes to this project will be documented in this file. - -The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) -and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). - -## [0.3.0] - 2018.06.23 - -### Added - -- Add `errors` option in `TorrentFileParser` and `parse_torrent_file` to let user set the encoding error handler. (Thanks [@yasuotakei]) -- Add `-e`/`--error` to CLI option to set the `errors` option of `parse_torrent_file`. -- `BDecoder` class and `decode` shortcut function to directly decode bytes. -- `decode` shortcut function to directly encode data to bytes. -- Added `hash_fields` parameter and method to customize hash field list. -- Added `hash_raw` parameter to let all hash field be parsed as raw bytes. - -### Changed - -- **BreakChange** `TorrentFileCreator` rename to `BEncoder` as the origin name don't describe its function. -- `TorrentFileParser` don't need the outmost level of parsed data to be a `dict` now. -- `BEncoder` don't need the outmost level of encoded data to be a `dict` now. -- `BEncoder` now support encode raw bytes. - -## [0.2.0] - 2018.5.25 - -### Change - -- Just bump version to 0.2.0 to follow semver. - -## [0.1.5rc1] - 2018.4.28 - -### Added - -- `TorrentFileCreator` class and `create_torrent_file` shortcut function for write back data to a torrent file. - -## [0.1.4] - 2018-04-06 - -### Added - -- `encoding` option can be `auto`, which will use `chardet` package to decide which encoding to use. If `chardet` is noe installed, will raise a warning and fallback to 'utf-8'. (Thanks to [@ltfychrise]) -- Add changelog. - -### Change - -- Reorganize test codes/files. - -### Fixed - -- Fix integer filed can't be negative bug. (Thanks to [@ltfychrise]) -- Fix `_seek_back` method not make `_pos` back bug. (Thanks to [@ltfychrise]) - -## [0.1.3] - 2017-06-21 - -### Added - -- Now `UnicodeDecodeError` is wrapped in `InvalidTorrentDataException`. - -### Fixed - -- Use `IOError` instead of `FileNotFoundError` in Python 2. - -### Changed - -- `InvalidTorrentFileException` rename to `InvalidTorrentDataException`. - -## [0.1.2] - 2017-06-21 - -### Changed - -- Emm, I don't know, I just changed the version code... - -## [0.1.1] - 2017-06-20 - -### Added - -- CLI add coding `--coding/-c` option for file string filed encoding. - -### Changed - -- `ed2k` and `filehash` field now use same structure as 'pieces'. - -## [0.1.0] - 2017-05-23 - -### Added - -- Parse torrent from file and data into a dict. -- CLI provided. -- Simple tests. -- Available on pip. - -[@ltfychrise]: https://github.com/ltfychrise -[@yasuotakei]: https://github.com/yasuotakei -[Unreleased]: https://github.com/7sDream/torrent_parser/compare/v0.3.0...HEAD -[0.3.0]: https://github.com/7sDream/torrent_parser/compare/v0.2.0...v0.3.0 -[0.2.0]: https://github.com/7sDream/torrent_parser/compare/v0.1.5rc1...v0.2.0 -[0.1.5rc1]: https://github.com/7sDream/torrent_parser/compare/v0.1.4...v0.1.5rc1 -[0.1.4]: https://github.com/7sDream/torrent_parser/compare/v0.1.3...v0.1.4 -[0.1.3]: https://github.com/7sDream/torrent_parser/compare/v0.1.2...v0.1.3 -[0.1.2]: https://github.com/7sDream/torrent_parser/compare/v0.1.1...v0.1.2 -[0.1.1]: https://github.com/7sDream/torrent_parser/compare/v0.1.0...v0.1.1 -[0.1.0]: https://github.com/7sDream/torrent_parser/tree/v0.1.0 diff --git a/MANIFEST.in b/MANIFEST.in deleted file mode 100644 index e2e577a..0000000 --- a/MANIFEST.in +++ /dev/null @@ -1 +0,0 @@ -include README.md LICENSE CHANGELOG.md diff --git a/addon.xml b/addon.xml new file mode 100644 index 0000000..323eeb1 --- /dev/null +++ b/addon.xml @@ -0,0 +1,17 @@ + + + + + + + + + all + en_GB ru_RU + Torrent file parser and creator for Python + Обработка и создание файлов .torrent + Разработан 7sDream (https://github.com/7sDream/torrent_parser) + Developed by 7sDream (https://github.com/7sDream/torrent_parser) + roman@ukamnya.ru + https://git.ukamnya.ru/roman/script.module.torrent_parser + diff --git a/torrent_parser.py b/lib/torrent_parser.py similarity index 100% rename from torrent_parser.py rename to lib/torrent_parser.py diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index d5df43f..0000000 --- a/setup.cfg +++ /dev/null @@ -1,6 +0,0 @@ -[metadata] -description-file = README.md -license-file = LICENSE - -[bdist_wheel] -universal = 1 diff --git a/setup.py b/setup.py deleted file mode 100755 index 2dc33dd..0000000 --- a/setup.py +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/env python -# coding=utf-8 - -try: - from setuptools import setup -except ImportError: - from distutils.core import setup - -import torrent_parser - -setup( - name='torrent_parser', - keywords=['file', 'torrent', 'JSON', 'parser'], - version=torrent_parser.__version__, - py_modules=['torrent_parser'], - url='https://github.com/7sDream/torrent_parser', - license='MIT', - author='7sDream', - author_email='7seconddream@gmail.com', - description='A .torrent file parser and creator for both Python 2 and 3', - install_requires=[], - entry_points={ - 'console_scripts': ['pytp=torrent_parser:__main'] - }, - classifiers=[ - 'Development Status :: 3 - Alpha', - 'Environment :: Console', - 'Intended Audience :: Developers', - 'Intended Audience :: End Users/Desktop', - 'License :: OSI Approved :: MIT License', - 'Natural Language :: English', - 'Operating System :: OS Independent', - 'Programming Language :: Python', - 'Programming Language :: Python :: 2.7', - 'Programming Language :: Python :: 3.5', - 'Programming Language :: Python :: 3.6', - 'Topic :: Multimedia', - 'Topic :: Software Development :: Libraries :: Python Modules', - 'Topic :: Utilities', - ] -) diff --git a/tests/__init__.py b/tests/__init__.py deleted file mode 100644 index 4e7bb8c..0000000 --- a/tests/__init__.py +++ /dev/null @@ -1,7 +0,0 @@ -from .test_create import * -from .test_parse import * -from .test_encoding_error import * -from .test_encode import * -from .test_decode import * -from .test_hash_field import * -from .test_hash_raw import * \ No newline at end of file diff --git a/tests/test_create.py b/tests/test_create.py deleted file mode 100644 index d051505..0000000 --- a/tests/test_create.py +++ /dev/null @@ -1,35 +0,0 @@ -from __future__ import unicode_literals - -import collections -import hashlib -import io -import os.path -import unittest - -from torrent_parser import TorrentFileParser, BEncoder - - -class TestCreate(unittest.TestCase): - TEST_FILES_DIR = os.path.join(os.path.dirname(__file__), 'test_files') - REAL_FILE = os.path.join(TEST_FILES_DIR, 'real.torrent') - - def test_simple_create(self): - data = collections.OrderedDict() - data['a'] = 1 - data['b'] = 2 - self.assertEqual(BEncoder(data).encode(), b'd1:ai1e1:bi2ee') - - def test_same_output_if_no_edit(self): - with open(self.REAL_FILE, 'rb') as fp: - in_data = fp.read() - data = TorrentFileParser(io.BytesIO(in_data), True).parse() - out_data = BEncoder(data).encode() - m1 = hashlib.md5() - m1.update(in_data) - m2 = hashlib.md5() - m2.update(out_data) - self.assertEqual(m1.digest(), m2.digest()) - - def test_dont_need_dict_outmost(self): - data = 123456 - self.assertEqual(BEncoder(data).encode(), b'i123456e') diff --git a/tests/test_decode.py b/tests/test_decode.py deleted file mode 100644 index 4257277..0000000 --- a/tests/test_decode.py +++ /dev/null @@ -1,11 +0,0 @@ -from __future__ import unicode_literals - -import unittest - -from torrent_parser import decode - - -class TestDecode(unittest.TestCase): - - def test_decode(self): - self.assertEqual(decode(b'i12345e'), 12345) diff --git a/tests/test_encode.py b/tests/test_encode.py deleted file mode 100644 index 7914bac..0000000 --- a/tests/test_encode.py +++ /dev/null @@ -1,11 +0,0 @@ -from __future__ import unicode_literals - -import unittest - -from torrent_parser import encode - - -class TestEncode(unittest.TestCase): - - def test_encode(self): - self.assertEqual(encode(12345), b'i12345e') diff --git a/tests/test_encoding_error.py b/tests/test_encoding_error.py deleted file mode 100644 index a95a950..0000000 --- a/tests/test_encoding_error.py +++ /dev/null @@ -1,25 +0,0 @@ -from __future__ import unicode_literals - -import os.path -import unittest - -from torrent_parser import ( - TorrentFileParser, parse_torrent_file, InvalidTorrentDataException -) - - -class TestDecodingError(unittest.TestCase): - TEST_FILES_DIR = os.path.join(os.path.dirname(__file__), 'test_files') - FILE = os.path.join(TEST_FILES_DIR, 'utf8.encoding.error.torrent') - - def test_default_option_will_raise_exception(self): - with self.assertRaises(InvalidTorrentDataException): - parse_torrent_file(self.FILE) - with self.assertRaises(InvalidTorrentDataException): - with open(self.FILE, 'rb') as f: - TorrentFileParser(f).parse() - - def test_not_raise_exception_when_use_ignore(self): - parse_torrent_file(self.FILE, errors='ignore') - with open(self.FILE, 'rb') as f: - TorrentFileParser(f, errors='ignore').parse() diff --git a/tests/test_files/neg.torrent b/tests/test_files/neg.torrent deleted file mode 100644 index 3da5fb1..0000000 --- a/tests/test_files/neg.torrent +++ /dev/null @@ -1 +0,0 @@ -d3:negi-1ee \ No newline at end of file diff --git a/tests/test_files/outmost.string.torrent b/tests/test_files/outmost.string.torrent deleted file mode 100644 index d15055f..0000000 --- a/tests/test_files/outmost.string.torrent +++ /dev/null @@ -1 +0,0 @@ -8:announce \ No newline at end of file diff --git a/tests/test_files/real.torrent b/tests/test_files/real.torrent deleted file mode 100644 index 1343392..0000000 Binary files a/tests/test_files/real.torrent and /dev/null differ diff --git a/tests/test_files/utf8.encoding.error.torrent b/tests/test_files/utf8.encoding.error.torrent deleted file mode 100644 index 3f159d3..0000000 Binary files a/tests/test_files/utf8.encoding.error.torrent and /dev/null differ diff --git a/tests/test_hash_field.py b/tests/test_hash_field.py deleted file mode 100644 index a7c1e17..0000000 --- a/tests/test_hash_field.py +++ /dev/null @@ -1,21 +0,0 @@ -from __future__ import unicode_literals - -import os.path -import unittest - -from torrent_parser import ( - TorrentFileParser, parse_torrent_file, decode -) - - -class TestHashField(unittest.TestCase): - TEST_FILES_DIR = os.path.join(os.path.dirname(__file__), 'test_files') - FILE = os.path.join(TEST_FILES_DIR, 'utf8.encoding.error.torrent') - - def test_not_raise_exception_when_add_hash_fields(self): - parse_torrent_file(self.FILE, hash_fields={'info_hash': (20, False)}) - with open(self.FILE, 'rb') as f: - TorrentFileParser(f).hash_field('info_hash').parse() - with open(self.FILE, 'rb') as f: - data = f.read() - decode(data, hash_fields={'info_hash': (20, False)}) diff --git a/tests/test_hash_raw.py b/tests/test_hash_raw.py deleted file mode 100644 index f6b19b9..0000000 --- a/tests/test_hash_raw.py +++ /dev/null @@ -1,23 +0,0 @@ -from __future__ import unicode_literals - -import os.path -import unittest - -from torrent_parser import decode, encode - - -class TestHashRaw(unittest.TestCase): - TEST_FILES_DIR = os.path.join(os.path.dirname(__file__), 'test_files') - FILE = os.path.join(TEST_FILES_DIR, 'utf8.encoding.error.torrent') - - def test_hash_raw_decode(self): - data = b'd4:hash4:\xAA\xBB\xCC\xDDe' - res = decode(data, hash_fields={'hash': (4, False)}, hash_raw=False) - self.assertEqual(res['hash'], 'aabbccdd') - res = decode(data, hash_fields={'hash': (4, False)}, hash_raw=True) - self.assertEqual(res['hash'], b'\xAA\xBB\xCC\xDD') - - def test_raw_bytes_encode(self): - res = {'hash': b'\xAA\xBB\xCC\xDD'} - data = encode(res) - self.assertEqual(data, b'd4:hash4:\xAA\xBB\xCC\xDDe') diff --git a/tests/test_parse.py b/tests/test_parse.py deleted file mode 100644 index 80962b5..0000000 --- a/tests/test_parse.py +++ /dev/null @@ -1,63 +0,0 @@ -from __future__ import unicode_literals - -import collections -import os.path -import unittest - -from torrent_parser import TorrentFileParser, parse_torrent_file - - -class TestParse(unittest.TestCase): - TEST_FILES_DIR = os.path.join(os.path.dirname(__file__), 'test_files') - REAL_FILE = os.path.join(TEST_FILES_DIR, 'real.torrent') - NEG_FILE = os.path.join(TEST_FILES_DIR, 'neg.torrent') - STRING_FILE = os.path.join(TEST_FILES_DIR, 'outmost.string.torrent') - - def test_parse_torrent_file_use_shortcut(self): - parse_torrent_file(self.REAL_FILE) - - def test_parse_torrent_file_use_class(self): - with open(self.REAL_FILE, 'rb') as fp: - TorrentFileParser(fp).parse() - - def test_encoding_auto(self): - with open(self.REAL_FILE, 'rb') as fp: - TorrentFileParser(fp, encoding='auto').parse() - - def test_parse_torrent_file_to_ordered_dict(self): - data = parse_torrent_file(self.REAL_FILE, True) - self.assertIsInstance(data, collections.OrderedDict) - - with open(self.REAL_FILE, 'rb') as fp: - data = TorrentFileParser(fp, True).parse() - self.assertIsInstance(data, collections.OrderedDict) - - def test_parse_correctness(self): - data = parse_torrent_file(self.REAL_FILE) - self.assertIn(['udp://tracker.publicbt.com:80/announce'], - data['announce-list']) - self.assertEqual(data['creation date'], 1409254242) - - def test_parse_two_times(self): - with open(self.REAL_FILE, 'rb') as fp: - parser = TorrentFileParser(fp) - data = parser.parse() - self.assertIn(['udp://tracker.publicbt.com:80/announce'], - data['announce-list']) - self.assertEqual(data['creation date'], 1409254242) - data = parser.parse() - self.assertIn(['udp://tracker.publicbt.com:80/announce'], - data['announce-list']) - self.assertEqual(data['creation date'], 1409254242) - - def test_int_is_negative(self): - data = parse_torrent_file(self.NEG_FILE) - self.assertEqual(data['neg'], -1) - - def test_dont_need_dict_outmost(self): - data = parse_torrent_file(self.STRING_FILE) - self.assertEqual(data, 'announce') - - -if __name__ == '__main__': - unittest.main()