[gimp-web/migrate/testing: 248/248] plug-ins: fix mirror listing per-country on the Python 3 port.




commit 94583d731fb85492753ea352ab2bcb40de21c7a8
Author: Jehan <jehan girinstud io>
Date:   Tue May 18 15:57:28 2021 +0200

    plug-ins: fix mirror listing per-country on the Python 3 port.
    
    It was mostly just encoding mixup. In Python 3, the string type is
    basically unicode string. That's it. :-)
    
    I think this was the only remnant blocking our port of the website to
    Python 3! \o/

 plugins/gimp_mirrors/gimp_mirrors.py | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
---
diff --git a/plugins/gimp_mirrors/gimp_mirrors.py b/plugins/gimp_mirrors/gimp_mirrors.py
index eff719af..24a720ce 100644
--- a/plugins/gimp_mirrors/gimp_mirrors.py
+++ b/plugins/gimp_mirrors/gimp_mirrors.py
@@ -34,15 +34,16 @@ def html_output( data ):
 
     html = u"<dl class='download-mirrors'>\n"
 
-    for key, values in sorted(data.iteritems()):
+    for key, values in sorted(data.items()):
 
         html += u"<dt>{}</dt>".format( key )
 
         for value in values:
-            if isinstance( value, unicode ):
+            if isinstance(value, str):
+                # In Python3 str are unicode strings.
                 tmp = value
             else:
-                tmp = unicode( value, 'utf_8')
+                tmp = value.decode('utf-8')
             html += u"<dd><a href='{}'>{}</a></dd>\n".format( tmp, tmp )
 
     html += u"</dl>"
@@ -87,12 +88,12 @@ def do_mirrors(path, context):
                         print("cannot resolve record: ", record)
 
                 try:
-                    with open( path, 'r') as f:
+                    with open( path, 'rb') as f:
                         s = f.read()
-                        #print s.decode('utf-8')
-                        s = s.decode('utf-8').replace(u"<!-- MIRRORS -->", html_output( mirrors ))
+                        #print(s.decode('utf-8'))
+                        s = s.decode('utf-8').replace(u"<!-- MIRRORS -->", html_output(mirrors))
 
-                    with open( path, 'w') as f:
+                    with open( path, 'wb') as f:
                         f.write( s.encode('utf-8') )
 
                 except:


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]