Products.CMFPlone/cssmin_relacement: fix unicode problem, fix logger

Alexander Loechel <jenkins-z4DKO/[email protected]>
Newsgroups gmane.comp.web.zope.plone.cvs
Message-ID <[email protected]>
Repository: Products.CMFPlone
Branch: refs/heads/cssmin_relacement
Date: 2017-07-19T23:38:47+02:00
Author: Alexander Loechel (loechel) <[email protected]>
Commit: https://github.com/plone/Products.CMFPlone/commit/3b410dd74878f4a42f424dee5838312153ba4b9e

fix unicode problem, fix logger

Files changed:
M Products/CMFPlone/resources/browser/cook.py

diff --git a/Products/CMFPlone/resources/browser/cook.py b/Products/CMFPlone/resources/browser/cook.py
index a2d1cf0db..a06cec4ac 100644
--- a/Products/CMFPlone/resources/browser/cook.py
+++ b/Products/CMFPlone/resources/browser/cook.py
@@ -18,6 +18,7 @@
 from zope.interface import alsoProvides
 
 import logging
+import sys
 
 
 logger = logging.getLogger('Products.CMFPlone')
@@ -77,7 +78,7 @@ def cookWhenChangingSettings(context, bundle=None):
 
     # Let's join all css and js
     css_compiler = Compiler(output_style='compressed')
-    cooked_css = ''
+    cooked_css = u''
     cooked_js = REQUIREJS_RESET_PREFIX
     siteUrl = getSite().absolute_url()
     request = getRequest()
@@ -91,20 +92,22 @@ def cookWhenChangingSettings(context, bundle=None):
                 css_url = siteUrl + '/' + css_resource
                 response = subrequest(css_url)
                 if response.status == 200:
-                    logger.info('Cooking css {0}'.format(css_resource))
+                    logger.info('Cooking css %s', css_resource)
                     css = response.getBody()
-                    cooked_css += '\n/* Resource: {0} */\n{1}\n'.format(
+                    if css_resource[-8:] != '.min.css':
+                        if sys.version_info == (2):
+                            css = unicode(css)  # Python 2 only function
+                        css = css_compiler.compile_string(css)
+                    cooked_css += u'\n/* Resource: {0} */\n{1}\n'.format(
                         css_resource,
-                        css if '.min.css' == css_resource[-8:] else css_compiler.compile_string(css)  # NOQA: E501
+                        css
                     )
                 else:
                     cooked_css +=\
-                        '\n/* Could not find resource: {0} */\n\n'.format(
+                        u'\n/* Could not find resource: {0} */\n\n'.format(
                             css_resource
                         )
-                    logger.warn(
-                        'Could not find resource: {0}'.format(css_resource)
-                    )
+                    logger.warn('Could not find resource: %s' , css_resource)
         if not resource.js or not js_path:
             continue
         js_url = siteUrl + '/' + resource.js
@@ -112,7 +115,7 @@ def cookWhenChangingSettings(context, bundle=None):
         if response.status == 200:
             js = response.getBody()
             try:
-                logger.info('Cooking js {0}'.format(resource.js))
+                logger.info('Cooking js %s', resource.js)
                 cooked_js += '\n/* resource: {0} */\n{1}'.format(
                     resource.js,
                     js if '.min.js' == resource.js[-7:] else
@@ -124,9 +127,9 @@ def cookWhenChangingSettings(context, bundle=None):
                         resource.js,
                         js
                     )
-                logger.warn('Error cooking resource: {0}'.format(resource.js))
+                logger.warn('Error cooking resource: %s', resource.js)
         else:
-            logger.warn('Could not find resource: {0}'.format(resource.js))
+            logger.warn('Could not find resource: %s', resource.js)
             cooked_js += '\n/* Could not find resource: {0} */\n\n'.format(
                 js_url
             )
@@ -149,11 +152,9 @@ def _write_resource(resource_path, cooked_string):
             folder = container[resource_name]
             fi = StringIO(cooked_string)
             folder.writeFile(resource_filepath, fi)
-            logger.info('Writing cooked resource: {0}'.format(resource_path))
+            logger.info('Writing cooked resource: %s', resource_path)
         except NotFound:
-            logger.warn('Error writing cooked resource: {0}'.format(
-                resource_path)
-            )
+            logger.warn('Error writing cooked resource: %s', resource_path)
 
     _write_resource(js_path, cooked_js)
     _write_resource(css_path, cooked_css)



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.