Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Use json.dump in FileExfiltrationWriter #15095

Merged
merged 2 commits into from Feb 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/15095.misc
@@ -0,0 +1 @@
Refactor writing json data in `FileExfiltrationWriter`.
16 changes: 8 additions & 8 deletions synapse/app/admin_cmd.py
Expand Up @@ -149,7 +149,7 @@ def write_events(self, room_id: str, events: List[EventBase]) -> None:

with open(events_file, "a") as f:
for event in events:
print(json.dumps(event.get_pdu_json()), file=f)
json.dump(event.get_pdu_json(), fp=f)

def write_state(
self, room_id: str, event_id: str, state: StateMap[EventBase]
Expand All @@ -162,7 +162,7 @@ def write_state(

with open(event_file, "a") as f:
for event in state.values():
print(json.dumps(event.get_pdu_json()), file=f)
json.dump(event.get_pdu_json(), fp=f)

def write_invite(
self, room_id: str, event: EventBase, state: StateMap[EventBase]
Expand All @@ -178,7 +178,7 @@ def write_invite(

with open(invite_state, "a") as f:
for event in state.values():
print(json.dumps(event), file=f)
json.dump(event, fp=f)

def write_knock(
self, room_id: str, event: EventBase, state: StateMap[EventBase]
Expand All @@ -194,15 +194,15 @@ def write_knock(

with open(knock_state, "a") as f:
for event in state.values():
print(json.dumps(event), file=f)
json.dump(event, fp=f)

def write_profile(self, profile: JsonDict) -> None:
user_directory = os.path.join(self.base_directory, "user_data")
os.makedirs(user_directory, exist_ok=True)
profile_file = os.path.join(user_directory, "profile")

with open(profile_file, "a") as f:
print(json.dumps(profile), file=f)
json.dump(profile, fp=f)

def write_devices(self, devices: List[JsonDict]) -> None:
user_directory = os.path.join(self.base_directory, "user_data")
Expand All @@ -211,7 +211,7 @@ def write_devices(self, devices: List[JsonDict]) -> None:

for device in devices:
with open(device_file, "a") as f:
print(json.dumps(device), file=f)
json.dump(device, fp=f)

def write_connections(self, connections: List[JsonDict]) -> None:
user_directory = os.path.join(self.base_directory, "user_data")
Expand All @@ -220,7 +220,7 @@ def write_connections(self, connections: List[JsonDict]) -> None:

for connection in connections:
with open(connection_file, "a") as f:
print(json.dumps(connection), file=f)
json.dump(connection, fp=f)

def write_account_data(
self, file_name: str, account_data: Mapping[str, JsonDict]
Expand All @@ -233,7 +233,7 @@ def write_account_data(
account_data_file = os.path.join(account_data_directory, file_name)

with open(account_data_file, "a") as f:
print(json.dumps(account_data), file=f)
json.dump(account_data, fp=f)

def finished(self) -> str:
return self.base_directory
Expand Down