|
|
@@ -93,7 +93,7 @@ def text_to_json(key, value):
|
|
|
# value has surrogate escape sequences
|
|
|
data[key] = remove_surrogates(value)
|
|
|
value_bytes = value.encode(coding, errors="surrogateescape")
|
|
|
- data.update(binary_to_json(key, value_bytes))
|
|
|
+ data |= binary_to_json(key, value_bytes)
|
|
|
else:
|
|
|
# value is pure unicode
|
|
|
data[key] = value
|
|
|
@@ -321,9 +321,7 @@ class PlaceholderReplacer:
|
|
|
self.overrides = {}
|
|
|
|
|
|
def __call__(self, text, overrides=None):
|
|
|
- ovr = {}
|
|
|
- ovr.update(self.overrides)
|
|
|
- ovr.update(overrides or {})
|
|
|
+ ovr = self.overrides | (overrides or {})
|
|
|
return _replace_placeholders(text, overrides=ovr)
|
|
|
|
|
|
|
|
|
@@ -776,8 +774,7 @@ class ArchiveFormatter(BaseFormatter):
|
|
|
)
|
|
|
|
|
|
def __init__(self, format, repository, manifest, key, *, iec=False, deleted=False):
|
|
|
- static_data = {} # here could be stuff on repo level, above archive level
|
|
|
- static_data.update(self.FIXED_KEYS)
|
|
|
+ static_data = {} | self.FIXED_KEYS # here could be stuff on repo level, above archive level
|
|
|
super().__init__(format, static_data)
|
|
|
self.repository = repository
|
|
|
self.manifest = manifest
|
|
|
@@ -804,16 +801,14 @@ class ArchiveFormatter(BaseFormatter):
|
|
|
self.name = archive_info.name
|
|
|
self.id = archive_info.id
|
|
|
item_data = {}
|
|
|
- item_data.update({} if jsonline else self.static_data)
|
|
|
- item_data.update(
|
|
|
- {
|
|
|
- "name": archive_info.name,
|
|
|
- "archive": archive_info.name,
|
|
|
- "id": bin_to_hex(archive_info.id),
|
|
|
- "time": self.format_time(archive_info.ts),
|
|
|
- "start": self.format_time(archive_info.ts),
|
|
|
- }
|
|
|
- )
|
|
|
+ item_data |= {} if jsonline else self.static_data
|
|
|
+ item_data |= {
|
|
|
+ "name": archive_info.name,
|
|
|
+ "archive": archive_info.name,
|
|
|
+ "id": bin_to_hex(archive_info.id),
|
|
|
+ "time": self.format_time(archive_info.ts),
|
|
|
+ "start": self.format_time(archive_info.ts),
|
|
|
+ }
|
|
|
for key in self.used_call_keys:
|
|
|
item_data[key] = self.call_keys[key]()
|
|
|
|
|
|
@@ -821,7 +816,7 @@ class ArchiveFormatter(BaseFormatter):
|
|
|
# But unsure whether hostname, username, command_line could contain surrogate escapes, play safe:
|
|
|
for key in "hostname", "username", "command_line":
|
|
|
if key in item_data:
|
|
|
- item_data.update(text_to_json(key, item_data[key]))
|
|
|
+ item_data |= text_to_json(key, item_data[key])
|
|
|
return item_data
|
|
|
|
|
|
@property
|
|
|
@@ -893,8 +888,7 @@ class ItemFormatter(BaseFormatter):
|
|
|
def __init__(self, archive, format):
|
|
|
from ..checksums import StreamingXXH64
|
|
|
|
|
|
- static_data = {"archivename": archive.name, "archiveid": archive.fpr}
|
|
|
- static_data.update(self.FIXED_KEYS)
|
|
|
+ static_data = {"archivename": archive.name, "archiveid": archive.fpr} | self.FIXED_KEYS
|
|
|
super().__init__(format, static_data)
|
|
|
self.xxh64 = StreamingXXH64
|
|
|
self.archive = archive
|
|
|
@@ -916,11 +910,11 @@ class ItemFormatter(BaseFormatter):
|
|
|
|
|
|
def get_item_data(self, item, jsonline=False):
|
|
|
item_data = {}
|
|
|
- item_data.update({} if jsonline else self.static_data)
|
|
|
+ item_data |= {} if jsonline else self.static_data
|
|
|
|
|
|
- item_data.update(text_to_json("path", item.path))
|
|
|
+ item_data |= text_to_json("path", item.path)
|
|
|
target = item.get("target", "")
|
|
|
- item_data.update(text_to_json("target", target))
|
|
|
+ item_data |= text_to_json("target", target)
|
|
|
if not jsonline:
|
|
|
item_data["extra"] = "" if not target else f" -> {item_data['target']}"
|
|
|
|
|
|
@@ -935,8 +929,8 @@ class ItemFormatter(BaseFormatter):
|
|
|
|
|
|
item_data["uid"] = item.get("uid") # int or None
|
|
|
item_data["gid"] = item.get("gid") # int or None
|
|
|
- item_data.update(text_to_json("user", item.get("user", str(item_data["uid"]))))
|
|
|
- item_data.update(text_to_json("group", item.get("group", str(item_data["gid"]))))
|
|
|
+ item_data |= text_to_json("user", item.get("user", str(item_data["uid"])))
|
|
|
+ item_data |= text_to_json("group", item.get("group", str(item_data["gid"])))
|
|
|
|
|
|
item_data["flags"] = item.get("bsdflags") # int if flags known, else (if flags unknown) None
|
|
|
# inode number from source filesystem (may be absent on some platforms)
|
|
|
@@ -1007,8 +1001,7 @@ class DiffFormatter(BaseFormatter):
|
|
|
METADATA = ("mode", "type", "owner", "group", "user", "mtime", "ctime")
|
|
|
|
|
|
def __init__(self, format, content_only=False):
|
|
|
- static_data = {}
|
|
|
- static_data.update(self.FIXED_KEYS)
|
|
|
+ static_data = {} | self.FIXED_KEYS
|
|
|
super().__init__(format or "{content}{link}{directory}{blkdev}{chrdev}{fifo} {path}{NL}", static_data)
|
|
|
self.content_only = content_only
|
|
|
self.format_keys = {f[1] for f in Formatter().parse(format)}
|
|
|
@@ -1047,7 +1040,7 @@ class DiffFormatter(BaseFormatter):
|
|
|
change.append(self.call_keys[key](item))
|
|
|
diff_data["change"] = " ".join([v for v in change if v])
|
|
|
diff_data["path"] = item.path
|
|
|
- diff_data.update({} if jsonline else self.static_data)
|
|
|
+ diff_data |= {} if jsonline else self.static_data
|
|
|
return diff_data
|
|
|
|
|
|
def format_other(self, key, diff: "ItemDiff"):
|
|
|
@@ -1218,7 +1211,7 @@ class BorgJsonEncoder(json.JSONEncoder):
|
|
|
def basic_json_data(manifest, *, cache=None, extra=None):
|
|
|
key = manifest.key
|
|
|
data = extra or {}
|
|
|
- data.update({"repository": BorgJsonEncoder().default(manifest.repository), "encryption": {"mode": key.ARG_NAME}})
|
|
|
+ data |= {"repository": BorgJsonEncoder().default(manifest.repository), "encryption": {"mode": key.ARG_NAME}}
|
|
|
data["repository"]["last_modified"] = OutputTimestamp(manifest.last_timestamp)
|
|
|
if key.NAME.startswith("key file"):
|
|
|
data["encryption"]["keyfile"] = key.find_key()
|