changeset 6:9ce41ef66dfa

python 3 port
author Goffi <goffi@goffi.org>
date Sat, 05 Oct 2019 01:26:51 +0200
parents 9ab2f5b872c7
children b5fc67c97c50
files pages/association/membership/page_meta.py pages/association/page_meta.py pages/documentation/page_meta.py pages/news/page_meta.py pages/presentation/page_meta.py pages/press/page_meta.py pages/social_contract/page_meta.py tasks/task_generate_doc.py tasks/task_social_contract.py
diffstat 9 files changed, 65 insertions(+), 65 deletions(-) [+]
line wrap: on
line diff
--- a/pages/association/membership/page_meta.py	Fri Jun 28 17:44:55 2019 +0200
+++ b/pages/association/membership/page_meta.py	Sat Oct 05 01:26:51 2019 +0200
@@ -12,8 +12,8 @@
 
 log = getLogger(__name__)
 
-name = u"association_membership"
-template = u"association/membership.html"
+name = "association_membership"
+template = "association/membership.html"
 
 FIELDS = (
     'name',
@@ -30,16 +30,16 @@
 REQUIRED = ('name', 'firstname', 'address', 'email', 'subscription')
 FormData = namedtuple("FormData", FIELDS)
 
-SUBJECT_ADMIN = D_(u"New subscription to the association")
-BODY_ADMIN = D_(u"""\
+SUBJECT_ADMIN = D_("New subscription to the association")
+BODY_ADMIN = D_("""\
 New subscription received:
 
 {fields_list}""").format(
-    fields_list=u"\n".join(u"- {0}: {{{0}}}".format(f) for f in FIELDS)
+    fields_list="\n".join("- {0}: {{{0}}}".format(f) for f in FIELDS)
     )
 
-SUBJECT = D_(u"Your association membership request")
-BODY = D_(u"""\
+SUBJECT = D_("Your association membership request")
+BODY = D_("""\
 Hello {firstname},
 
 you request to join the "Salut à Toi" association has been well received.
@@ -48,8 +48,8 @@
 You can contact us at contact"""
 # we split the address to avoid
 # it being recognized too easily by spam bots
-+ u'@' + u'salut-a-toi' + u'.org'
-u"""
++ '@' + 'salut-a-toi' + '.org'
+"""
 or on the official XMPP chat room:
 xmpp: sat@chat.jabberfr.org
 web: https://chat.jabberfr.org/converse.js/sat@chat.jabberfr.org
@@ -58,19 +58,19 @@
 """)
 
 WARNING_MSG_NOT_READ = D_(
-    u"You must have read the documents to validate your membership request")
+    "You must have read the documents to validate your membership request")
 WARNING_MSG_MISSING_FIELDS = D_(
-    u"The form you posted is not complete, we can't validate this membership request.\n"
-    u"Please fill all the required fields, thank you!")
+    "The form you posted is not complete, we can't validate this membership request.\n"
+    "Please fill all the required fields, thank you!")
 
 @defer.inlineCallbacks
 def on_data_post(self, request):
     data = FormData(*self.getPostedData(request, FIELDS, raise_on_missing=False))
     if any(not getattr(data, f) for f in REQUIRED):
-        log.warning(u"missing data fields:\n{data}".format(data=data))
+        log.warning("missing data fields:\n{data}".format(data=data))
         raise exceptions.DataError(WARNING_MSG_MISSING_FIELDS)
     if not C.bool(data.documents_read or C.BOOL_FALSE):
-        log.warning(u"documents_read has not been checked:\n{data}".format(data=data))
+        log.warning("documents_read has not been checked:\n{data}".format(data=data))
         raise exceptions.DataError(WARNING_MSG_NOT_READ)
     addresses = config.getConfig(
         self.host.main_conf,
--- a/pages/association/page_meta.py	Fri Jun 28 17:44:55 2019 +0200
+++ b/pages/association/page_meta.py	Sat Oct 05 01:26:51 2019 +0200
@@ -5,5 +5,5 @@
 
 log = getLogger(__name__)
 
-name = u"association"
-template = u"association/association.html"
+name = "association"
+template = "association/association.html"
--- a/pages/documentation/page_meta.py	Fri Jun 28 17:44:55 2019 +0200
+++ b/pages/documentation/page_meta.py	Sat Oct 05 01:26:51 2019 +0200
@@ -6,8 +6,8 @@
 
 log = getLogger(__name__)
 
-name = u"documentation"
-template = u"doc/doc.html"
+name = "documentation"
+template = "doc/doc.html"
 
 allowed_docs = None
 
@@ -20,18 +20,18 @@
     if allowed_docs is None:
         allowed_docs = sorted(self.getConfig("sub_docs_dict", {}).keys())
         try:
-            allowed_docs.remove(u'sat')
+            allowed_docs.remove('sat')
         except KeyError:
-            log.error(u"sat doc not available")
+            log.error("sat doc not available")
         else:
-            allowed_docs.insert(0, u"sat")
+            allowed_docs.insert(0, "sat")
     try:
         doc_name = self.nextPath(request)
     except IndexError:
-        doc_name = u'sat'
+        doc_name = 'sat'
     else:
         if doc_name not in allowed_docs:
-            log.warning(_(u"unknown doc name: {doc_name}").format(doc_name=doc_name))
-            doc_name = u'sat'
-    template_data[u'doc_name'] = doc_name
-    template_data[u'all_docs'] = allowed_docs
+            log.warning(_("unknown doc name: {doc_name}").format(doc_name=doc_name))
+            doc_name = 'sat'
+    template_data['doc_name'] = doc_name
+    template_data['all_docs'] = allowed_docs
--- a/pages/news/page_meta.py	Fri Jun 28 17:44:55 2019 +0200
+++ b/pages/news/page_meta.py	Sat Oct 05 01:26:51 2019 +0200
@@ -9,8 +9,8 @@
 
 log = getLogger(__name__)
 
-name = u"news"
-template = u"news/news.html"
+name = "news"
+template = "news/news.html"
 service = None
 node = None
 
@@ -19,28 +19,28 @@
 def prepare_render(self, request):
     global service, node
     if service is None:
-        blog_dict = self.getConfig(u'news_blog_dict', {})
+        blog_dict = self.getConfig('news_blog_dict', {})
         try:
             service = jid.JID(blog_dict['service'])
         except RuntimeError as e:
-            log.warning(_(u"Can't parse service in news_blog_dict: {e}").format(e=e))
+            log.warning(_("Can't parse service in news_blog_dict: {e}").format(e=e))
             service = None
         except KeyError:
-            log.warnning(_(u"Missing service in news_blog_dict"))
+            log.warnning(_("Missing service in news_blog_dict"))
             service = None
-        node = blog_dict.get('node', u'')
+        node = blog_dict.get('node', '')
         if not blog_dict or service is None:
-            log.warning(_(u'No value set for news_blog_dict, "news" page can\'t be used'))
+            log.warning(_('No value set for news_blog_dict, "news" page can\'t be used'))
             self.pageError(request, C.HTTP_SERVICE_UNAVAILABLE)
 
     data = self.getRData(request)
-    data[u'service'] = service
-    data[u'node'] = node
+    data['service'] = service
+    data['node'] = node
 
     # self.checkCache(
     #     request, C.CACHE_PUBSUB, service=service, node=node, short="microblog")
 
     # we now need blog items, using blog common page
     # this will fill the "items" template data
-    blog_page = self.getPageByName(u"blog_view")
+    blog_page = self.getPageByName("blog_view")
     yield blog_page.prepare_render(self, request)
--- a/pages/presentation/page_meta.py	Fri Jun 28 17:44:55 2019 +0200
+++ b/pages/presentation/page_meta.py	Sat Oct 05 01:26:51 2019 +0200
@@ -5,5 +5,5 @@
 
 log = getLogger(__name__)
 
-name = u"presentation"
-template = u"presentation/presentation.html"
+name = "presentation"
+template = "presentation/presentation.html"
--- a/pages/press/page_meta.py	Fri Jun 28 17:44:55 2019 +0200
+++ b/pages/press/page_meta.py	Sat Oct 05 01:26:51 2019 +0200
@@ -5,5 +5,5 @@
 
 log = getLogger(__name__)
 
-name = u"press"
-template = u"press/press.html"
+name = "press"
+template = "press/press.html"
--- a/pages/social_contract/page_meta.py	Fri Jun 28 17:44:55 2019 +0200
+++ b/pages/social_contract/page_meta.py	Sat Oct 05 01:26:51 2019 +0200
@@ -5,8 +5,8 @@
 from sat.tools.common.template import safe
 from libervia.server import session_iface
 
-name = u"social_contract"
-template = u"social_contract/social_contract.html"
+name = "social_contract"
+template = "social_contract/social_contract.html"
 social_contracts = {}
 
 
@@ -14,10 +14,10 @@
     global social_contracts
     session_data = self.host.getSessionData(request, session_iface.ISATSession)
     if session_data.locale is None:
-        locale = u"en"
+        locale = "en"
     else:
         locale = session_data.locale
-        if u'_' in locale:
+        if '_' in locale:
             locale = locale[:locale.find('_')]
 
     try:
@@ -26,21 +26,21 @@
         # we don't have the document in cache
         build_path = self.host.getBuildPath(self.vhost_root.site_name)
 
-        if locale == u"fr":
+        if locale == "fr":
             # main social contract is in French, so we don't have suffix in this case
-            filename = u"CONTRAT_SOCIAL.html"
+            filename = "CONTRAT_SOCIAL.html"
         else:
-            filename = u"CONTRAT_SOCIAL_{locale}.html".format(locale=locale)
+            filename = "CONTRAT_SOCIAL_{locale}.html".format(locale=locale)
 
         filepath = os.path.join(build_path, filename)
         if not os.path.isfile(filepath):
             # there is not translation for this locale, we use English one as default
-            filename = u"CONTRAT_SOCIAL_en.html"
+            filename = "CONTRAT_SOCIAL_en.html"
             filepath = os.path.join(build_path, filename)
 
         with open(filepath) as f:
-            social_contracts[locale] = safe(f.read().decode('utf-8'))
+            social_contracts[locale] = safe(f.read())
 
         social_contract = social_contracts[locale]
 
-    request.template_data[u"social_contract"] = social_contract
+    request.template_data["social_contract"] = social_contract
--- a/tasks/task_generate_doc.py	Fri Jun 28 17:44:55 2019 +0200
+++ b/tasks/task_generate_doc.py	Sat Oct 05 01:26:51 2019 +0200
@@ -1,4 +1,4 @@
-#!/ur/bin/env python2
+#!/ur/bin/env python3
 
 import os.path
 from twisted.internet import defer
@@ -8,7 +8,7 @@
 log = getLogger(__name__)
 
 WATCH_DIRS = []
-DOC_DIRS_DEFAULT = (u'doc', u'docs')
+DOC_DIRS_DEFAULT = ('doc', 'docs')
 
 
 def prepare(self):
@@ -16,9 +16,9 @@
     doc_path = self.getConfig("doc_path")
     if doc_path is not None:
         to_watch.add(doc_path)
-    sub_docs = self.getConfig("sub_docs_dict", value_type=u"path")
+    sub_docs = self.getConfig("sub_docs_dict", value_type="path")
     if sub_docs is not None:
-        for d in sub_docs.values():
+        for d in list(sub_docs.values()):
             to_watch.add(d)
     global WATCH_DIRS
     WATCH_DIRS = list(to_watch)
@@ -29,7 +29,7 @@
     # root documentation
     doc_path = self.getConfig("doc_path")
     # sub docs will be generated before the root documentation
-    sub_docs = self.getConfig("sub_docs_dict", value_type=u"path")
+    sub_docs = self.getConfig("sub_docs_dict", value_type="path")
 
     if doc_path is None:
         # we check if there is documentation inside the site
@@ -41,21 +41,21 @@
                 break
 
     if doc_path is None and sub_docs is None:
-        log.info(u"No documentation found for {site_name}, skipping".format(
+        log.info("No documentation found for {site_name}, skipping".format(
             site_name = self.site_name))
         return
 
-    sphinx = self.findCommand('sphinx-build2', 'sphinx-build')
+    sphinx = self.findCommand('sphinx-build')
 
     # we first generate the sub documentations
-    for name, sub_doc_path in sub_docs.iteritems():
-        sub_dir = regex.pathEscape(name or u'')
-        build_path = os.path.join(self.build_path, u'doc', sub_dir)
+    for name, sub_doc_path in list(sub_docs.items()):
+        sub_dir = regex.pathEscape(name or '')
+        build_path = os.path.join(self.build_path, 'doc', sub_dir)
         yield self.runCommand(sphinx, sub_doc_path, build_path)
 
     # then the root one
     if doc_path is not None:
-        build_path = os.path.join(self.build_path, u'doc')
+        build_path = os.path.join(self.build_path, 'doc')
         yield self.runCommand(sphinx, doc_path, build_path)
 
-    log.info(_(u"documentation has been generated"))
+    log.info(_("documentation has been generated"))
--- a/tasks/task_social_contract.py	Fri Jun 28 17:44:55 2019 +0200
+++ b/tasks/task_social_contract.py	Sat Oct 05 01:26:51 2019 +0200
@@ -13,9 +13,9 @@
     for filepath in glob.glob(os.path.join(sat_path, "CONTRAT_SOCIAL*")):
         filename = os.path.basename(filepath)
         with open(filepath) as f:
-            md = markdown.markdown(f.read().decode('utf-8'))
+            md = markdown.markdown(f.read())
         build_path = os.path.join(self.build_path, filename + '.html')
         with open(build_path, 'w') as f:
-            f.write(md.encode('utf-8'))
+            f.write(md)
 
-    log.info(_(u"social contract has been converted to  HTML"))
+    log.info(_("social contract has been converted to  HTML"))