Merge pull request #894 from collinanderson/printstderr

sys.stderr.write -> print(msg, file=sys.stderr)
This commit is contained in:
Berker Peksag 2014-09-16 23:03:07 +03:00
commit e0b3c42dd2
5 changed files with 20 additions and 13 deletions

View File

@ -2,6 +2,7 @@
#
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
from __future__ import print_function
import os
import sys
@ -34,7 +35,7 @@ class BaseApplication(object):
self.load_default_config()
self.load_config()
except Exception as e:
sys.stderr.write("\nError: %s\n" % str(e))
print("\nError: %s" % str(e), file=sys.stderr)
sys.stderr.flush()
sys.exit(1)
@ -70,7 +71,7 @@ class BaseApplication(object):
try:
Arbiter(self).run()
except RuntimeError as e:
sys.stderr.write("\nError: %s\n\n" % e)
print("\nError: %s\n" % e, file=sys.stderr)
sys.stderr.flush()
sys.exit(1)
@ -91,8 +92,9 @@ class Application(BaseApplication):
try:
execfile_(filename, cfg, cfg)
except Exception:
print("Failed to read config file: %s" % filename)
print("Failed to read config file: %s" % filename, file=sys.stderr)
traceback.print_exc()
sys.stderr.flush()
sys.exit(1)
return cfg
@ -118,7 +120,8 @@ class Application(BaseApplication):
try:
self.cfg.set(k.lower(), v)
except:
sys.stderr.write("Invalid value for %s: %s\n\n" % (k, v))
print("Invalid value for %s: %s\n" % (k, v), file=sys.stderr)
sys.stderr.flush()
raise
return cfg
@ -162,7 +165,8 @@ class Application(BaseApplication):
try:
self.load()
except:
sys.stderr.write("\nError while loading the application:\n\n")
msg = "\nError while loading the application:\n"
print(msg, file=sys.stderr)
traceback.print_exc()
sys.stderr.flush()
sys.exit(1)

View File

@ -4,6 +4,7 @@
# See the NOTICE for more information.
""" module used to build the django wsgi application """
from __future__ import print_function
import os
import re
@ -36,9 +37,9 @@ def make_wsgi_application():
if get_validation_errors(s):
s.seek(0)
error = s.read()
sys.stderr.write("One or more models did not validate:\n%s" % error)
msg = "One or more models did not validate:\n%s" % error
print(msg, file=sys.stderr)
sys.stderr.flush()
sys.exit(1)
translation.activate(settings.LANGUAGE_CODE)

View File

@ -2,6 +2,7 @@
#
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
from __future__ import print_function
import os
import pkg_resources
@ -155,7 +156,7 @@ class PasterServerApplication(PasterBaseApplication):
if k.lower() in self.cfg.settings and v is not None:
self.cfg.set(k.lower(), v)
except Exception as e:
sys.stderr.write("\nConfig error: %s\n" % str(e))
print("\nConfig error: %s" % str(e), file=sys.stderr)
sys.stderr.flush()
sys.exit(1)

View File

@ -2,6 +2,7 @@
#
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
from __future__ import print_function
import errno
import os
@ -520,8 +521,7 @@ class Arbiter(object):
except AppImportError as e:
self.log.debug("Exception while loading the application: \n%s",
traceback.format_exc())
sys.stderr.write("%s\n" % e)
print("%s" % e, file=sys.stderr)
sys.stderr.flush()
sys.exit(self.APP_LOAD_ERROR)
except:

View File

@ -3,6 +3,7 @@
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
from __future__ import print_function
import email.utils
import fcntl
@ -520,13 +521,13 @@ def is_fileobject(obj):
def warn(msg):
sys.stderr.write("!!!\n")
print("!!!", file=sys.stderr)
lines = msg.splitlines()
for i, line in enumerate(lines):
if i == 0:
line = "WARNING: %s" % line
sys.stderr.write("!!! %s\n" % line)
print("!!! %s" % line, file=sys.stderr)
sys.stderr.write("!!!\n\n")
print("!!!\n", file=sys.stderr)
sys.stderr.flush()