[gnome-clocks] Alarm, World: Minor file handling changes
- From: Paolo Borelli <pborelli src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-clocks] Alarm, World: Minor file handling changes
- Date: Fri, 14 Dec 2012 20:10:40 +0000 (UTC)
commit cb8971325a04958fc51fdace074436ee67c8f65c
Author: Volker Sobek <reklov live com>
Date: Mon Dec 10 14:28:41 2012 +0100
Alarm, World: Minor file handling changes
Open files with the 'with' statement and stop json.dump()
from escaping non-ASCII characters.
gnomeclocks/alarm.py | 10 ++++------
gnomeclocks/world.py | 10 ++++------
2 files changed, 8 insertions(+), 12 deletions(-)
---
diff --git a/gnomeclocks/alarm.py b/gnomeclocks/alarm.py
index d17cdcf..edfec17 100644
--- a/gnomeclocks/alarm.py
+++ b/gnomeclocks/alarm.py
@@ -44,16 +44,14 @@ class AlarmsStorage:
"active": a.active
}
alarm_list.append(d)
- f = open(self.filename, "wb")
- json.dump(alarm_list, f)
- f.close()
+ with open(self.filename, "wb") as f:
+ json.dump(alarm_list, f, ensure_ascii=False)
def load(self):
alarms = []
try:
- f = open(self.filename, "rb")
- alarm_list = json.load(f)
- f.close()
+ with open(self.filename, "rb") as f:
+ alarm_list = json.load(f)
for a in alarm_list:
try:
n, h, m, d = (a['name'], int(a['hour']), int(a['minute']), a['days'])
diff --git a/gnomeclocks/world.py b/gnomeclocks/world.py
index ddb3e4f..351e6a9 100644
--- a/gnomeclocks/world.py
+++ b/gnomeclocks/world.py
@@ -39,16 +39,14 @@ class WorldClockStorage:
def save(self, clocks):
locations = [str(c.location.serialize()) for c in clocks]
- f = open(self.filename, "wb")
- json.dump(locations, f)
- f.close()
+ with open(self.filename, "wb") as f:
+ json.dump(locations, f, ensure_ascii=False)
def load(self):
clocks = []
try:
- f = open(self.filename, "rb")
- locations = json.load(f)
- f.close()
+ with open(self.filename, "rb") as f:
+ locations = json.load(f)
for l in locations:
try:
variant = GLib.Variant.parse(None, l, None, None)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]