From 727ce0d3d34e9786b452b57e75de07d6dc00214e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=9B=9B?= <42721712+L4cache@users.noreply.github.com> Date: Wed, 27 Sep 2023 04:43:16 +0800 Subject: [PATCH] Expression as piece length? --- torrentfile/utils.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/torrentfile/utils.py b/torrentfile/utils.py index d95cbd2..b2fd8f5 100644 --- a/torrentfile/utils.py +++ b/torrentfile/utils.py @@ -25,6 +25,7 @@ import ctypes import shutil import platform +import re from pathlib import Path if platform.system() == "Windows": # pragma: nocover @@ -175,7 +176,12 @@ def normalize_piece_length(piece_length: int) -> int: if piece_length.isnumeric(): piece_length = int(piece_length) else: - raise PieceLengthValueError(piece_length) + try: + if re.search('[0-9*<]*(.*)',piece_length).group(1): + raise PieceLengthValueError(piece_length) + piece_length = int(eval(piece_length)) + except: + raise PieceLengthValueError(piece_length) if piece_length > (1 << 14): if 2**math.log2(piece_length) == piece_length: