mirror of
https://github.com/gryf/gryf-overlay.git
synced 2025-12-18 12:00:26 +01:00
Added workaround for tuir with mailcap module missing in Python 3.13
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
AUX tuir-config.patch 1107 BLAKE2B 3eb93f1747a61b7362a54dd3c9425d7b40e64162dd4aad5f4d68265f3b398e6039d18c63a6b4cf6c9deb4f5ac87a1954a419982c7080c784ae2b4b608fef1283 SHA512 0bcbdf8839d6f64df7db3f50ad15305aba96ce948bd87ea4cab4cf4ec48959fc0166b68b814e39b3caf0712fafbafd0d85effd1dd18b6b5367b7da2b867f6cd4
|
||||
AUX tuir-mailcap_fix_for_py313.patch 10024 BLAKE2B dd71c305aa5c862443ff36b7ac5d8ec2e97a8b4db6a5686981ae6d15638bd7d04ed9c8bc9f3a2fced13ca14e6ca583c2689c8f18d61058c64f965ca970028d69 SHA512 2501f7701d5d49c67456a214b2c233db9a761ffa00f7ea055316d527d93e4418c39beb68c752dea371de334f6a3807069e97e889def6d8649f13e03d33336dda
|
||||
DIST tuir-v1.29.0.tar.bz2 17261008 BLAKE2B bbd621c4ccbd1f257eb14956c225e1a2dc3fb594a91cf739deb32ee67b2c6c823eb8d6ec190a941384b3e230f2afd7747be26cea6f0d98edb7e4b80d2acf02a5 SHA512 a95834e569e6c4d8327ac8e7a4aa69ed47fbd2e82d7bc80f74a2f20b26ddd2ee3f4b00179c8df5ad1917f44f9c20ee39ff04189b9179b583722d6f53a15fd2b5
|
||||
EBUILD tuir-1.29.0.ebuild 640 BLAKE2B 145707edef5789e4cf8937536b90d10837b0985fadc686fb49f6f63e456685c71da9bb95b3401e00acefdac9e8ad06366fcea22415a8ee09f9f40219eb295ed7 SHA512 7ac4a080c24d0a381366c6f36ad224645a846fbf22d9c9d6dd90d8f510cea229131255a54d191b992cdca7535268b63939c6d218394836a6f3540a5be8c7388e
|
||||
EBUILD tuir-1.29.0.ebuild 690 BLAKE2B e3d63e27dbb92f4d5ccca92b57a54bca8e485fcbb3cc54d15f12d744cf24b5720dfb450071032dfe52f1555391182cc07d01af26de11f7b5acea05ca38bc68c7 SHA512 579cb2ad0921af1eaf4c3821046b42f1865f3f5e4bb8c7da72307bfeca499b2eacf54e9fb9b2e13cd2aef58987cb06b2f52cfa316e25b4b44a9aa7e56845f5a5
|
||||
|
||||
321
net-news/tuir/files/tuir-mailcap_fix_for_py313.patch
Normal file
321
net-news/tuir/files/tuir-mailcap_fix_for_py313.patch
Normal file
@@ -0,0 +1,321 @@
|
||||
diff --git a/tuir/mailcap.py b/tuir/mailcap.py
|
||||
new file mode 100644
|
||||
index 0000000..a5060d8
|
||||
--- /dev/null
|
||||
+++ b/tuir/mailcap.py
|
||||
@@ -0,0 +1,299 @@
|
||||
+"""Mailcap file handling. See RFC 1524."""
|
||||
+
|
||||
+import os
|
||||
+import re
|
||||
+import warnings
|
||||
+
|
||||
+__all__ = ["getcaps","findmatch"]
|
||||
+
|
||||
+
|
||||
+def lineno_sort_key(entry):
|
||||
+ # Sort in ascending order, with unspecified entries at the end
|
||||
+ if 'lineno' in entry:
|
||||
+ return 0, entry['lineno']
|
||||
+ return 1, 0
|
||||
+
|
||||
+_find_unsafe = re.compile(r'[^\xa1-\U0010FFFF\w@+=:,./-]').search
|
||||
+
|
||||
+class UnsafeMailcapInput(Warning):
|
||||
+ """Warning raised when refusing unsafe input"""
|
||||
+
|
||||
+
|
||||
+# Part 1: top-level interface.
|
||||
+
|
||||
+def getcaps():
|
||||
+ """Return a dictionary containing the mailcap database.
|
||||
+
|
||||
+ The dictionary maps a MIME type (in all lowercase, e.g. 'text/plain')
|
||||
+ to a list of dictionaries corresponding to mailcap entries. The list
|
||||
+ collects all the entries for that MIME type from all available mailcap
|
||||
+ files. Each dictionary contains key-value pairs for that MIME type,
|
||||
+ where the viewing command is stored with the key "view".
|
||||
+
|
||||
+ """
|
||||
+ caps = {}
|
||||
+ lineno = 0
|
||||
+ for mailcap in listmailcapfiles():
|
||||
+ try:
|
||||
+ with open(mailcap, 'r') as fp:
|
||||
+ morecaps, lineno = _readmailcapfile(fp, lineno)
|
||||
+ except OSError:
|
||||
+ continue
|
||||
+
|
||||
+ for key, value in morecaps.items():
|
||||
+ if key not in caps:
|
||||
+ caps[key] = value
|
||||
+ else:
|
||||
+ caps[key] = caps[key] + value
|
||||
+ return caps
|
||||
+
|
||||
+def listmailcapfiles():
|
||||
+ """Return a list of all mailcap files found on the system."""
|
||||
+ # This is mostly a Unix thing, but we use the OS path separator anyway
|
||||
+ if 'MAILCAPS' in os.environ:
|
||||
+ pathstr = os.environ['MAILCAPS']
|
||||
+ mailcaps = pathstr.split(os.pathsep)
|
||||
+ else:
|
||||
+ if 'HOME' in os.environ:
|
||||
+ home = os.environ['HOME']
|
||||
+ else:
|
||||
+ # Don't bother with getpwuid()
|
||||
+ home = '.' # Last resort
|
||||
+ mailcaps = [home + '/.mailcap', '/etc/mailcap',
|
||||
+ '/usr/etc/mailcap', '/usr/local/etc/mailcap']
|
||||
+ return mailcaps
|
||||
+
|
||||
+
|
||||
+# Part 2: the parser.
|
||||
+def readmailcapfile(fp):
|
||||
+ """Read a mailcap file and return a dictionary keyed by MIME type."""
|
||||
+ caps, _ = _readmailcapfile(fp, None)
|
||||
+ return caps
|
||||
+
|
||||
+
|
||||
+def _readmailcapfile(fp, lineno):
|
||||
+ """Read a mailcap file and return a dictionary keyed by MIME type.
|
||||
+
|
||||
+ Each MIME type is mapped to an entry consisting of a list of
|
||||
+ dictionaries; the list will contain more than one such dictionary
|
||||
+ if a given MIME type appears more than once in the mailcap file.
|
||||
+ Each dictionary contains key-value pairs for that MIME type, where
|
||||
+ the viewing command is stored with the key "view".
|
||||
+ """
|
||||
+ caps = {}
|
||||
+ while line := fp.readline():
|
||||
+ # Ignore comments and blank lines
|
||||
+ if line[0] == '#' or line.strip() == '':
|
||||
+ continue
|
||||
+ nextline = line
|
||||
+ # Join continuation lines
|
||||
+ while nextline[-2:] == '\\\n':
|
||||
+ nextline = fp.readline()
|
||||
+ if not nextline:
|
||||
+ nextline = '\n'
|
||||
+ line = line[:-2] + nextline
|
||||
+ # Parse the line
|
||||
+ key, fields = parseline(line)
|
||||
+ if not (key and fields):
|
||||
+ continue
|
||||
+ if lineno is not None:
|
||||
+ fields['lineno'] = lineno
|
||||
+ lineno += 1
|
||||
+ # Normalize the key
|
||||
+ types = key.split('/')
|
||||
+ for j in range(len(types)):
|
||||
+ types[j] = types[j].strip()
|
||||
+ key = '/'.join(types).lower()
|
||||
+ # Update the database
|
||||
+ if key in caps:
|
||||
+ caps[key].append(fields)
|
||||
+ else:
|
||||
+ caps[key] = [fields]
|
||||
+ return caps, lineno
|
||||
+
|
||||
+def parseline(line):
|
||||
+ """Parse one entry in a mailcap file and return a dictionary.
|
||||
+
|
||||
+ The viewing command is stored as the value with the key "view",
|
||||
+ and the rest of the fields produce key-value pairs in the dict.
|
||||
+ """
|
||||
+ fields = []
|
||||
+ i, n = 0, len(line)
|
||||
+ while i < n:
|
||||
+ field, i = parsefield(line, i, n)
|
||||
+ fields.append(field)
|
||||
+ i = i+1 # Skip semicolon
|
||||
+ if len(fields) < 2:
|
||||
+ return None, None
|
||||
+ key, view, rest = fields[0], fields[1], fields[2:]
|
||||
+ fields = {'view': view}
|
||||
+ for field in rest:
|
||||
+ i = field.find('=')
|
||||
+ if i < 0:
|
||||
+ fkey = field
|
||||
+ fvalue = ""
|
||||
+ else:
|
||||
+ fkey = field[:i].strip()
|
||||
+ fvalue = field[i+1:].strip()
|
||||
+ if fkey in fields:
|
||||
+ # Ignore it
|
||||
+ pass
|
||||
+ else:
|
||||
+ fields[fkey] = fvalue
|
||||
+ return key, fields
|
||||
+
|
||||
+def parsefield(line, i, n):
|
||||
+ """Separate one key-value pair in a mailcap entry."""
|
||||
+ start = i
|
||||
+ while i < n:
|
||||
+ c = line[i]
|
||||
+ if c == ';':
|
||||
+ break
|
||||
+ elif c == '\\':
|
||||
+ i = i+2
|
||||
+ else:
|
||||
+ i = i+1
|
||||
+ return line[start:i].strip(), i
|
||||
+
|
||||
+
|
||||
+# Part 3: using the database.
|
||||
+
|
||||
+def findmatch(caps, MIMEtype, key='view', filename="/dev/null", plist=[]):
|
||||
+ """Find a match for a mailcap entry.
|
||||
+
|
||||
+ Return a tuple containing the command line, and the mailcap entry
|
||||
+ used; (None, None) if no match is found. This may invoke the
|
||||
+ 'test' command of several matching entries before deciding which
|
||||
+ entry to use.
|
||||
+
|
||||
+ """
|
||||
+ if _find_unsafe(filename):
|
||||
+ msg = (f"Refusing to use mailcap with filename {filename}. Use a safe "
|
||||
+ "temporary filename.")
|
||||
+ warnings.warn(msg, category=UnsafeMailcapInput, stacklevel=1)
|
||||
+ return None, None
|
||||
+ entries = lookup(caps, MIMEtype, key)
|
||||
+ # XXX This code should somehow check for the needsterminal flag.
|
||||
+ for e in entries:
|
||||
+ if 'test' in e:
|
||||
+ test = subst(e['test'], filename, plist)
|
||||
+ if test is None:
|
||||
+ continue
|
||||
+ if test and os.system(test) != 0:
|
||||
+ continue
|
||||
+ command = subst(e[key], MIMEtype, filename, plist)
|
||||
+ if command is not None:
|
||||
+ return command, e
|
||||
+ return None, None
|
||||
+
|
||||
+def lookup(caps, MIMEtype, key=None):
|
||||
+ entries = []
|
||||
+ if MIMEtype in caps:
|
||||
+ entries = entries + caps[MIMEtype]
|
||||
+ MIMEtypes = MIMEtype.split('/')
|
||||
+ MIMEtype = MIMEtypes[0] + '/*'
|
||||
+ if MIMEtype in caps:
|
||||
+ entries = entries + caps[MIMEtype]
|
||||
+ if key is not None:
|
||||
+ entries = [e for e in entries if key in e]
|
||||
+ entries = sorted(entries, key=lineno_sort_key)
|
||||
+ return entries
|
||||
+
|
||||
+def subst(field, MIMEtype, filename, plist=[]):
|
||||
+ # XXX Actually, this is Unix-specific
|
||||
+ res = ''
|
||||
+ i, n = 0, len(field)
|
||||
+ while i < n:
|
||||
+ c = field[i]; i = i+1
|
||||
+ if c != '%':
|
||||
+ if c == '\\':
|
||||
+ c = field[i:i+1]; i = i+1
|
||||
+ res = res + c
|
||||
+ else:
|
||||
+ c = field[i]; i = i+1
|
||||
+ if c == '%':
|
||||
+ res = res + c
|
||||
+ elif c == 's':
|
||||
+ res = res + filename
|
||||
+ elif c == 't':
|
||||
+ if _find_unsafe(MIMEtype):
|
||||
+ msg = (f"Refusing to substitute MIME type {MIMEtype} into "
|
||||
+ f"a shell command.")
|
||||
+ warnings.warn(msg, category=UnsafeMailcapInput,
|
||||
+ stacklevel=1)
|
||||
+ return None
|
||||
+ res = res + MIMEtype
|
||||
+ elif c == '{':
|
||||
+ start = i
|
||||
+ while i < n and field[i] != '}':
|
||||
+ i = i+1
|
||||
+ name = field[start:i]
|
||||
+ i = i+1
|
||||
+ param = findparam(name, plist)
|
||||
+ if _find_unsafe(param):
|
||||
+ msg = (f"Refusing to substitute parameter {param} "
|
||||
+ f"({name}) into a shell command")
|
||||
+ warnings.warn(msg, category=UnsafeMailcapInput,
|
||||
+ stacklevel=1)
|
||||
+ return None
|
||||
+ res = res + param
|
||||
+ # XXX To do:
|
||||
+ # %n == number of parts if type is multipart/*
|
||||
+ # %F == list of alternating type and filename for parts
|
||||
+ else:
|
||||
+ res = res + '%' + c
|
||||
+ return res
|
||||
+
|
||||
+def findparam(name, plist):
|
||||
+ name = name.lower() + '='
|
||||
+ n = len(name)
|
||||
+ for p in plist:
|
||||
+ if p[:n].lower() == name:
|
||||
+ return p[n:]
|
||||
+ return ''
|
||||
+
|
||||
+
|
||||
+# Part 4: test program.
|
||||
+
|
||||
+def test():
|
||||
+ import sys
|
||||
+ caps = getcaps()
|
||||
+ if not sys.argv[1:]:
|
||||
+ show(caps)
|
||||
+ return
|
||||
+ for i in range(1, len(sys.argv), 2):
|
||||
+ args = sys.argv[i:i+2]
|
||||
+ if len(args) < 2:
|
||||
+ print("usage: mailcap [MIMEtype file] ...")
|
||||
+ return
|
||||
+ MIMEtype = args[0]
|
||||
+ file = args[1]
|
||||
+ command, e = findmatch(caps, MIMEtype, 'view', file)
|
||||
+ if not command:
|
||||
+ print("No viewer found for", type)
|
||||
+ else:
|
||||
+ print("Executing:", command)
|
||||
+ sts = os.system(command)
|
||||
+ sts = os.waitstatus_to_exitcode(sts)
|
||||
+ if sts:
|
||||
+ print("Exit status:", sts)
|
||||
+
|
||||
+def show(caps):
|
||||
+ print("Mailcap files:")
|
||||
+ for fn in listmailcapfiles(): print("\t" + fn)
|
||||
+ print()
|
||||
+ if not caps: caps = getcaps()
|
||||
+ print("Mailcap entries:")
|
||||
+ print()
|
||||
+ ckeys = sorted(caps)
|
||||
+ for type in ckeys:
|
||||
+ print(type)
|
||||
+ entries = caps[type]
|
||||
+ for e in entries:
|
||||
+ keys = sorted(e)
|
||||
+ for k in keys:
|
||||
+ print(" %-15s" % k, e[k])
|
||||
+ print()
|
||||
+
|
||||
+if __name__ == '__main__':
|
||||
+ test()
|
||||
diff --git a/tuir/terminal.py b/tuir/terminal.py
|
||||
index 410ad59..0ce7738 100644
|
||||
--- a/tuir/terminal.py
|
||||
+++ b/tuir/terminal.py
|
||||
@@ -30,7 +30,10 @@ try:
|
||||
# Fix only needed for versions prior to python 3.6
|
||||
from mailcap_fix import mailcap
|
||||
except ImportError:
|
||||
- import mailcap
|
||||
+ try:
|
||||
+ import mailcap
|
||||
+ except ImportError:
|
||||
+ from . import mailcap
|
||||
|
||||
try:
|
||||
# Added in python 3.4+
|
||||
@@ -4,7 +4,7 @@
|
||||
EAPI=8
|
||||
|
||||
DISTUTILS_USE_PEP517=setuptools
|
||||
PYTHON_COMPAT=( python3_{8..13} )
|
||||
PYTHON_COMPAT=( python3_{10..13} )
|
||||
|
||||
inherit distutils-r1
|
||||
|
||||
@@ -29,6 +29,7 @@ RESTRICT="test"
|
||||
|
||||
PATCHES=(
|
||||
"${FILESDIR}"/${PN}-config.patch
|
||||
"${FILESDIR}"/${PN}-mailcap_fix_for_py313.patch
|
||||
)
|
||||
|
||||
S=${WORKDIR}/${PN}-v${PV}
|
||||
|
||||
Reference in New Issue
Block a user