File prewikka-fix_python3.patch of Package prewikka

From: Thomas Andrejak <thomas.andrejak@gmail.com>
Date: 2017-10-04 23:25:00 +0100
References: no
Upstream: no
Subject: Python 3 compatibility

--- prewikka/dataprovider/__init__.py	2017-07-18 13:45:57.000000000 +0200
+++ prewikka/dataprovider/__init__.py	2017-10-07 17:10:09.140721871 +0200
@@ -22,12 +22,15 @@
 import copy
 import time
 import types
+import sys
 from datetime import datetime
 
 from prewikka import error, hookmanager, pluginmanager
 from prewikka.utils import AttrObj, CachingIterator, compat, json
 from prewikka.utils.timeutil import parser
 
+if sys.version_info >= (3, 0):
+    long = int
 
 def _str_to_datetime(date):
     if date.isdigit():
--- prewikka/session/session.py	2017-07-18 13:45:57.000000000 +0200
+++ prewikka/session/session.py	2017-10-07 17:13:02.224865916 +0200
@@ -23,6 +23,7 @@
 import os
 import struct
 import time
+import sys
 
 from prewikka import database, hookmanager, log, pluginmanager, usergroup, utils
 from prewikka.error import PrewikkaUserError, RedirectionError
@@ -137,7 +138,11 @@
         t = time.time()
 
         self._db.delete_expired_sessions(t - self._expiration)
-        sessionid = text_type(binascii.hexlify(os.urandom(16) + struct.pack(b">d", t)))
+        sessionid = binascii.hexlify(os.urandom(16) + struct.pack(b">d", t))
+        if sys.version_info >= (3, 0):
+            sessionid = sessionid.decode('ascii')
+
+        sessionid = text_type(sessionid)
 
         self._db.create_session(sessionid, user, int(t))
         self.__set_session(request, sessionid)
--- prewikka/utils/json.py	2017-07-18 13:45:57.000000000 +0200
+++ prewikka/utils/json.py	2017-10-07 17:14:59.718248149 +0200
@@ -21,6 +21,7 @@
 
 import datetime
 import json
+from six import with_metaclass
 
 from prewikka.utils import html
 
@@ -36,8 +37,7 @@
         return nclass
 
 
-class JSONObject(object):
-    __metaclass__ = _JSONMetaClass
+class JSONObject(with_metaclass(_JSONMetaClass, object)):
 
     def __jsonobj__(self):
         return { "__prewikka_class__": (self.__class__.__name__, self.__json__()) }
--- prewikka/utils/url.py	2017-07-18 13:45:57.000000000 +0200
+++ prewikka/utils/url.py	2017-10-07 17:16:41.927970738 +0200
@@ -56,7 +56,11 @@
     else:
         authority = tpl[0].encode('idna') + ":%s" % tpl[1]
 
-    return urlunsplit((scheme.encode(encoding), authority,
+    sc = scheme.encode(encoding)
+    if sys.version_info >= (3, 0):
+        sc = quote(sc, safe)
+
+    return urlunsplit((sc, authority,
                        quote(path.encode(encoding), safe),
                        quote(query.encode(encoding), safe),
                        quote(frag.encode(encoding), safe)))
--- prewikka/web/request.py	2017-07-18 13:45:57.000000000 +0200
+++ prewikka/web/request.py	2017-10-07 17:21:21.645737400 +0200
@@ -40,7 +40,11 @@
                 self._buffersize = buffersize
 
         def flush(self):
-                self._wcb(''.join(self._dlist))
+                if sys.version_info >= (3, 0):
+                    self._wcb(''.join((x.decode('utf-8') for x in self._dlist)).encode('utf-8'))
+                else:
+                    self._wcb(''.join(self._dlist))
+
                 self._dlist = []
                 self._len = 0
 
@@ -97,10 +101,16 @@
         # Join is used in place of concatenation / formatting, because we
         # prefer performance over readability in this place
         if event:
-            self._buffer.write("".join(["event: ", event.encode("utf8"), "\n"]))
+            if sys.version_info >= (3, 0):
+                self._buffer.write("".join(["event: ", text_type(event), "\n"]).encode("utf8"))
+            else:
+                self._buffer.write("".join(["event: ", event.encode('utf-8'), "\n"]))
 
         if data:
-            self._buffer.write("".join(["data: ", data.encode("utf8"), "\n\n"]))
+            if sys.version_info >= (3, 0):
+                self._buffer.write("".join(["data: ", text_type(data), "\n\n"]).encode("utf8"))
+            else:
+                self._buffer.write("".join(["data: ", data.encode('utf-8'), "\n\n"]))
 
         if sync:
             self._buffer.flush()
openSUSE Build Service is sponsored by