]> git.phdru.name Git - m_lib.git/blobdiff - m_lib/net/www/util.py
Use print function for Py3 compatibility
[m_lib.git] / m_lib / net / www / util.py
index 28b8f09eb8799b347e8319799a2421d24d2de6d2..40021b79679740aa588454a7b86c039b0b6c77b2 100644 (file)
@@ -1,21 +1,22 @@
-"Common WWW/CGI utilities"
+"""Common WWW/CGI utilities"""
 
 
+from __future__ import print_function
 import sys, os
 
 
 def exception(str = ""):
    if sys.exc_type == SystemExit: # pass exit() normally
       return
-   print "Content-Type: text/html"
-   print # Terminate HTTP headers
+
+   # Add the second linefeed to terminate HTTP headers
+   print("Content-Type: text/html\n")
 
    import html
-   print html.exception()
+   print(html.exception())
 
    if str:
-      print str
+      print(str)
 
    sys.exit(1)
 
@@ -24,10 +25,10 @@ def error(err_str):
    if not err_str:
       err_str = "Unknown error"
 
-   print "Content-Type: text/html"
-   print # Terminate HTTP headers
+   # Add the second linefeed to terminate HTTP headers
+   print("Content-Type: text/html\n")
 
-   print str(err_str)
+   print(str(err_str))
    sys.exit(1)
 
 
@@ -52,7 +53,7 @@ def convert_empty(estr):
 
 
 def gen_html(title, body):
-   print """
+   print("""
    <HTML>
       <HEAD>
          <TITLE>
@@ -64,7 +65,7 @@ def gen_html(title, body):
          %s
       </BODY>
    </HTML>
-   """ % (title, body)
+   """ % (title, body))
 
 
 def mkexpires(hours=1, minutes=0, seconds=0):