소스 검색

Merge pull request #910 from diazona/master

[render_math] Fix NameError in Python 3
Justin Mayer 7 년 전
부모
커밋
1a61cd1b31
1개의 변경된 파일11개의 추가작업 그리고 21개의 파일을 삭제
  1. 11 21
      render_math/math.py

+ 11 - 21
render_math/math.py

@@ -45,6 +45,12 @@ try:
 except ImportError as e:
 except ImportError as e:
     PelicanMathJaxExtension = None
     PelicanMathJaxExtension = None
 
 
+try:
+    string_type = basestring
+except NameError:
+    string_type = str
+
+
 def process_settings(pelicanobj):
 def process_settings(pelicanobj):
     """Sets user specified MathJax settings (see README for more details)"""
     """Sets user specified MathJax settings (see README for more details)"""
 
 
@@ -90,10 +96,7 @@ def process_settings(pelicanobj):
         # and 3 of python
         # and 3 of python
 
 
         if key == 'align':
         if key == 'align':
-            try:
-                typeVal = isinstance(value, basestring)
-            except NameError:
-                typeVal = isinstance(value, str)
+            typeVal = isinstance(value, string_type)
 
 
             if not typeVal:
             if not typeVal:
                 continue
                 continue
@@ -122,10 +125,7 @@ def process_settings(pelicanobj):
             mathjax_settings[key] = 'true' if value else 'false'
             mathjax_settings[key] = 'true' if value else 'false'
 
 
         if key == 'latex_preview':
         if key == 'latex_preview':
-            try:
-                typeVal = isinstance(value, basestring)
-            except NameError:
-                typeVal = isinstance(value, str)
+            typeVal = isinstance(value, string_type)
 
 
             if not typeVal:
             if not typeVal:
                 continue
                 continue
@@ -133,10 +133,7 @@ def process_settings(pelicanobj):
             mathjax_settings[key] = value
             mathjax_settings[key] = value
 
 
         if key == 'color':
         if key == 'color':
-            try:
-                typeVal = isinstance(value, basestring)
-            except NameError:
-                typeVal = isinstance(value, str)
+            typeVal = isinstance(value, string_type)
 
 
             if not typeVal:
             if not typeVal:
                 continue
                 continue
@@ -161,19 +158,12 @@ def process_settings(pelicanobj):
 
 
         if key == 'tex_extensions' and isinstance(value, list):
         if key == 'tex_extensions' and isinstance(value, list):
             # filter string values, then add '' to them
             # filter string values, then add '' to them
-            try:
-                value = filter(lambda string: isinstance(string, basestring), value)
-            except NameError:
-                value = filter(lambda string: isinstance(string, str), value)
-
+            value = filter(lambda string: isinstance(string, string_type), value)
             value = map(lambda string: "'%s'" % string, value)
             value = map(lambda string: "'%s'" % string, value)
             mathjax_settings[key] = ',' + ','.join(value)
             mathjax_settings[key] = ',' + ','.join(value)
 
 
         if key == 'mathjax_font':
         if key == 'mathjax_font':
-            try:
-                typeVal = isinstance(value, basestring)
-            except NameError:
-                typeVal = isinstance(value, str)
+            typeVal = isinstance(value, string_type)
 
 
             if not typeVal:
             if not typeVal:
                 continue
                 continue