]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Fix Tornado on Google App Engine.
authorBen Darnell <ben@bendarnell.com>
Sat, 17 May 2014 14:56:35 +0000 (10:56 -0400)
committerBen Darnell <ben@bendarnell.com>
Sat, 17 May 2014 14:56:35 +0000 (10:56 -0400)
Imports of tornado.ioloop have crept into more places, so the old
app engine policy of never importing these modules doesn't work.
Instead, we add guards around imports of unavailable modules
(fcntl, ssl, multiprocessing) so that everything is at least importable.

Closes #1059.

maint/test/appengine/common/cgi_runtests.py
tornado/iostream.py
tornado/netutil.py
tornado/platform/auto.py
tornado/process.py
tornado/simple_httpclient.py
tornado/tcpserver.py
tornado/test/import_test.py

index f33c131bc9aa963e9078f51691845abfdb6d02d3..44ddf7ae881a7dffea7960ab4e051bfa53d3108d 100644 (file)
@@ -2,65 +2,46 @@
 import sys
 import unittest
 
-# Most of our tests depend on IOLoop, which is not importable on app engine.
-# Run the tests that work, and check that forbidden imports don't sneak
-# in to modules that are supposed to work on app engine.
+# Most of our tests depend on IOLoop, which is not usable on app engine.
+# Run the tests that work, and check that everything else is at least
+# importable (via tornado.test.import_test)
 TEST_MODULES = [
     'tornado.httputil.doctests',
-    #'tornado.iostream.doctests',
+    'tornado.iostream.doctests',
     'tornado.util.doctests',
     #'tornado.test.auth_test',
+    #'tornado.test.concurrent_test',
     #'tornado.test.curl_httpclient_test',
     'tornado.test.escape_test',
     #'tornado.test.gen_test',
     #'tornado.test.httpclient_test',
     #'tornado.test.httpserver_test',
     'tornado.test.httputil_test',
-    #'tornado.test.import_test',
+    'tornado.test.import_test',
     #'tornado.test.ioloop_test',
     #'tornado.test.iostream_test',
+    'tornado.test.locale_test',
+    #'tornado.test.netutil_test',
+    #'tornado.test.log_test',
+    'tornado.test.options_test',
     #'tornado.test.process_test',
     #'tornado.test.simple_httpclient_test',
     #'tornado.test.stack_context_test',
     'tornado.test.template_test',
     #'tornado.test.testing_test',
     #'tornado.test.twisted_test',
+    'tornado.test.util_test',
     #'tornado.test.web_test',
+    #'tornado.test.websocket_test',
     #'tornado.test.wsgi_test',
 ]
 
-def import_everything():
-    # import tornado.auth
-    # import tornado.autoreload
-    # import tornado.curl_httpclient  # depends on pycurl
-    import tornado.escape
-    # import tornado.httpclient
-    # import tornado.httpserver
-    import tornado.httputil
-    # import tornado.ioloop
-    # import tornado.iostream
-    import tornado.locale
-    import tornado.options
-    # import tornado.netutil
-    # import tornado.platform.twisted # depends on twisted
-    # import tornado.process
-    # import tornado.simple_httpclient
-    import tornado.stack_context
-    import tornado.template
-    import tornado.testing
-    import tornado.util
-    import tornado.web
-    # import tornado.websocket
-    import tornado.wsgi
-
 def all():
     return unittest.defaultTestLoader.loadTestsFromNames(TEST_MODULES)
 
 def main():
     print "Content-Type: text/plain\r\n\r\n",
 
-    import_everything()
-
     try:
         unittest.main(defaultTest='all', argv=sys.argv[:1])
     except SystemExit, e:
index 7f2e364999e31fa14c0f45a058b7fdee395495be..c8c0749433a2bd65b52c8ebf9442ed7cf1ab0b60 100644 (file)
@@ -31,7 +31,6 @@ import errno
 import numbers
 import os
 import socket
-import ssl
 import sys
 import re
 
@@ -47,6 +46,12 @@ try:
 except ImportError:
     _set_nonblocking = None
 
+try:
+    import ssl
+except ImportError:
+    # ssl is not available on Google App Engine
+    ssl = None
+
 # These errnos indicate that a non-blocking operation must be retried
 # at a later time.  On most platforms they're the same value, but on
 # some they differ.
index 50e3a0b922a293519203e8c6ada38b14b3e6e1a2..2042b91dd924d0449355f6eabf495a396923bdf3 100644 (file)
@@ -21,7 +21,6 @@ from __future__ import absolute_import, division, print_function, with_statement
 import errno
 import os
 import socket
-import ssl
 import stat
 
 from tornado.concurrent import dummy_executor, run_on_executor
@@ -29,9 +28,17 @@ from tornado.ioloop import IOLoop
 from tornado.platform.auto import set_close_exec
 from tornado.util import u, Configurable, errno_from_exception
 
+try:
+    import ssl
+except ImportError:
+    # ssl is not available on Google App Engine
+    ssl = None
+
 if hasattr(ssl, 'match_hostname') and hasattr(ssl, 'CertificateError'):  # python 3.2+
     ssl_match_hostname = ssl.match_hostname
     SSLCertificateError = ssl.CertificateError
+elif ssl is None:
+    ssl_match_hostname = SSLCertificateError = None
 else:
     import backports.ssl_match_hostname
     ssl_match_hostname = backports.ssl_match_hostname.match_hostname
index e55725b37b172c332acad1726bb00100d88dfbaf..1dbb3f4169f68f1e5d481011d2fa6f265b457f71 100644 (file)
@@ -30,6 +30,9 @@ import os
 if os.name == 'nt':
     from tornado.platform.common import Waker
     from tornado.platform.windows import set_close_exec
+elif 'APPENGINE_RUNTIME' in os.environ:
+    from tornado.platform.common import Waker
+    def set_close_exec(fd): pass
 else:
     from tornado.platform.posix import set_close_exec, Waker
 
index 74575d05aea07a654d972bd4cd5aee08ec81b3c0..0f38b856d94515a94a4551cd4cfb6cac0c222b5d 100644 (file)
@@ -21,7 +21,6 @@ the server into multiple processes and managing subprocesses.
 from __future__ import absolute_import, division, print_function, with_statement
 
 import errno
-import multiprocessing
 import os
 import signal
 import subprocess
@@ -37,6 +36,12 @@ from tornado.platform.auto import set_close_exec
 from tornado import stack_context
 from tornado.util import errno_from_exception
 
+try:
+    import multiprocessing
+except ImportError:
+    # Multiprocessing is not availble on Google App Engine.
+    multiprocessing = None
+
 try:
     long  # py2
 except NameError:
@@ -45,6 +50,8 @@ except NameError:
 
 def cpu_count():
     """Returns the number of processors on this machine."""
+    if multiprocessing is None:
+        return 1
     try:
         return multiprocessing.cpu_count()
     except NotImplementedError:
index d35ff1defa17f944d066fd8f132a38db17eaa5b2..b7be7950f0ba32e3cd87b933cf54530becab5a7d 100644 (file)
@@ -17,7 +17,6 @@ import copy
 import functools
 import re
 import socket
-import ssl
 import sys
 
 try:
@@ -30,6 +29,12 @@ try:
 except ImportError:
     import urllib.parse as urlparse  # py3
 
+try:
+    import ssl
+except ImportError:
+    # ssl is not available on Google App Engine.
+    ssl = None
+
 try:
     import certifi
 except ImportError:
index 74326c1f1bbb6b4dd7a5cae6a3a3a0277068eb88..d5e28df6efbdfc28d914564472b7d99fc20b6fd2 100644 (file)
@@ -20,7 +20,6 @@ from __future__ import absolute_import, division, print_function, with_statement
 import errno
 import os
 import socket
-import ssl
 
 from tornado.log import app_log
 from tornado.ioloop import IOLoop
@@ -29,6 +28,11 @@ from tornado.netutil import bind_sockets, add_accept_handler, ssl_wrap_socket
 from tornado import process
 from tornado.util import errno_from_exception
 
+try:
+    import ssl
+except ImportError:
+    # ssl is not available on Google App Engine.
+    ssl = None
 
 class TCPServer(object):
     r"""A non-blocking, single-threaded TCP server.
index ccd6ef35f87cc2e825de5517377f729fcbc4db5d..de7cc0b9fbf51e7cf464944107cc77fc9f77f619 100644 (file)
@@ -13,6 +13,7 @@ class ImportTest(unittest.TestCase):
         # import tornado.curl_httpclient  # depends on pycurl
         import tornado.escape
         import tornado.gen
+        import tornado.http1connection
         import tornado.httpclient
         import tornado.httpserver
         import tornado.httputil