Commits

Victor Stinner committed 646047a

Python 3: fix more submodules

* print syntax
* replace "except Exception, exc:" with "except Exception as exc:"

  • Participants
  • Parent commits 894f073

Comments (0)

Files changed (17)

File paste/auth/auth_tkt.py

 
         token = auth_tkt.AuthTick('sharedsecret', 'username',
             os.environ['REMOTE_ADDR'], tokens=['admin'])
-        print 'Status: 200 OK'
-        print 'Content-type: text/html'
-        print token.cookie()
-        print
+        print('Status: 200 OK')
+        print('Content-type: text/html')
+        print(token.cookie())
+        print("")
         ... redirect HTML ...
 
     Webware usage::

File paste/cascade.py

                         list(v)
                         # then close:
                         v.close()
-            except self.catch_exceptions, e:
+            except self.catch_exceptions:
                 pass
         if copy_wsgi_input:
             environ['wsgi.input'].seek(0)

File paste/debug/doctest_webapp.py

 def run(command):
     data = run_raw(command)
     if data:
-        print data
+        print(data)
 
 def run_raw(command):
     """
     show_file('shell-command', name, description='shell transcript',
               data=data)
     if and_print and output:
-        print output
+        print(output)
 
 def _make_env():
     env = os.environ.copy()
         full = os.path.join(dir, fn)
         if os.path.isdir(full):
             fn = fn + '/'
-        print ' '*indent + fn
+        print(' '*indent + fn)
         if os.path.isdir(full) and recurse:
             ls(dir=full, recurse=True, indent=indent+2)
 
         expected = f.read()
         f.close()
         if not html_matches(expected, result):
-            print 'Pages did not match.  Expected from %s:' % fn
-            print '-'*60
-            print expected
-            print '='*60
-            print 'Actual output:'
-            print '-'*60
-            print result
+            print('Pages did not match.  Expected from %s:' % fn)
+            print('-'*60)
+            print(expected)
+            print('='*60)
+            print('Actual output:')
+            print('-'*60)
+            print(result)
 
 def html_matches(pattern, text):
     regex = re.escape(pattern)

File paste/debug/fsdiff.py

         __tracebackhide__ = True
         bytes = self.bytes
         if s not in bytes:
-            print 'Could not find %r in:' % s
-            print bytes
+            print('Could not find %r in:' % s)
+            print(bytes)
             assert s in bytes
 
     def __repr__(self):

File paste/debug/testserver.py

             if now > self.expires and self.timeout:
                 # note regression test doesn't handle exceptions in
                 # threads very well; so we just print and exit
-                print "\nWARNING: WSGIRegressionServer timeout exceeded\n"
+                print("\nWARNING: WSGIRegressionServer timeout exceeded\n")
                 break
             if self.pending:
                 self.handle_request()
 
 def serve(application, host=None, port=None, handler=None):
     server = WSGIRegressionServer(application, host, port, handler)
-    print "serving on %s:%s" % server.server_address
+    print("serving on %s:%s" % server.server_address)
     server.serve_forever()
     return server
 

File paste/debug/watchthreads.py

                 environ_template.substitute(
                 key=cgi.escape(str(key)),
                 value=cgi.escape(str(value))))
-        except Exception, e:
+        except Exception as e:
             environ_rows.append(
                 environ_template.substitute(
                 key=cgi.escape(str(key)),
         else:
             count = 0
             while 1:
-                print "I'm alive %s (%s)" % (count, thread.get_ident())
+                print("I'm alive %s (%s)" % (count, thread.get_ident()))
                 time.sleep(10)
                 count += 1
         start_response('200 OK', [('content-type', 'text/plain')])

File paste/flup_session.py

 
         try:
             app_iter = self.application(environ, cookie_start_response)
-        except httpexceptions.HTTPException, e:
+        except httpexceptions.HTTPException as e:
             headers = (e.headers or {}).items()
             service.addCookie(headers)
             e.headers = dict(headers)

File paste/registry.py

 
         try:
             app_iter = self.application(environ, start_response)
-            #print "REG ", type(app_iter)
+            #print("REG ", type(app_iter))
             if isinstance(app_iter, (list, tuple)):
-                #print "DIRECT"
+                #print("DIRECT")
                 return app_iter
-            #print "STREAMING"
+            #print("STREAMING")
             return self.streaming_iter(app_iter, reg, environ)
 
         except Exception as e:

File paste/reloader.py

 ``watch_config_files`` and check all the filenames it returns.
 """
 
+from __future__ import print_function
 import os
 import sys
 import time
             try:
                 filenames.extend(file_callback())
             except:
-                print >> sys.stderr, "Error calling paste.reloader callback %r:" % file_callback
+                print("Error calling paste.reloader callback %r:" % file_callback,
+                      file=sys.stderr)
                 traceback.print_exc()
         for module in sys.modules.values():
             try:
                 filename = module.__file__
-            except (AttributeError, ImportError), exc:
+            except (AttributeError, ImportError) as exc:
                 continue
             if filename is not None:
                 filenames.append(filename)
             if not self.module_mtimes.has_key(filename):
                 self.module_mtimes[filename] = mtime
             elif self.module_mtimes[filename] < mtime:
-                print >> sys.stderr, (
-                    "%s changed; reloading..." % filename)
+                print("%s changed; reloading..." % filename, file=sys.stderr)
                 return False
         return True
 

File paste/request.py

         >>> def call_it(script_name, path_info):
         ...     env = {'SCRIPT_NAME': script_name, 'PATH_INFO': path_info}
         ...     result = path_info_pop(env)
-        ...     print 'SCRIPT_NAME=%r; PATH_INFO=%r; returns=%r' % (
-        ...         env['SCRIPT_NAME'], env['PATH_INFO'], result)
+        ...     print('SCRIPT_NAME=%r; PATH_INFO=%r; returns=%r' % (
+        ...         env['SCRIPT_NAME'], env['PATH_INFO'], result))
         >>> call_it('/foo', '/bar')
         SCRIPT_NAME='/foo/bar'; PATH_INFO=''; returns='bar'
         >>> call_it('/foo/bar', '')

File paste/transaction.py

     curr = conn.cursor()
     curr.execute("SELECT now(), %s" % conn.quote("B'n\\'gles"))
     (time, bing) = curr.fetchone()
-    print bing, time
+    print(bing, time)
 

File paste/util/PySourceColor.py

 @A @B(arghh) @C
 def LlamaSaysNi(arg='Ni!',arg2="RALPH"):
    """This docstring is deeply disturbed by all the llama references"""
-   print '%s The Wonder Llama says %s'% (arg2,arg)
+   print('%s The Wonder Llama says %s'% (arg2,arg))
 # So I was like duh!, and he was like ya know?!,
 # and so we were both like huh...wtf!? RTFM!! LOL!!;)
 @staticmethod## Double comments are KewL.

File paste/util/finddata.py

 # you can't import this from another package, when you don't know if
 # that package is installed yet.
 
+from __future__ import print_function
 import os
 import sys
 from fnmatch import fnmatchcase
                         or fn.lower() == pattern.lower()):
                         bad_name = True
                         if show_ignored:
-                            print >> sys.stderr, (
-                                "Directory %s ignored by pattern %s"
-                                % (fn, pattern))
+                            print("Directory %s ignored by pattern %s"
+                                  % (fn, pattern), file=sys.stderr)
                         break
                 if bad_name:
                     continue
                         or fn.lower() == pattern.lower()):
                         bad_name = True
                         if show_ignored:
-                            print >> sys.stderr, (
-                                "File %s ignored by pattern %s"
-                                % (fn, pattern))
+                            print("File %s ignored by pattern %s"
+                                  % (fn, pattern), file=sys.stderr)
                         break
                 if bad_name:
                     continue

File paste/util/looper.py

 looper you can get a better sense of the context.  Use like::
 
     >>> for loop, item in looper(['a', 'b', 'c']):
-    ...     print loop.number, item
+    ...     print(loop.number, item)
     ...     if not loop.last:
-    ...         print '---'
+    ...         print('---')
     1 a
     ---
     2 b

File paste/util/quoting.py

     """
     comment = str(s)
     #comment = _bad_chars_re.sub('', comment)
-    #print 'in ', repr(str(s))
-    #print 'out', repr(comment)
+    #print('in ', repr(str(s)))
+    #print('out', repr(comment))
     comment = _comment_quote_re.sub('-&gt;', comment)
     return comment
 

File paste/util/template.py

     def _exec(self, code, ns, pos):
         __traceback_hide__ = True
         try:
-            exec code in ns
+            six.exec_(code, ns)
         except:
             exc_info = sys.exc_info()
             e = exc_info[1]
         help="Put the environment in as top-level variables")
     options, args = parser.parse_args(args)
     if len(args) < 1:
-        print 'You must give a template filename'
-        print dir(parser)
+        print('You must give a template filename')
+        print(dir(parser))
         assert 0
     template_name = args[0]
     args = args[1:]
         vars.update(os.environ)
     for value in args:
         if '=' not in value:
-            print 'Bad argument: %r' % value
+            print('Bad argument: %r' % value)
             sys.exit(2)
         name, value = value.split('=', 1)
         if name.startswith('py:'):

File paste/wsgilib.py

 A module of many disparate routines.
 """
 
+from __future__ import print_function
+
 # functions which moved to paste.request and paste.response
 # Deprecated around 15 Dec 2005
 from paste.request import get_cookies, parse_querystring, parse_formvars
     def __del__(self):
         if not self._closed:
             # We can't raise an error or anything at this stage
-            print >> sys.stderr, (
-                "Error: app_iter.close() was not called when finishing "
+            print("Error: app_iter.close() was not called when finishing "
                 "WSGI request. finalization function %s not called"
-                % self.close_func)
+                  % self.close_func, file=sys.stderr)
 
 class add_start_close(object):
     """
     def __del__(self):
         if not self._closed:
             # We can't raise an error or anything at this stage
-            print >> sys.stderr, (
-                "Error: app_iter.close() was not called when finishing "
+            print("Error: app_iter.close() was not called when finishing "
                 "WSGI request. finalization function %s not called"
-                % self.close_func)
+                  % self.close_func, file=sys.stderr)
 
 class chained_app_iters(object):
 
     def __del__(self):
         if not self._closed:
             # We can't raise an error or anything at this stage
-            print >> sys.stderr, (
-                "Error: app_iter.close() was not called when finishing "
+            print("Error: app_iter.close() was not called when finishing "
                 "WSGI request. finalization function %s not called"
-                % self.close_func)
+                  % self.close_func, file=sys.stderr)
 
 class encode_unicode_app_iter(object):
     """