From c73cf5c5d0f15c0c3460acdb4463aa2d3ecf1fb5 Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Sat, 11 Jan 2025 15:23:53 +0300 Subject: [PATCH] mc: Include `eff_bdecode.py` into the code --- eff_bdecode.py | 78 -------------------------------------- torrent | 92 ++++++++++++++++++++++++++++++++++++++++++--- torrent-ANNOUNCE | 31 ++------------- torrent-ANNOUNCE-ru | 2 +- torrent-ChangeLog | 4 ++ 5 files changed, 94 insertions(+), 113 deletions(-) delete mode 100644 eff_bdecode.py diff --git a/eff_bdecode.py b/eff_bdecode.py deleted file mode 100644 index 2f8fc5e..0000000 --- a/eff_bdecode.py +++ /dev/null @@ -1,78 +0,0 @@ -# http://effbot.org/zone/bencode.htm -# http://effbot.org/zone/copyright.htm -# -# Copyright (C) 1995-2013 by Fredrik Lundh -# -# By obtaining, using, and/or copying this software and/or its associated -# documentation, you agree that you have read, understood, and will comply with -# the following terms and conditions: -# -# Permission to use, copy, modify, and distribute this software and its -# associated documentation for any purpose and without fee is hereby granted, -# provided that the above copyright notice appears in all copies, and that both -# that copyright notice and this permission notice appear in supporting -# documentation, and that the name of Secret Labs AB or the author not be used -# in advertising or publicity pertaining to distribution of the software -# without specific, written prior permission. -# -# SECRET LABS AB AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS -# SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN -# NO EVENT SHALL SECRET LABS AB OR THE AUTHOR BE LIABLE FOR ANY SPECIAL, -# INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM -# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR -# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -# PERFORMANCE OF THIS SOFTWARE. - -from functools import partial -import re - - -def tokenize(text, match=re.compile(b"([idel])|(\\d+):|(-?\\d+)").match): - i = 0 - while i < len(text): - m = match(text, i) - s = m.group(m.lastindex) - i = m.end() - if m.lastindex == 2: - yield "s" - yield text[i:i+int(s)] - i = i + int(s) - else: - yield s.decode('ascii') - - -def decode_item(next_, token): - if token == "i": - # integer: "i" value "e" - data = int(next_()) - if next_() != "e": - raise ValueError - elif token == "s": - # string: "s" value (virtual tokens) - data = next_() - elif token == "l" or token == "d": - # container: "l" (or "d") values "e" - data = [] - tok = next_() - while tok != "e": - data.append(decode_item(next_, tok)) - try: - tok = next_() - except StopIteration: - break - if token == "d": - data = dict(zip(data[0::2], data[1::2])) - else: - raise ValueError - return data - - -def decode(text): - try: - src = tokenize(text) - data = decode_item(partial(next, src), next(src)) - for token in src: # look for more tokens - raise SyntaxError("trailing junk") - except (AttributeError, ValueError, StopIteration): - raise SyntaxError("syntax error") - return data diff --git a/torrent b/torrent index a0f827e..466da30 100755 --- a/torrent +++ b/torrent @@ -2,8 +2,9 @@ """Torrent Virtual FileSystem for Midnight Commander The script requires Midnight Commander 3.1+ -(http://www.midnight-commander.org/), Python 2.4+ (http://www.python.org/), -module eff_bdecode.py (http://effbot.org/zone/bencode.htm). +(http://www.midnight-commander.org/), Python 2.7+ (http://www.python.org/), +module eff_bdecode.py (from effbot.org/zone/bencode.htm) is now included +in the code. For mc 4.7+ just put the script in $HOME/[.local/share/].mc/extfs.d. For older versions put it in /usr/[local/][lib|share]/mc/extfs @@ -35,9 +36,9 @@ The filesystem is, naturally, read-only. """ -__version__ = "1.3.1" +__version__ = "1.4.0" __author__ = "Oleg Broytman " -__copyright__ = "Copyright (C) 2010-2023 PhiloSoft Design" +__copyright__ = "Copyright (C) 2010-2025 PhiloSoft Design" __license__ = "GPL" @@ -45,7 +46,6 @@ from datetime import datetime from os.path import dirname, getmtime import sys from time import localtime, asctime -from eff_bdecode import decode try: import locale @@ -102,6 +102,86 @@ else: def output(s): sys.stdout.write(s + '\n') +# ---------- eff_bdecode.py ---------- +# effbot.org/zone/bencode.htm +# +# Copyright (C) 1995-2013 by Fredrik Lundh +# +# By obtaining, using, and/or copying this software and/or its associated +# documentation, you agree that you have read, understood, and will comply with +# the following terms and conditions: +# +# Permission to use, copy, modify, and distribute this software and its +# associated documentation for any purpose and without fee is hereby granted, +# provided that the above copyright notice appears in all copies, and that both +# that copyright notice and this permission notice appear in supporting +# documentation, and that the name of Secret Labs AB or the author not be used +# in advertising or publicity pertaining to distribution of the software +# without specific, written prior permission. +# +# SECRET LABS AB AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS +# SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN +# NO EVENT SHALL SECRET LABS AB OR THE AUTHOR BE LIABLE FOR ANY SPECIAL, +# INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +# PERFORMANCE OF THIS SOFTWARE. + +from functools import partial +import re + + +def tokenize(text, match=re.compile(b"([idel])|(\\d+):|(-?\\d+)").match): + i = 0 + while i < len(text): + m = match(text, i) + s = m.group(m.lastindex) + i = m.end() + if m.lastindex == 2: + yield "s" + yield text[i:i+int(s)] + i = i + int(s) + else: + yield s.decode('ascii') + + +def decode_item(next_, token): + if token == "i": + # integer: "i" value "e" + data = int(next_()) + if next_() != "e": + raise ValueError + elif token == "s": + # string: "s" value (virtual tokens) + data = next_() + elif token == "l" or token == "d": + # container: "l" (or "d") values "e" + data = [] + tok = next_() + while tok != "e": + data.append(decode_item(next_, tok)) + try: + tok = next_() + except StopIteration: + break + if token == "d": + data = dict(zip(data[0::2], data[1::2])) + else: + raise ValueError + return data + + +def eff_bdecode(text): + try: + src = tokenize(text) + data = decode_item(partial(next, src), next(src)) + for token in src: # look for more tokens + raise SyntaxError("trailing junk") + except (AttributeError, ValueError, StopIteration): + raise SyntaxError("syntax error") + return data +# ---------- /eff_bdecode.py ---------- + def mctorrent_list(): """List the entire VFS""" @@ -302,7 +382,7 @@ def decode_torrent(): torrent_file = open(sys.argv[2], 'rb') data = torrent_file.read() torrent_file.close() - torrent = decode(data) + torrent = eff_bdecode(data) except IOError as error_str: torrent_error(error_str) diff --git a/torrent-ANNOUNCE b/torrent-ANNOUNCE index 11644f0..c99a7e8 100644 --- a/torrent-ANNOUNCE +++ b/torrent-ANNOUNCE @@ -7,35 +7,10 @@ Midnight Commander. WHAT'S NEW -Version 1.2.4 (2018-05-18) - Fix a bug in handling overflow with dates > 2038 year. -Version 1.2.3 (2015-07-08) - Set directories/files date/time to the content of ".META/creation date" file -if it exists or to the last modification time of the torrent file itself. +Version 1.4.0 (2025-01-11) -Version 1.2.2 (2015-01-10) - Changed link to installation instructions. - -Version 1.2.1 (2013-11-20) - Fixed a minor bug. - -Version 1.2.0 (2013-11-16) - Get charset from the environment. - -Version 1.1.1 (2013-11-11) - Documented the fact that the script can be put in -$HOME/[.local/share/].mc/extfs.d. - -Version 1.1.0 (2013-06-10) - Show DHT nodes if they are present. - Show publisher and publisher-url if they are available. - Use name.utf-8, path.utf-8 and comment.utf-8 if those are available. - Use codepage instead of encoding if codepage is available - and encoding is not. - -Version 1.0.0 (2010-11-11) - Initial release. + Include eff_bdecode.py into the code. WHERE TO GET @@ -68,7 +43,7 @@ AUTHOR Oleg Broytman COPYRIGHT - Copyright (C) 2010-2015 PhiloSoft Design + Copyright (C) 2010-2025 PhiloSoft Design LICENSE GPL diff --git a/torrent-ANNOUNCE-ru b/torrent-ANNOUNCE-ru index 556ba4b..4aef1fe 100644 --- a/torrent-ANNOUNCE-ru +++ b/torrent-ANNOUNCE-ru @@ -37,7 +37,7 @@ date', если оно существует; если такого поля не Олег Бройтман COPYRIGHT - Copyright (C) 2010-2015 PhiloSoft Design + Copyright (C) 2010-2025 PhiloSoft Design ЛИЦЕНЗИЯ GPL diff --git a/torrent-ChangeLog b/torrent-ChangeLog index 3c4b8e7..7337285 100644 --- a/torrent-ChangeLog +++ b/torrent-ChangeLog @@ -1,3 +1,7 @@ +Version 1.4.0 (2025-01-11) + + Include eff_bdecode.py into the code. + Version 1.3.1 (2023-08-13) Update for Python 3. -- 2.39.5