summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarius Gedminas <marius@gedmin.as>2020-10-09 09:19:09 +0300
committerGitHub <noreply@github.com>2020-10-09 09:19:09 +0300
commit19ca73209bfc3e83d803561b3c46fe3109b53421 (patch)
treea827f7f0f37e709cc4286fe65761ed7fb24a0f04
parent8c6d2aa17b3bf86d28c1fa275b50e5cc4794b30d (diff)
parent32d9f2938a57e6ab981919516341b2bb1a58ebb3 (diff)
Merge pull request #194 from StephaneMangin/python2_removal_continued
Python 2 removal continued
-rwxr-xr-xbenchmark.py1
-rwxr-xr-xsetup.py3
-rw-r--r--src/gtimelog/main.py3
-rw-r--r--src/gtimelog/settings.py2
-rw-r--r--src/gtimelog/tests/test_timelog.py7
-rw-r--r--src/gtimelog/timelog.py40
6 files changed, 23 insertions, 33 deletions
diff --git a/benchmark.py b/benchmark.py
index eec25dd..ba79d16 100755
--- a/benchmark.py
+++ b/benchmark.py
@@ -1,5 +1,4 @@
#!/usr/bin/python3
-from __future__ import print_function
import gc
import os
diff --git a/setup.py b/setup.py
index d86dee9..d254844 100755
--- a/setup.py
+++ b/setup.py
@@ -1,6 +1,5 @@
#!/usr/bin/env python
import ast
-import io
import os
import re
import sys
@@ -12,7 +11,7 @@ here = os.path.dirname(__file__)
def read(filename):
- with io.open(os.path.join(here, filename), 'r', encoding='utf-8') as f:
+ with open(os.path.join(here, filename), encoding='utf-8') as f:
return f.read()
diff --git a/src/gtimelog/main.py b/src/gtimelog/main.py
index d9e4a7b..7ac0c3d 100644
--- a/src/gtimelog/main.py
+++ b/src/gtimelog/main.py
@@ -30,7 +30,6 @@ import email.header
import email.mime.text
import functools
import gettext
-import io
import locale
import logging
import os
@@ -344,7 +343,7 @@ class Application(Gtk.Application):
def get_contributors(self):
contributors = []
- with io.open(CONTRIBUTORS_FILE, encoding='UTF-8') as f:
+ with open(CONTRIBUTORS_FILE, encoding='utf-8') as f:
for line in f:
if line.startswith('- '):
contributors.append(line[2:].strip())
diff --git a/src/gtimelog/settings.py b/src/gtimelog/settings.py
index 6292c81..1c8a240 100644
--- a/src/gtimelog/settings.py
+++ b/src/gtimelog/settings.py
@@ -2,8 +2,6 @@
Settings for GTimeLog
"""
-from __future__ import absolute_import
-
import datetime
import locale
import os
diff --git a/src/gtimelog/tests/test_timelog.py b/src/gtimelog/tests/test_timelog.py
index 9132f22..79b8625 100644
--- a/src/gtimelog/tests/test_timelog.py
+++ b/src/gtimelog/tests/test_timelog.py
@@ -1,6 +1,5 @@
"""Tests for gtimelog.timelog"""
-import codecs
import datetime
import doctest
import os
@@ -1004,7 +1003,7 @@ class Mixins(object):
def write_file(self, filename, content):
filename = os.path.join(self.mkdtemp(), filename)
- with codecs.open(filename, 'w', encoding='UTF-8') as f:
+ with open(filename, 'w', encoding='utf-8') as f:
f.write(content)
return filename
@@ -1049,10 +1048,10 @@ class TestTaskList(Mixins, unittest.TestCase):
])
def test_unicode(self):
- taskfile = self.write_file('tasks.txt', u'\N{SNOWMAN}')
+ taskfile = self.write_file('tasks.txt', '\N{SNOWMAN}')
tasklist = TaskList(taskfile)
self.assertEqual(tasklist.groups, [
- ('Other', [u'\N{SNOWMAN}']),
+ ('Other', ['\N{SNOWMAN}']),
])
def test_reloading(self):
diff --git a/src/gtimelog/timelog.py b/src/gtimelog/timelog.py
index cea7084..07c06da 100644
--- a/src/gtimelog/timelog.py
+++ b/src/gtimelog/timelog.py
@@ -2,9 +2,6 @@
Non-GUI bits of gtimelog.
"""
-from __future__ import unicode_literals
-
-import codecs
import collections
import csv
import datetime
@@ -550,11 +547,11 @@ class Reports(object):
continue # skip empty "arrival" entries
entry = entry[:1].upper() + entry[1:]
- output.write(u" %-61s %+5s\n" %
+ output.write(" %-61s %+5s\n" %
(entry, format_duration_short(duration)))
output.write('-' * 70 + '\n')
- output.write(u"%+70s\n" % format_duration_short(totals[cat]))
+ output.write("%+70s\n" % format_duration_short(totals[cat]))
output.write('\n')
output.write("Total work done this %s: %s\n" %
(period_name, format_duration_short(total_work)))
@@ -629,7 +626,7 @@ class Reports(object):
if no_cat is not None:
items.append(('(none)', no_cat))
for cat, duration in items:
- output.write(u"%-62s %s\n" % (
+ output.write("%-62s %s\n" % (
cat, format_duration_long(duration)))
output.write('\n')
@@ -666,7 +663,7 @@ class Reports(object):
cat, datetime.timedelta(0)) + duration
entry = entry[:1].upper() + entry[1:]
- output.write(u"%-62s %s\n" %
+ output.write("%-62s %s\n" %
(entry, format_duration_long(duration)))
output.write('\n')
output.write("Total work done this %s: %s\n" %
@@ -681,7 +678,7 @@ class Reports(object):
def weekly_report_subject(self, who):
week = self.window.min_timestamp.isocalendar()[1]
- return u'Weekly report for %s (week %02d)' % (who, week)
+ return 'Weekly report for %s (week %02d)' % (who, week)
def weekly_report(self, output, email, who):
if self.style == 'categorized':
@@ -703,7 +700,7 @@ class Reports(object):
def monthly_report_subject(self, who):
month = self.window.min_timestamp.strftime('%Y/%m')
- return u'Monthly report for %s (%s)' % (who, month)
+ return 'Monthly report for %s (%s)' % (who, month)
def monthly_report(self, output, email, who):
if self.style == 'categorized':
@@ -727,7 +724,7 @@ class Reports(object):
min = self.window.min_timestamp.strftime('%Y-%m-%d')
max = self.window.max_timestamp - datetime.timedelta(1)
max = max.strftime('%Y-%m-%d')
- return u'Custom date range report for %s (%s - %s)' % (who, min, max)
+ return 'Custom date range report for %s (%s - %s)' % (who, min, max)
def custom_range_report_categorized(self, output, email, who):
"""Format a custom range report with entries displayed under categories."""
@@ -741,8 +738,8 @@ class Reports(object):
weekday_names = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
weekday = weekday_names[self.window.min_timestamp.weekday()]
week = self.window.min_timestamp.isocalendar()[1]
- return (u"{0:%Y-%m-%d} report for {who}"
- u" ({weekday}, week {week:0>2})".format(
+ return ("{0:%Y-%m-%d} report for {who}"
+ " ({weekday}, week {week:0>2})".format(
self.window.min_timestamp, who=who,
weekday=weekday, week=week))
@@ -753,8 +750,8 @@ class Reports(object):
"""
window = self.window
if self.email_headers:
- output.write(u"To: %s\n" % email)
- output.write(u"Subject: %s\n" % self.daily_report_subject(who))
+ output.write("To: %s\n" % email)
+ output.write("Subject: %s\n" % self.daily_report_subject(who))
output.write('\n')
items = list(window.all_entries())
if not items:
@@ -770,7 +767,7 @@ class Reports(object):
if work:
for start, entry, duration in work:
entry = entry[:1].upper() + entry[1:]
- output.write(u"%-62s %s\n" % (entry,
+ output.write("%-62s %s\n" % (entry,
format_duration_long(duration)))
cat, task = TimeCollection.split_category(entry)
categories[cat] = categories.get(
@@ -787,7 +784,7 @@ class Reports(object):
if slack:
for start, entry, duration in slack:
entry = entry[:1].upper() + entry[1:]
- output.write(u"%-62s %s\n" % (entry,
+ output.write("%-62s %s\n" % (entry,
format_duration_long(duration)))
output.write('\n')
output.write("Time spent slacking: %s\n" %
@@ -992,11 +989,10 @@ class TimeLog(TimeCollection):
def raw_append(self, line, need_space):
"""Append a line to the time log file."""
- f = codecs.open(self.filename, "a", encoding='UTF-8')
- if need_space:
- f.write('\n')
- f.write(line + '\n')
- f.close()
+ with open(self.filename, "a", encoding='utf-8') as f:
+ if need_space:
+ f.write('\n')
+ f.write(line + '\n')
self.last_mtime = get_mtime(self.filename)
def append(self, entry, now=None):
@@ -1106,7 +1102,7 @@ class TaskList(object):
groups = {}
self.last_mtime = get_mtime(self.filename)
try:
- with codecs.open(self.filename, encoding='UTF-8') as f:
+ with open(self.filename, encoding='utf-8') as f:
for line in f:
line = line.strip()
if not line or line.startswith('#'):