From f81c7886874fab2a1dbccfd2ef1fae0c4d909898 Mon Sep 17 00:00:00 2001 From: George Tzoumas Date: Wed, 19 Feb 2020 00:56:16 +0100 Subject: [PATCH] upgrade to Python 3.7 - just launched 2to3-3.7 -- seems to be working! - had to fix string decoding in calmagick.py --- callirhoe.py | 28 +++++++-------- calmagick.py | 62 +++++++++++++++++----------------- geom/sloppy.py | 2 +- lang/DE.py | 18 +++++----- lang/EL.py | 18 +++++----- lang/EN.py | 18 +++++----- lang/FR.py | 18 +++++----- lang/TR.py | 14 ++++---- layouts/_base.py | 6 ++-- layouts/bars.py | 4 +-- layouts/classic.py | 6 ++-- layouts/sparse.py | 6 ++-- lib/geom.py | 12 +++---- lib/holiday.py | 9 +++-- lib/xcairo.py | 4 +-- scripts/make_resources_list.py | 6 ++-- style/bw_gfs.py | 2 +- style/bw_sparse_gfs.py | 2 +- style/gfs.py | 2 +- style/rainbow.py | 4 +-- style/rainbow_gfs.py | 4 +-- style/transparent_gfs.py | 2 +- 22 files changed, 123 insertions(+), 124 deletions(-) diff --git a/callirhoe.py b/callirhoe.py index adbfb8f..7564555 100755 --- a/callirhoe.py +++ b/callirhoe.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2.7 +#!/usr/bin/env python3.7 # -*- coding: utf-8 -*- # callirhoe - high quality calendar rendering @@ -93,7 +93,7 @@ def import_plugin(plugin_paths, cat, longcat, longcat2, listopt, preset): def print_examples(): """print usage examples""" - print """Examples: + print("""Examples: Create a calendar of the current year (by default in a 4x3 grid): $ callirhoe my_calendar.pdf @@ -124,7 +124,7 @@ Create a calendar as a full-hd wallpaper (1920x1080): and do some magic with ImageMagick! ;) $ convert wallpaper.png -negate fancy.png -""" +""") def add_list_option(parser, opt): @@ -198,20 +198,20 @@ def main_program(): list_and_exit = False if options.list_languages: - for x in plugin_list("lang"): print x[0], - print + for x in plugin_list("lang"): print(x[0], end=' ') + print() list_and_exit = True if options.list_styles: - for x in plugin_list("style"): print x[0], - print + for x in plugin_list("style"): print(x[0], end=' ') + print() list_and_exit = True if options.list_geometries: - for x in plugin_list("geom"): print x[0], - print + for x in plugin_list("geom"): print(x[0], end=' ') + print() list_and_exit = True if options.list_layouts: - for x in plugin_list("layouts"): print x[0], - print + for x in plugin_list("layouts"): print(x[0], end=' ') + print() list_and_exit = True if list_and_exit: return @@ -248,11 +248,11 @@ def main_program(): # the usual "beware of exec()" crap applies here... but come on, # this is a SCRIPTING language, you can always hack the source code!!! if options.lang_assign: - for x in options.lang_assign: exec "Language.%s" % x + for x in options.lang_assign: exec("Language.%s" % x) if options.style_assign: - for x in options.style_assign: exec "Style.%s" % x + for x in options.style_assign: exec("Style.%s" % x) if options.geom_assign: - for x in options.geom_assign: exec "Geometry.%s" % x + for x in options.geom_assign: exec("Geometry.%s" % x) calendar.long_month_name = Language.long_month_name calendar.long_day_name = Language.long_day_name diff --git a/calmagick.py b/calmagick.py index 7ffb84a..53a4b43 100755 --- a/calmagick.py +++ b/calmagick.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2.7 +#!/usr/bin/env python3.7 # -*- coding: utf-8 -*- # callirhoe - high quality calendar rendering @@ -31,7 +31,7 @@ import tempfile import glob import random import optparse -import Queue +import queue import threading import lib @@ -84,17 +84,17 @@ class PNMImage(object): state = 0; for i in range(len(strlist)): # skip comments - if strlist[i].startswith('#'): continue + if strlist[i].startswith(b'#'): continue # skip empty lines if len(strlist[i]) == 0: continue # parse header if state == 0: - if not strlist[i].startswith('P2'): + if not strlist[i].startswith(b'P2'): raise RuntimeError('invalid PNM image format: %s' % strlist[i]) state += 1 # parse size elif state == 1: - w,h = map(int,strlist[i].split()) + w,h = list(map(int,strlist[i].split())) if w != h: raise RuntimeError('non-square PNM image') self.size = (w,h) @@ -105,14 +105,14 @@ class PNMImage(object): state += 1 # bitmap else: - data = ' '.join(filter(lambda s: not s.startswith('#'), strlist[i:])) - intlist = map(int,data.split()) + data = ' '.join([s.decode('utf-8') for s in strlist[i:] if not s.startswith(b'#')]) + intlist = list(map(int,data.split())) self.data = [intlist[x:x+w] for x in range(0, len(intlist), w)] break self._rsum_cache=(-1,-1,0) # y,x,s # self.xsum = [map(lambda x: sum(self.data[y][0:x]), range(w+1)) for y in range(0,h)] - self.xsum = [map(lambda x: self._rsum(y,x), range(w+1)) for y in range(0,h)] + self.xsum = [[self._rsum(y,x) for x in range(w+1)] for y in range(0,h)] def _rsum(self,y,x): """running sum with cache @@ -171,13 +171,13 @@ class PNMImage(object): w,h = self.size sz_lo = _bound(int(w*size_range[0]+0.5),1,w) sz_hi = _bound(int(w*size_range[1]+0.5),1,w) - szv_range = range(sz_lo, sz_hi+1) + szv_range = list(range(sz_lo, sz_hi+1)) if rr == 1: - sz_range = zip(szv_range, szv_range) + sz_range = list(zip(szv_range, szv_range)) elif rr > 1: - sz_range = zip(szv_range, map(lambda x: _bound(int(x/rr+0.5),1,w), szv_range)) + sz_range = list(zip(szv_range, [_bound(int(x/rr+0.5),1,w) for x in szv_range])) else: - sz_range = zip(map(lambda x: _bound(int(x*rr+0.5),1,w), szv_range), szv_range) + sz_range = list(zip([_bound(int(x*rr+0.5),1,w) for x in szv_range], szv_range)) best = self.lowest_block_avg(*sz_range[0]) # we do not use at_least because non-global minimum, when relaxed, may jump well above threshold entropy_thres = max(at_least, best[0]*(1+relax)) @@ -427,17 +427,17 @@ def _entropy_placement(img, size, args, options, r): R = float(w)/h if r == 0: r = R if options.verbose: - print "Calculating image entropy..." + print("Calculating image entropy...") qresize = '%dx%d!' % ((options.quantum,)*2) pnm_entropy = PNMImage(subprocess.check_output([_prog_im, img] + args + _IM_entropy_args(options.alt) + [qresize, '-normalize'] + (['-negate'] if options.placement == 'max' else []) + "-compress None pnm:-".split()).splitlines()) # find optimal fit - if options.verbose: print "Fitting... ", + if options.verbose: print("Fitting... ", end=' ') best = pnm_entropy.fit_rect((options.min_size,options.max_size), options.low_entropy, options.relax, r/R) if options.verbose: - print "ent=%0.2f frac=(%0.2f,%0.2f) pos=(%d,%d) bs=(%d,%d) min=%0.2f r=%0.2f" % ( - best[0], best[1][0], best[1][1], best[2][0], best[2][1], best[3][0], best[3][1], best[4], R*best[3][0]/best[3][1]) + print("ent=%0.2f frac=(%0.2f,%0.2f) pos=(%d,%d) bs=(%d,%d) min=%0.2f r=%0.2f" % ( + best[0], best[1][0], best[1][1], best[2][0], best[2][1], best[3][0], best[3][1], best[4], R*best[3][0]/best[3][1])) # (W,H,X,Y) w,h = size @@ -511,17 +511,17 @@ def compose_calendar(img, outimg, options, callirhoe_args, magick_args, stats=No if img in cache: geometry, dark = cache[img] if options.verbose and geometry: - if stats: print "[%d/%d]" % stats, - print "Reusing image info from cache...", geometry, "DARK" if dark else "LIGHT" + if stats: print("[%d/%d]" % stats, end=' ') + print("Reusing image info from cache...", geometry, "DARK" if dark else "LIGHT") if geometry is None: if options.verbose: - if stats: print "[%d/%d]" % stats, - print "Extracting image info..." + if stats: print("[%d/%d]" % stats, end=' ') + print("Extracting image info...") w,h = _IM_get_image_size(img, magick_args[0]) qresize = '%dx%d!' % ((options.quantum,)*2) if options.verbose: - print "%s %dx%d %dmp R=%0.2f" % (img, w, h, int(w*h/1000000.0+0.5), float(w)/h) + print("%s %dx%d %dmp R=%0.2f" % (img, w, h, int(w*h/1000000.0+0.5), float(w)/h)) if '/' in options.ratio: tmp = options.ratio.split('/') @@ -547,14 +547,14 @@ def compose_calendar(img, outimg, options, callirhoe_args, magick_args, stats=No '-compose', 'multiply', img, '-composite', '-region', '%dx%d+%d+%d' % geometry, '-negate', outimg]) elif options.test == 'print': - print ' '.join(map(str,geometry)) + print(' '.join(map(str,geometry))) elif options.test == 'crop': subprocess.call([_prog_im, img] + magick_args[0] + ['-crop', '%dx%d+%d+%d' % geometry, outimg]) return # generate callirhoe calendar - if options.verbose: print "Generating calendar image (%s) ... [&]" % options.style + if options.verbose: print("Generating calendar image (%s) ... [&]" % options.style) if not options.vanilla: callirhoe_args = callirhoe_args + ['--no-footer', '--border=0'] calimg = mktemp('.png') try: @@ -562,14 +562,14 @@ def compose_calendar(img, outimg, options, callirhoe_args, magick_args, stats=No if dark is None: # measure luminance - if options.verbose: print "Measuring luminance...", + if options.verbose: print("Measuring luminance...", end=' ') if options.negative > 0 and options.negative < 255: luma = _IM_get_image_luminance(img, magick_args[0], geometry) - if options.verbose: print "(%s)" % luma, + if options.verbose: print("(%s)" % luma, end=' ') else: luma = 255 - options.negative dark = luma < options.negative - if options.verbose: print "DARK" if dark else "LIGHT" + if options.verbose: print("DARK" if dark else "LIGHT") if cache is not None: with _mutex: cache[img] = (geometry, dark) @@ -578,7 +578,7 @@ def compose_calendar(img, outimg, options, callirhoe_args, magick_args, stats=No if pcal.returncode != 0: raise RuntimeError("calmagick: calendar creation failed") # perform final composition - if options.verbose: print "Composing overlay (%s)..." % outimg + if options.verbose: print("Composing overlay (%s)..." % outimg) overlay = ['(', '-negate', calimg, ')'] if dark else [calimg] subprocess.call([_prog_im, img] + magick_args[0] + ['-region', '%dx%d+%d+%d' % geometry] + ([] if options.brightness == 0 else ['-brightness-contrast', '%d' % (-options.brightness if dark else options.brightness)]) + @@ -602,7 +602,7 @@ def parse_range(s,hint=None): if hint and span == 0: span = hint year = lib.parse_year(t[1]) margs = [] - for m in xrange(span): + for m in range(span): margs += [(month,year)] month += 1 if month > 12: month = 1; year += 1 @@ -626,7 +626,7 @@ def range_worker(q,ev,i): try: compose_calendar(*item) except Exception as e: - print >> sys.stderr, "Exception in Thread-%d: %s" % (i,e.args) + print("Exception in Thread-%d: %s" % (i,e.args), file=sys.stderr) ev.set() finally: q.task_done() @@ -655,14 +655,14 @@ def main_program(): if options.range: flist = sorted(glob.glob(args[0])) mrange = parse_range(options.range,hint=len(flist)) - if options.verbose: print "Composing %d photos..." % len(mrange) + if options.verbose: print("Composing %d photos..." % len(mrange)) if options.sample is not None: flist = random.sample(flist, options.sample if options.sample else min(len(mrange),len(flist))) nf = len(flist) if nf > 0: if len(mrange) > nf and options.prefix == 'no?': options.prefix = 'yes' if options.jobs > 1: - q = Queue.Queue() + q = queue.Queue() ev = threading.Event() for i in range(options.jobs): t = threading.Thread(target=range_worker,args=(q,ev,i)) diff --git a/geom/sloppy.py b/geom/sloppy.py index 959a701..fdf80e8 100644 --- a/geom/sloppy.py +++ b/geom/sloppy.py @@ -18,7 +18,7 @@ """module defining the sloppy geometry""" -import default +from . import default class dom(default.dom): pass diff --git a/lang/DE.py b/lang/DE.py index 4ad3923..7251f98 100644 --- a/lang/DE.py +++ b/lang/DE.py @@ -19,18 +19,18 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see http://www.gnu.org/licenses/ -long_day_name = [ u'Montag', u'Dienstag', u'Mittwoch', - u'Donnerstag', u'Freitag', u'Samstag', u'Sonntag' ] +long_day_name = [ 'Montag', 'Dienstag', 'Mittwoch', + 'Donnerstag', 'Freitag', 'Samstag', 'Sonntag' ] -short_day_name = [ u'Mo', u'Di', u'Mi', u'Do', u'Fr', u'Sa', u'So' ] +short_day_name = [ 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa', 'So' ] long_month_name = [ '', - u'Januar', u'Februar', u'März', u'April', - u'Mai', u'Juni', u'Juli', u'August', - u'September', u'Oktober', u'November', u'Dezember' ] + 'Januar', 'Februar', 'März', 'April', + 'Mai', 'Juni', 'Juli', 'August', + 'September', 'Oktober', 'November', 'Dezember' ] short_month_name = [ '', - u'Jan', u'Feb', u'Mrz', u'Apr', u'Mai', u'Jun', - u'Jul', u'Aug', u'Sep', u'Okt', u'Nov', u'Dez' ] + 'Jan', 'Feb', 'Mrz', 'Apr', 'Mai', 'Jun', + 'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dez' ] -week_of_year_prefix = u'W' +week_of_year_prefix = 'W' diff --git a/lang/EL.py b/lang/EL.py index 8eebeb3..08363cc 100644 --- a/lang/EL.py +++ b/lang/EL.py @@ -18,16 +18,16 @@ """Greek language definition file""" -long_day_name = [ u'Δευτέρα', u'Τρίτη', u'Τετάρτη', - u'Πέμπτη', u'Παρασκευή', u'Σάββατο', u'Κυριακή' ] +long_day_name = [ 'Δευτέρα', 'Τρίτη', 'Τετάρτη', + 'Πέμπτη', 'Παρασκευή', 'Σάββατο', 'Κυριακή' ] -short_day_name = [ u'Δε', u'Τρ', u'Τε', u'Πε', u'Πα', u'Σα', u'Κυ' ] +short_day_name = [ 'Δε', 'Τρ', 'Τε', 'Πε', 'Πα', 'Σα', 'Κυ' ] -long_month_name = [ '', u'Ιανουάριος', u'Φεβρουάριος', u'Μάρτιος', u'Απρίλιος', - u'Μάιος', u'Ιούνιος', u'Ιούλιος', u'Αύγουστος', - u'Σεπτέμβριος', u'Οκτώβριος', u'Νοέμβριος', u'Δεκέμβριος' ] +long_month_name = [ '', 'Ιανουάριος', 'Φεβρουάριος', 'Μάρτιος', 'Απρίλιος', + 'Μάιος', 'Ιούνιος', 'Ιούλιος', 'Αύγουστος', + 'Σεπτέμβριος', 'Οκτώβριος', 'Νοέμβριος', 'Δεκέμβριος' ] -short_month_name = [ '', u'Ιαν', u'Φεβ', u'Μαρ', u'Απρ', u'Μαϊ', u'Ιον', u'Ιολ', - u'Αυγ', u'Σεπ', u'Οκτ', u'Νοε', u'Δεκ' ] +short_month_name = [ '', 'Ιαν', 'Φεβ', 'Μαρ', 'Απρ', 'Μαϊ', 'Ιον', 'Ιολ', + 'Αυγ', 'Σεπ', 'Οκτ', 'Νοε', 'Δεκ' ] -week_of_year_prefix = u'Ε' +week_of_year_prefix = 'Ε' diff --git a/lang/EN.py b/lang/EN.py index 7a671b6..31df3b5 100644 --- a/lang/EN.py +++ b/lang/EN.py @@ -18,18 +18,18 @@ """English language definition file""" -long_day_name = [ u'Monday', u'Tuesday', u'Wednesday', - u'Thursday', u'Friday', u'Saturday', u'Sunday' ] +long_day_name = [ 'Monday', 'Tuesday', 'Wednesday', + 'Thursday', 'Friday', 'Saturday', 'Sunday' ] -short_day_name = [ u'Mo', u'Tu', u'We', u'Th', u'Fr', u'Sa', u'Su' ] +short_day_name = [ 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa', 'Su' ] long_month_name = [ '', - u'January', u'February', u'March', u'April', - u'May', u'June', u'July', u'August', - u'September', u'October', u'November', u'December' ] + 'January', 'February', 'March', 'April', + 'May', 'June', 'July', 'August', + 'September', 'October', 'November', 'December' ] short_month_name = [ '', - u'Jan', u'Feb', u'Mar', u'Apr', u'May', u'Jun', - u'Jul', u'Aug', u'Sep', u'Oct', u'Nov', u'Dec' ] + 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', + 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ] -week_of_year_prefix = u'W' +week_of_year_prefix = 'W' diff --git a/lang/FR.py b/lang/FR.py index 0e73290..8a7e332 100644 --- a/lang/FR.py +++ b/lang/FR.py @@ -18,17 +18,17 @@ """French language definition file""" -long_day_name = [ u'Lundi', u'Mardi', u'Mercredi', - u'Jeudi', u'Vendredi', u'Samedi', u'Dimanche' ] +long_day_name = [ 'Lundi', 'Mardi', 'Mercredi', + 'Jeudi', 'Vendredi', 'Samedi', 'Dimanche' ] -short_day_name = [ u'Lu', u'Ma', u'Me', u'Je', u'Ve', u'Sa', u'Di' ] +short_day_name = [ 'Lu', 'Ma', 'Me', 'Je', 'Ve', 'Sa', 'Di' ] long_month_name = [ '', - u'Janvier', u'Février', u'Mars', u'Avril', - u'Mai', u'Juin', u'Juillet', u'Août', - u'Septembre', u'Octobre', u'Novembre', u'Décembre' ] + 'Janvier', 'Février', 'Mars', 'Avril', + 'Mai', 'Juin', 'Juillet', 'Août', + 'Septembre', 'Octobre', 'Novembre', 'Décembre' ] -short_month_name = [ '', u'Jan', u'Fév', u'Mar', u'Avr', u'Mai', u'Jun', u'Jul', - u'Aoû', u'Sep', u'Oct', u'Nov', u'Déc' ] +short_month_name = [ '', 'Jan', 'Fév', 'Mar', 'Avr', 'Mai', 'Jun', 'Jul', + 'Aoû', 'Sep', 'Oct', 'Nov', 'Déc' ] -week_of_year_prefix = u'S' +week_of_year_prefix = 'S' diff --git a/lang/TR.py b/lang/TR.py index 77491ae..0a38502 100644 --- a/lang/TR.py +++ b/lang/TR.py @@ -19,15 +19,15 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see http://www.gnu.org/licenses/ -long_day_name = [ u'Pazartesi', u'Salı', u' Çarşamba ', - u'Perşembe', u'Cuma', u'Cumartesi', u'Pazar' ] +long_day_name = [ 'Pazartesi', 'Salı', ' Çarşamba ', + 'Perşembe', 'Cuma', 'Cumartesi', 'Pazar' ] -short_day_name = [ u'Pt', u'Sa', u'Ça', u'Pe', u'Cu', u'Ct', u'Pa' ] +short_day_name = [ 'Pt', 'Sa', 'Ça', 'Pe', 'Cu', 'Ct', 'Pa' ] -long_month_name = [ '', u'Ocak', u'Şubat', u'Mart', u'Nisan', - u'Mayıs', u'Haziran', u'Temmuz', u'Ağustos', - u'Eylül', u'Ekim', u'Kasım', u'Aralık' ] +long_month_name = [ '', 'Ocak', 'Şubat', 'Mart', 'Nisan', + 'Mayıs', 'Haziran', 'Temmuz', 'Ağustos', + 'Eylül', 'Ekim', 'Kasım', 'Aralık' ] short_month_name = long_month_name -week_of_year_prefix = u'H' +week_of_year_prefix = 'H' diff --git a/layouts/_base.py b/layouts/_base.py index 3aa8f7c..facb77c 100644 --- a/layouts/_base.py +++ b/layouts/_base.py @@ -241,7 +241,7 @@ class CalendarRenderer(object): try: page = PageWriter(self.Outfile, G.pagespec, not self.options.opaque, G.landscape, G.border) except InvalidFormat as e: - print >> sys.stderr, "invalid output format", e.args[0] + print("invalid output format", e.args[0], file=sys.stderr) sys.exit(1) if rows == 0 and cols == 0: @@ -277,9 +277,9 @@ class CalendarRenderer(object): cur_year = self.Year num_placed = 0 page_layout = [] - for k in xrange(num_pages): + for k in range(num_pages): page_layout.append([]) - for i in xrange(mpp): + for i in range(mpp): page_layout[k].append((cur_month,cur_year)) num_placed += 1 cur_month += 1 diff --git a/layouts/bars.py b/layouts/bars.py index 52910a5..66fbc56 100644 --- a/layouts/bars.py +++ b/layouts/bars.py @@ -24,7 +24,7 @@ import optparse import sys from datetime import date, timedelta -import _base +from . import _base parser = _base.get_parser(__name__) parser.set_defaults(rows=2) @@ -36,7 +36,7 @@ class CalendarRenderer(_base.CalendarRenderer): make_sloppy_rect(cr, rect, G.month.sloppy_dx, G.month.sloppy_dy, G.month.sloppy_rot) day, span = calendar.monthrange(year, month) - mmeasure = 'A'*max(map(len,L.month_name)) + mmeasure = 'A'*max(list(map(len,L.month_name))) if self.options.month_with_year: mmeasure += 'A'*(len(str(year))+1) diff --git a/layouts/classic.py b/layouts/classic.py index 4b0d887..3fd286f 100644 --- a/layouts/classic.py +++ b/layouts/classic.py @@ -23,7 +23,7 @@ import calendar import sys from datetime import date, timedelta -import _base +from . import _base parser = _base.get_parser(__name__) parser.add_option("--phantom-days", action="store_true", default=False, @@ -53,8 +53,8 @@ class CalendarRenderer(_base.CalendarRenderer): day, span = calendar.monthrange(year, month) weekrows = 6 if G.month.symmetric else _weekrows_of_month(year, month) dom = -day + 1; - wmeasure = 'A'*max(map(len,L.day_name)) - mmeasure = 'A'*max(map(len,L.month_name)) + wmeasure = 'A'*max(list(map(len,L.day_name))) + mmeasure = 'A'*max(list(map(len,L.month_name))) if self.options.month_with_year: mmeasure += 'A'*(len(str(year))+1) diff --git a/layouts/sparse.py b/layouts/sparse.py index 8305d48..535db94 100644 --- a/layouts/sparse.py +++ b/layouts/sparse.py @@ -27,7 +27,7 @@ import optparse import sys from datetime import date, timedelta -import _base +from . import _base # TODO: merge with base parser... def get_parser(layout_name): @@ -139,8 +139,8 @@ class CalendarRenderer(_base.CalendarRenderer): make_sloppy_rect(cr, rect, G.month.sloppy_dx, G.month.sloppy_dy, G.month.sloppy_rot) day, span = calendar.monthrange(year, month) - wmeasure = 'A'*max(map(len,L.day_name)) - mmeasure = 'A'*max(map(len,L.month_name)) + wmeasure = 'A'*max(list(map(len,L.day_name))) + mmeasure = 'A'*max(list(map(len,L.month_name))) rows = 31 if G.month.symmetric else span grid = VLayout(rect_from_origin(rect), 32) # title bar always symmetric diff --git a/lib/geom.py b/lib/geom.py index d7d5139..3e253ee 100644 --- a/lib/geom.py +++ b/lib/geom.py @@ -124,7 +124,7 @@ def color_mix(a, b, frac): @param frac: amount of first color @rtype: tuple """ - return map(lambda (x,y): x*frac + y*(1 - frac), zip(a,b)) + return [x_y[0]*frac + x_y[1]*(1 - frac) for x_y in zip(a,b)] def color_scale(a, frac): """scale color values @@ -133,7 +133,7 @@ def color_scale(a, frac): @param frac: scale amount (to be multiplied) @rtype: tuple """ - return map(lambda x: min(1.0,x*frac), a) + return [min(1.0,x*frac) for x in a] def color_auto_fg(bg, light = (1,1,1), dark = (0,0,0)): """return I{light} or I{dark} foreground color based on an ad-hoc evaluation of I{bg} @@ -196,7 +196,7 @@ class VLayout(object): @rtype: (float,float,float,float),... """ - return map(self.item, range(self.count())) + return list(map(self.item, list(range(self.count())))) class HLayout(VLayout): """horizontal layout manager defined as a transpose of L{VLayout}""" @@ -282,21 +282,21 @@ class GLayout(object): @rtype: (float,float,float,float),... """ - return map(self.item_seq, range(self.count())) + return list(map(self.item_seq, list(range(self.count())))) def row_items(self, row): """get sequence of cell rects of a row @rtype: (float,float,float,float),... """ - return map(lambda x: self.item(row, x), range(self.col_count())) + return [self.item(row, x) for x in range(self.col_count())] def col_items(self, col): """get sequence of cell rects of a column @rtype: (float,float,float,float),... """ - return map(lambda x: self.item(x, col), range(self.row_count())) + return [self.item(x, col) for x in range(self.row_count())] def item_span(self, nr, nc, row = -1, col = -1): diff --git a/lib/holiday.py b/lib/holiday.py index f3d4fdd..d8b4f49 100644 --- a/lib/holiday.py +++ b/lib/holiday.py @@ -59,7 +59,7 @@ def _strip_empty(sl): @rtype: [str,...] """ - return filter(lambda z: z, sl) if sl else [] + return [z for z in sl if z] if sl else [] def _flatten(sl): """join list I{sl} into a comma-separated string @@ -281,8 +281,7 @@ class HolidayProvider(object): footer_tuple = (footer, None, footer, None) else: footer_tuple = (None, None, None, None) - return tuple(map(lambda k: Holiday([header_tuple[k]], [footer_tuple[k]], flags), - range(4))) + return tuple([Holiday([header_tuple[k]], [footer_tuple[k]], flags) for k in range(4)]) def load_holiday_file(self, filename): """load a holiday file into the C{HolidayProvider} object @@ -386,7 +385,7 @@ class HolidayProvider(object): if not dt in self.cache: self.cache[dt] = Holiday() self.cache[dt].merge_with(self.monthly[m0]) # fixed - for dt in filter(lambda z: z.year == y, self.fixed): + for dt in [z for z in self.fixed if z.year == y]: if not dt in self.cache: self.cache[dt] = Holiday() self.cache[dt].merge_with(self.fixed[dt]) # orthodox easter @@ -454,5 +453,5 @@ if __name__ == '__main__': while cur <= d2: y,m,d = cur.year, cur.month, cur.day hol = hp.get_holiday(y,m,d) - if hol: print cur.strftime("%a %b %d %Y"),hol + if hol: print(cur.strftime("%a %b %d %Y"),hol) cur += timedelta(1) diff --git a/lib/xcairo.py b/lib/xcairo.py index 774ce3d..68bd5da 100644 --- a/lib/xcairo.py +++ b/lib/xcairo.py @@ -26,14 +26,14 @@ import cairo import math import random from os.path import splitext -from geom import * +from .geom import * XDPI = 72.0 """dots per inch of output device""" # decreasing order # [1188, 840, 594, 420, 297, 210, 148, 105, 74, 52, 37] -ISOPAGE = map(lambda x: int(210*math.sqrt(2)**x+0.5), range(5,-6,-1)) +ISOPAGE = [int(210*math.sqrt(2)**x+0.5) for x in range(5,-6,-1)] """ISO page height list, index k for height of Ak paper""" def page_spec(spec = None): diff --git a/scripts/make_resources_list.py b/scripts/make_resources_list.py index 1b17b1d..c5d43e1 100644 --- a/scripts/make_resources_list.py +++ b/scripts/make_resources_list.py @@ -6,6 +6,6 @@ res = dict() for x in ['lang', 'style', 'layouts', 'geom']: res[x] = glob.glob('%s/*.py' % x) -print 'resource_list = {}' -for x in res.keys(): - print 'resource_list["%s"] = %s' % (x, str(res[x])) +print('resource_list = {}') +for x in list(res.keys()): + print('resource_list["%s"] = %s' % (x, str(res[x]))) diff --git a/style/bw_gfs.py b/style/bw_gfs.py index d26f98a..bbcbeca 100644 --- a/style/bw_gfs.py +++ b/style/bw_gfs.py @@ -18,7 +18,7 @@ """module defining Greek Font Society fonts for black & white style""" -import bw as base +from . import bw as base # day of week class dow(base.dow): diff --git a/style/bw_sparse_gfs.py b/style/bw_sparse_gfs.py index ad06013..e47d82a 100644 --- a/style/bw_sparse_gfs.py +++ b/style/bw_sparse_gfs.py @@ -18,7 +18,7 @@ """module defining Greek Font Society fonts for black & white sparse style""" -import bw_sparse as base +from . import bw_sparse as base # day of week class dow(base.dow): diff --git a/style/gfs.py b/style/gfs.py index 573eb94..b19ab81 100644 --- a/style/gfs.py +++ b/style/gfs.py @@ -18,7 +18,7 @@ """module defining Greek Font Society fonts for default style""" -import default +from . import default # day of week class dow(default.dow): diff --git a/style/rainbow.py b/style/rainbow.py index 8c8a083..0800900 100644 --- a/style/rainbow.py +++ b/style/rainbow.py @@ -18,7 +18,7 @@ """module defining rainbow color style""" -import default +from . import default # day of week class dow(default.dow): pass @@ -52,6 +52,6 @@ class month(default.month): color_mix(spring,summer,0.66), color_mix(spring,summer,0.33), summer, # july color_mix(summer,autumn,0.66), color_mix(summer,autumn,0.33), autumn, # october color_mix(autumn,winter,0.66), color_mix(autumn,winter,0.33)) # december - color_map_bg = (map(lambda x: color_scale(x, 0.5), _c1), _c1) + color_map_bg = ([color_scale(x, 0.5) for x in _c1], _c1) color_map_fg = (((1,1,1),)*13, ((0,0,0),)*13) # map(lambda x: color_auto_fg(x), color_map_bg[1] diff --git a/style/rainbow_gfs.py b/style/rainbow_gfs.py index ea2d42a..fd6ed17 100644 --- a/style/rainbow_gfs.py +++ b/style/rainbow_gfs.py @@ -18,7 +18,7 @@ """module defining rainbow color & gfs style""" -import gfs +from . import gfs # day of week class dow(gfs.dow): pass @@ -52,6 +52,6 @@ class month(gfs.month): color_mix(spring,summer,0.66), color_mix(spring,summer,0.33), summer, # july color_mix(summer,autumn,0.66), color_mix(summer,autumn,0.33), autumn, # october color_mix(autumn,winter,0.66), color_mix(autumn,winter,0.33)) # december - color_map_bg = (map(lambda x: color_scale(x, 0.5), _c1), _c1) + color_map_bg = ([color_scale(x, 0.5) for x in _c1], _c1) color_map_fg = (((1,1,1),)*13, ((0,0,0),)*13) # map(lambda x: color_auto_fg(x), color_map_bg[1] diff --git a/style/transparent_gfs.py b/style/transparent_gfs.py index cbbf0d5..2a11b6b 100644 --- a/style/transparent_gfs.py +++ b/style/transparent_gfs.py @@ -18,7 +18,7 @@ """module defining Greek Font Society fonts for transparent style""" -import transparent as base +from . import transparent as base # day of week class dow(base.dow):