Fix Windows compatibility issues and AGE and GPG support

This commit is contained in:
SlugFiller
2023-09-10 02:30:33 +03:00
15 changed files with 1012 additions and 102 deletions

View File

@@ -5,6 +5,7 @@ import functools
import io
import logging
import struct
import sys
import time
log = logging.getLogger(__name__)
@@ -258,6 +259,30 @@ def assuan_serialize(data):
return data
def escape_cmd_quotes(in_str):
"""
Escape a string for use as a command line argument inside quotes.
Does not add quotes. This allows appending multiple strings inside the quotes.
"""
if sys.platform == 'win32':
return in_str.translate(str.maketrans({'%': '%%', '\"': '\"\"'}))
else:
return in_str.translate(str.maketrans({'\"': '\\\"', '\'': '\\\'', '\\': '\\\\'}))
def escape_cmd_win(in_str):
"""Escape a string for Windows batch files in a context where quotes cannot be used."""
return in_str.translate(str.maketrans({'\"': '^\"',
'%': '%%',
'&': '^&',
'\'': '^\'',
'<': '^<',
'>': '^>',
'^': '^^',
'|': '^|'}))
class ExpiringCache:
"""Simple cache with a deadline."""