/snap/core20/2866/usr/lib/python3.8
NameSizeModeActions
asyncio/-0755rm
collections/-0755rm
concurrent/-0755rm
ctypes/-0755rm
curses/-0755rm
dbm/-0755rm
distutils/-0755rm
email/-0755rm
encodings/-0755rm
html/-0755rm
http/-0755rm
importlib/-0755rm
json/-0755rm
lib-dynload/-0755rm
lib2to3/-0755rm
logging/-0755rm
multiprocessing/-0755rm
pydoc_data/-0755rm
sqlite3/-0755rm
test/-0755rm
unittest/-0755rm
urllib/-0755rm
venv/-0755rm
wsgiref/-0755rm
xml/-0755rm
xmlrpc/-0755rm
__pycache__/-0755rm
abc.py44890644editdlrm
aifc.py328140644editdlrm
antigravity.py4770644editdlrm
argparse.py963110644editdlrm
ast.py192340644editdlrm
asynchat.py113280644editdlrm
asyncore.py200940644editdlrm
base64.py203820755editdlrm
bdb.py320560644editdlrm
binhex.py139540644editdlrm
bisect.py22140644editdlrm
bz2.py125580644editdlrm
calendar.py248320644editdlrm
cgi.py339320755editdlrm
cgitb.py120960644editdlrm
chunk.py54350644editdlrm
cmd.py148600644editdlrm
code.py106220644editdlrm
codecs.py366670644editdlrm
codeop.py63300644editdlrm
colorsys.py40640644editdlrm
compileall.py136780644editdlrm
configparser.py543740644editdlrm
contextlib.py249950644editdlrm
contextvars.py1290644editdlrm
copy.py86610644editdlrm
copyreg.py71350644editdlrm
cProfile.py69980755editdlrm
crypt.py36100644editdlrm
csv.py161440644editdlrm
dataclasses.py499730644editdlrm
datetime.py882870644editdlrm
decimal.py3200644editdlrm
difflib.py840580644editdlrm
dis.py205700644editdlrm
doctest.py1045430644editdlrm
dummy_threading.py28150644editdlrm
enum.py381360644editdlrm
filecmp.py98300644editdlrm
fileinput.py147090644editdlrm
fnmatch.py40790644editdlrm
formatter.py151430644editdlrm
fractions.py243290644editdlrm
ftplib.py351290644editdlrm
functools.py374060644editdlrm
genericpath.py49750644editdlrm
getopt.py74890644editdlrm
getpass.py59940644editdlrm
gettext.py275650644editdlrm
glob.py56970644editdlrm
gzip.py214130644editdlrm
hashlib.py97300644editdlrm
heapq.py228770644editdlrm
hmac.py66290644editdlrm
imaplib.py536060644editdlrm
imghdr.py38080644editdlrm
imp.py105360644editdlrm
inspect.py1185500644editdlrm
io.py35410644editdlrm
ipaddress.py763360644editdlrm
keyword.py9450644editdlrm
LICENSE.txt139250644editdlrm
linecache.py53300644editdlrm
locale.py781950644editdlrm
lzma.py129830644editdlrm
mailbox.py786610644editdlrm
mailcap.py90670644editdlrm
mimetypes.py216640644editdlrm
modulefinder.py244300644editdlrm
netrc.py55660644editdlrm
nntplib.py432610644editdlrm
ntpath.py258140644editdlrm
nturl2path.py28870644editdlrm
numbers.py102440644editdlrm
opcode.py58080644editdlrm
operator.py107110644editdlrm
optparse.py603690644editdlrm
os.py389950644editdlrm
pathlib.py526100644editdlrm
pdb.py627380755editdlrm
pickle.py644670644editdlrm
pickletools.py934860644editdlrm
pipes.py89160644editdlrm
pkgutil.py214610644editdlrm
platform.py404250755editdlrm
plistlib.py324600644editdlrm
poplib.py150770644editdlrm
posixpath.py155000644editdlrm
pprint.py214840644editdlrm
profile.py235340755editdlrm
pstats.py273450644editdlrm
pty.py48070644editdlrm
pyclbr.py152550644editdlrm
pydoc.py1068630755editdlrm
py_compile.py81480644editdlrm
queue.py113560644editdlrm
quopri.py72520755editdlrm
random.py288020644editdlrm
re.py158610644editdlrm
reprlib.py52670644editdlrm
rlcompleter.py70970644editdlrm
runpy.py120520644editdlrm
sched.py64420644editdlrm
secrets.py20380644editdlrm
selectors.py185610644editdlrm
shelve.py85270644editdlrm
shlex.py133250644editdlrm
shutil.py514740644editdlrm
signal.py22730644editdlrm
site.py223360644editdlrm
sitecustomize.py-0editdlrm
smtpd.py347090755editdlrm
smtplib.py448040755editdlrm
sndhdr.py70990644editdlrm
socket.py352430644editdlrm
socketserver.py272960644editdlrm
sre_compile.py266950644editdlrm
sre_constants.py71540644editdlrm
sre_parse.py402300644editdlrm
ssl.py523630644editdlrm
stat.py54850644editdlrm
statistics.py396900644editdlrm
string.py105350644editdlrm
stringprep.py129170644editdlrm
struct.py2570644editdlrm
subprocess.py773300644editdlrm
sunau.py183750644editdlrm
symbol.py21090644editdlrm
symtable.py80210644editdlrm
sysconfig.py250350644editdlrm
tabnanny.py114060755editdlrm
tarfile.py955800755editdlrm
telnetlib.py232540644editdlrm
tempfile.py329200644editdlrm
textwrap.py194070644editdlrm
this.py10030644editdlrm
threading.py508200644editdlrm
timeit.py134800755editdlrm
token.py23680644editdlrm
tokenize.py258410644editdlrm
trace.py298580755editdlrm
traceback.py236110644editdlrm
tracemalloc.py170760644editdlrm
tty.py8790644editdlrm
turtle.py1437160644editdlrm
types.py97130644editdlrm
typing.py689620644editdlrm
uu.py69570755editdlrm
uuid.py304660644editdlrm
warnings.py196880644editdlrm
wave.py182300644editdlrm
weakref.py213870644editdlrm
webbrowser.py240830755editdlrm
xdrlib.py59130644editdlrm
zipapp.py75350644editdlrm
zipfile.py891350644editdlrm
zipimport.py307650644editdlrm
_bootlocale.py18010644editdlrm
_collections_abc.py261000644editdlrm
_compat_pickle.py87490644editdlrm
_compression.py53400644editdlrm
_dummy_thread.py60270644editdlrm
_markupbase.py145980644editdlrm
_osx_support.py217740644editdlrm
_pydecimal.py2286660644editdlrm
_pyio.py931770644editdlrm
_py_abc.py61890644editdlrm
_sitebuiltins.py31150644editdlrm
_strptime.py252680644editdlrm
_sysconfigdata__linux_x86_64-linux-gnu.py258340644editdlrm
_sysconfigdata__x86_64-linux-gnu.py258340644editdlrm
_threading_local.py72200644editdlrm
_weakrefset.py57350644editdlrm
__future__.py51470644editdlrm
__phello__.foo.py640644editdlrm
Edit: /snap/core20/2866/usr/lib/python3.8/mailcap.py (9067B)
"""Mailcap file handling. See RFC 1524.""" import os import warnings import re __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'] else: 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: fp = open(mailcap, 'r') except OSError: continue with fp: morecaps, lineno = _readmailcapfile(fp, lineno) for key, value in morecaps.items(): if not key 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.""" warnings.warn('readmailcapfile is deprecated, use getcaps instead', DeprecationWarning, 2) 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 1: line = fp.readline() if not line: break # 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 = "Refusing to use mailcap with filename %r. Use a safe temporary filename." % (filename,) warnings.warn(msg, UnsafeMailcapInput) 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 = "Refusing to substitute MIME type %r into a shell command." % (MIMEtype,) warnings.warn(msg, UnsafeMailcapInput) 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 = "Refusing to substitute parameter %r (%s) into a shell command" % (param, name) warnings.warn(msg, UnsafeMailcapInput) 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) 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()