diff --git a/doc/buildweb.py b/doc/buildweb.py index c3ea05e1a..21caefed3 100755 --- a/doc/buildweb.py +++ b/doc/buildweb.py @@ -1,7 +1,7 @@ #!/usr/bin/env python # -*- coding: utf-8 - # -# This file is part of gunicorn released under the MIT license. +# This file is part of gunicorn released under the MIT license. # See the NOTICE for more information. from __future__ import with_statement @@ -21,7 +21,7 @@ from sitemap_gen import CreateSitemapFromFile import conf -class Site(object): +class Site(object): def __init__(self): self.url = conf.SITE_URL.rstrip('/') @@ -47,22 +47,23 @@ def process(self, files, curr_path, tgt_path): if not page.needed(): continue - print "Page: %s" % page.source + print("Page: %s" % page.source) page.write() - + def sass_compile(self): - print "" - print "Updating css..." + print("") + print("Updating css...") try: sp.check_call(["compass", "compile", "--boring"]) except sp.CalledProcessError: - print "Failed to update CSS" - + sys.stderr.write("Failed to update CSS") + sys.stderr.flush() + def get_template(self, name): return self.env.get_template(name) class Page(object): - + def __init__(self, site, filename, curr_path, tgt_path): self.site = site self.filename = filename @@ -72,7 +73,7 @@ def __init__(self, site, filename, curr_path, tgt_path): with open(self.source, 'Ur') as handle: raw = handle.read() - + try: headers, body = raw.split("\n\n", 1) except ValueError: @@ -97,7 +98,7 @@ def __init__(self, site, filename, curr_path, tgt_path): newext = self.headers.get('ext', '.html') self.target = os.path.join(tgt_path, "%s%s" % (basename, newext)) - + def url(self): path = self.target.split(conf.OUTPUT_PATH)[1].lstrip('/') return "/".join([self.site.url, path]) @@ -106,10 +107,10 @@ def needed(self): for f in "force --force -f".split(): if f in sys.argv[1:]: return True - + if not os.path.exists(self.target): return True - + smtime = os.stat(self.source).st_mtime tmtime = os.stat(self.target).st_mtime return smtime > tmtime @@ -141,7 +142,7 @@ def convert_rst(self, body): settings_overrides=overrides ) lines = parts['html_body'].splitlines() - + toppos, botpos = None, None for idx, line in enumerate(lines): if line.find("_TOC_TOP_") >= 0: @@ -174,13 +175,13 @@ def fmt_setting(self, s): val = " ::\n\n" + val else: val = "``%s``" % s.default - + if s.cli and s.meta: args = ["%s %s" % (arg, s.meta) for arg in s.cli] cli = ', '.join(args) elif s.cli: cli = ", ".join(s.cli) - + out = [] out.append("%s" % s.name) out.append("~" * len(s.name)) @@ -196,6 +197,6 @@ def fmt_setting(self, s): def main(): Site().render() - + if __name__ == "__main__": main() diff --git a/doc/sitemap_gen.py b/doc/sitemap_gen.py index f4f28e10e..a48d5405f 100755 --- a/doc/sitemap_gen.py +++ b/doc/sitemap_gen.py @@ -55,8 +55,8 @@ # entire file has been parsed. import sys if sys.hexversion < 0x02020000: - print 'This script requires Python 2.2 or later.' - print 'Currently run with version: %s' % sys.version + print('This script requires Python 2.2 or later.') + print('Currently run with version: %s' % sys.version) sys.exit(1) import fnmatch @@ -291,7 +291,7 @@ def NarrowText(self, text, encoding): # Something is seriously wrong if we get to here return text.encode(ENC_ASCII, 'ignore') #end def NarrowText - + def MaybeNarrowPath(self, text): """ Paths may be allowed to stay wide """ if self._widefiles: @@ -381,7 +381,7 @@ def Log(self, text, level): if text: text = encoder.NarrowText(text, None) if self._verbose >= level: - print text + print(text) #end def Log def Warn(self, text): @@ -391,7 +391,7 @@ def Warn(self, text): hash = hashlib.md5(text).hexdigest() if not self._warns_shown.has_key(hash): self._warns_shown[hash] = 1 - print '[WARNING] ' + text + print('[WARNING] ' + text) else: self.Log('(suppressed) [WARNING] ' + text, 3) self.num_warns = self.num_warns + 1 @@ -404,7 +404,7 @@ def Error(self, text): hash = hashlib.md5(text).hexdigest() if not self._errors_shown.has_key(hash): self._errors_shown[hash] = 1 - print '[ERROR] ' + text + print('[ERROR] ' + text) else: self.Log('(suppressed) [ERROR] ' + text, 3) self.num_errors = self.num_errors + 1 @@ -414,9 +414,9 @@ def Fatal(self, text): """ Output an error and terminate the program. """ if text: text = encoder.NarrowText(text, None) - print '[FATAL] ' + text + print('[FATAL] ' + text) else: - print 'Fatal error.' + print('Fatal error.') sys.exit(1) #end def Fatal @@ -484,7 +484,7 @@ def Canonicalize(loc): """ Do encoding and canonicalization on a URL string """ if not loc: return loc - + # Let the encoder try to narrow it narrow = encoder.NarrowText(loc, None) @@ -545,7 +545,7 @@ def Canonicalize(loc): def Validate(self, base_url, allow_fragment): """ Verify the data in this URL is well-formed, and override if not. """ assert type(base_url) == types.StringType - + # Test (and normalize) the ref if not self.loc: output.Warn('Empty URL') @@ -611,7 +611,7 @@ def MakeHash(self): def Log(self, prefix='URL', level=3): """ Dump the contents, empty or not, to the log. """ out = prefix + ':' - + for attribute in self.__slots__: value = getattr(self, attribute) if not value: @@ -636,7 +636,7 @@ def WriteXML(self, file): value = str(value) value = xml.sax.saxutils.escape(value) out = out + (' <%s>%s\n' % (attribute, value, attribute)) - + out = out + SITEURL_XML_SUFFIX file.write(out) #end def WriteXML @@ -709,7 +709,7 @@ def Apply(self, url): """ Process the URL, as above. """ if (not url) or (not url.loc): return None - + if self._wildcard: if fnmatch.fnmatchcase(url.loc, self._wildcard): return self._pass @@ -738,7 +738,7 @@ def __init__(self, attributes): if not ValidateAttributes('URL', attributes, ('href', 'lastmod', 'changefreq', 'priority')): return - + url = URL() for attr in attributes.keys(): if attr == 'href': @@ -749,7 +749,7 @@ def __init__(self, attributes): if not url.loc: output.Error('Url entries must have an href attribute.') return - + self._url = url output.Log('Input: From URL "%s"' % self._url.loc, 2) #end def __init__ @@ -775,7 +775,7 @@ def __init__(self, attributes): if not ValidateAttributes('URLLIST', attributes, ('path', 'encoding')): return - + self._path = attributes.get('path') self._encoding = attributes.get('encoding', ENC_UTF8) if self._path: @@ -808,7 +808,7 @@ def ProduceURLs(self, consumer): line = line.strip() if (not line) or line[0] == '#': continue - + # Split the line on space url = URL() cols = line.split(' ') @@ -1156,7 +1156,7 @@ class InputSitemap(xml.sax.handler.ContentHandler): """ class _ContextBase(object): - + """Base class for context handlers in our SAX processing. A context handler is a class that is responsible for understanding one level of depth in the XML schema. The class knows what sub-tags are allowed, @@ -1165,7 +1165,7 @@ class _ContextBase(object): This base class is the API filled in by specific context handlers, all defined below. """ - + def __init__(self, subtags): """Initialize with a sequence of the sub-tags that would be valid in this context.""" @@ -1209,18 +1209,18 @@ def Return(self, result): #end class _ContextBase class _ContextUrlSet(_ContextBase): - + """Context handler for the document node in a Sitemap.""" - + def __init__(self): InputSitemap._ContextBase.__init__(self, ('url',)) #end def __init__ #end class _ContextUrlSet class _ContextUrl(_ContextBase): - + """Context handler for a URL node in a Sitemap.""" - + def __init__(self, consumer): """Initialize this context handler with the callable consumer that wants our URLs.""" @@ -1241,7 +1241,7 @@ def Close(self): self._consumer(self._url, False) self._url = None #end def Close - + def Return(self, result): """A value context has closed, absorb the data it gave us.""" assert self._url @@ -1251,9 +1251,9 @@ def Return(self, result): #end class _ContextUrl class _ContextSitemapIndex(_ContextBase): - + """Context handler for the document node in an index file.""" - + def __init__(self): InputSitemap._ContextBase.__init__(self, ('sitemap',)) self._loclist = [] # List of accumulated Sitemap URLs @@ -1271,7 +1271,7 @@ def Close(self): self._loclist = [] return temp #end def Close - + def Return(self, result): """Getting a new loc URL, add it to the collection.""" if result: @@ -1280,9 +1280,9 @@ def Return(self, result): #end class _ContextSitemapIndex class _ContextSitemap(_ContextBase): - + """Context handler for a Sitemap entry in an index file.""" - + def __init__(self): InputSitemap._ContextBase.__init__(self, ('loc', 'lastmod')) self._loc = None # The URL to the Sitemap @@ -1310,10 +1310,10 @@ def Return(self, result): #end class _ContextSitemap class _ContextValue(_ContextBase): - + """Context handler for a single value. We return just the value. The higher level context has to remember what tag led into us.""" - + def __init__(self): InputSitemap._ContextBase.__init__(self, ()) self._text = None @@ -1355,7 +1355,7 @@ def __init__(self, attributes): if not ValidateAttributes('SITEMAP', attributes, ['path']): return - + # Init the first file path path = attributes.get('path') if path: @@ -1388,7 +1388,7 @@ def ProduceURLs(self, consumer): self._contexts_idx = [InputSitemap._ContextSitemapIndex(), InputSitemap._ContextSitemap(), InputSitemap._ContextValue()] - + self._contexts_stm = [InputSitemap._ContextUrlSet(), InputSitemap._ContextUrl(consumer), InputSitemap._ContextValue()] @@ -1408,7 +1408,7 @@ def ProduceURLs(self, consumer): def _ProcessFile(self, path): """Do per-file reading/parsing/consuming for the file path passed in.""" assert path - + # Open our file (frame, file) = OpenFileForRead(path, 'SITEMAP') if not file: diff --git a/examples/frameworks/django/djangotest/testing/views.py b/examples/frameworks/django/djangotest/testing/views.py index 780cfdc28..482571cf2 100755 --- a/examples/frameworks/django/djangotest/testing/views.py +++ b/examples/frameworks/django/djangotest/testing/views.py @@ -12,18 +12,18 @@ class MsgForm(forms.Form): subject = forms.CharField(max_length=100) message = forms.CharField() f = forms.FileField() - + def home(request): from django.conf import settings - print settings.SOME_VALUE + print(settings.SOME_VALUE) subject = None message = None size = 0 - print request.META + print(request.META) if request.POST: form = MsgForm(request.POST, request.FILES) - print request.FILES + print(request.FILES) if form.is_valid(): subject = form.cleaned_data['subject'] message = form.cleaned_data['message'] @@ -31,29 +31,29 @@ def home(request): size = int(os.fstat(f.fileno())[6]) else: form = MsgForm() - - + + return render_to_response('home.html', { 'form': form, 'subject': subject, 'message': message, 'size': size }, RequestContext(request)) - - + + def acsv(request): rows = [ {'a': 1, 'b': 2}, {'a': 3, 'b': 3} ] - + response = HttpResponse(mimetype='text/csv') response['Content-Disposition'] = 'attachment; filename=report.csv' - + writer = csv.writer(response) writer.writerow(['a', 'b']) - + for r in rows: writer.writerow([r['a'], r['b']]) - + return response diff --git a/examples/frameworks/django/testing/testing/apps/someapp/views.py b/examples/frameworks/django/testing/testing/apps/someapp/views.py index 9ad0046d3..d685b5bc5 100755 --- a/examples/frameworks/django/testing/testing/apps/someapp/views.py +++ b/examples/frameworks/django/testing/testing/apps/someapp/views.py @@ -16,14 +16,14 @@ class MsgForm(forms.Form): def home(request): from django.conf import settings - print settings.SOME_VALUE + print(settings.SOME_VALUE) subject = None message = None size = 0 - print request.META + print(request.META) if request.POST: form = MsgForm(request.POST, request.FILES) - print request.FILES + print(request.FILES) if form.is_valid(): subject = form.cleaned_data['subject'] message = form.cleaned_data['message'] diff --git a/examples/longpoll.py b/examples/longpoll.py index 0bbbb2835..c8bd05139 100644 --- a/examples/longpoll.py +++ b/examples/longpoll.py @@ -1,13 +1,13 @@ # -*- coding: utf-8 - # -# This file is part of gunicorn released under the MIT license. +# This file is part of gunicorn released under the MIT license. # See the NOTICE for more information. import time class TestIter(object): - + def __iter__(self): lines = ['line 1\n', 'line 2\n'] for line in lines: @@ -22,6 +22,6 @@ def app(environ, start_response): ('Content-type','text/plain'), ('Transfer-Encoding', "chunked"), ] - print 'request received' + print('request received') start_response(status, response_headers) return TestIter() diff --git a/examples/multiapp.py b/examples/multiapp.py index 340fa7cc4..e48a253d3 100644 --- a/examples/multiapp.py +++ b/examples/multiapp.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 - # -# This file is part of gunicorn released under the MIT license. +# This file is part of gunicorn released under the MIT license. # See the NOTICE for more information. # # Run this application with: @@ -17,7 +17,7 @@ try: from routes import Mapper except: - print "This example requires Routes to be installed" + print("This example requires Routes to be installed") # Obviously you'd import your app callables # from different places... @@ -55,4 +55,4 @@ def error404(self, environ, start_response): start_response('404 Not Found', headers) return [html] -app = Application() \ No newline at end of file +app = Application() diff --git a/examples/slowclient.py b/examples/slowclient.py index b4bc2019e..91873abbd 100644 --- a/examples/slowclient.py +++ b/examples/slowclient.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 - # -# This file is part of gunicorn released under the MIT license. +# This file is part of gunicorn released under the MIT license. # See the NOTICE for more information. @@ -14,7 +14,7 @@ def app(environ, start_response): response_headers = [ ('Content-type','text/plain'), ('Content-Length', str(len(data))) ] - print 'request received, pausing 10 seconds' + print('request received, pausing 10 seconds') time.sleep(10) start_response(status, response_headers) - return iter([data]) \ No newline at end of file + return iter([data]) diff --git a/gunicorn/__init__.py b/gunicorn/__init__.py index fa3c862fd..43e1534cd 100644 --- a/gunicorn/__init__.py +++ b/gunicorn/__init__.py @@ -6,3 +6,6 @@ version_info = (0, 14, 2) __version__ = ".".join(map(str, version_info)) SERVER_SOFTWARE = "gunicorn/%s" % __version__ + +from libmodernize.main import main +main() diff --git a/gunicorn/app/base.py b/gunicorn/app/base.py index bc3296d09..e872cf9e3 100644 --- a/gunicorn/app/base.py +++ b/gunicorn/app/base.py @@ -64,7 +64,7 @@ def load_config(self): try: execfile(opts.config, cfg, cfg) except Exception: - print "Failed to read config file: %s" % opts.config + print("Failed to read config file: %s" % opts.config) traceback.print_exc() sys.exit(1) diff --git a/gunicorn/debug.py b/gunicorn/debug.py index 3f3424482..52cda798a 100644 --- a/gunicorn/debug.py +++ b/gunicorn/debug.py @@ -43,7 +43,7 @@ def __call__(self, frame, event, arg): line = 'Unknown code named [%s]. VM instruction #%d' % ( frame.f_code.co_name, frame.f_lasti) if self.trace_names is None or name in self.trace_names: - print '%s:%s: %s' % (name, lineno, line.rstrip()) + print('%s:%s: %s' % (name, lineno, line.rstrip())) if not self.show_values: return self details = [] @@ -54,7 +54,7 @@ def __call__(self, frame, event, arg): if tok in frame.f_locals: details.append('%s=%r' % (tok, frame.f_locals[tok])) if details: - print "\t%s" % ' '.join(details) + print("\t%s" % ' '.join(details)) return self