def test_make_wsgi_app2(self): app = make_wsgi_app(config={'tipfy': { 'foo': 'bar' }}) assert isinstance(app, Tipfy) assert app.config.get('tipfy', 'foo') == 'bar'
def test_run_wsgi_app(self): """We aren't testing anything here.""" from os import environ environ['SERVER_NAME'] = 'foo.com' environ['SERVER_PORT'] = '80' environ['REQUEST_METHOD'] = 'GET' rules = [Rule('/', handler='resources.handlers.HomeHandler', name='home')] app = make_wsgi_app(rules=rules, debug=True) run_wsgi_app(app)
def test_make_wsgi_app_with_middleware(self): def app_wrapper(environ, start_response): pass class AppMiddleware(object): def post_make_app(self, app): app.wsgi_app = app_wrapper app = make_wsgi_app(config={'tipfy': { 'middleware': [AppMiddleware] }}) self.assertEqual(app.wsgi_app, app_wrapper)
def test_run_wsgi_app_with_middleware(self): class AppMiddleware_2(object): pass from os import environ environ['SERVER_NAME'] = 'foo.com' environ['SERVER_PORT'] = '80' environ['REQUEST_METHOD'] = 'GET' rules = [Rule('/', handler='resources.handlers.HomeHandler', name='home')] app = make_wsgi_app(rules=rules, config={'tipfy': { 'middleware': [AppMiddleware_2] }}) run_wsgi_app(app)
def compile_templates(argv=None): """Compiles templates for better performance. This is a command line script. From the buildout directory, run: bin/jinja2_compile It will compile templates from the directory configured for 'templates_dir' to the one configured for 'templates_compiled_target'. At this time it doesn't accept any arguments. """ if argv is None: argv = sys.argv cwd = os.getcwd() app_path = os.path.join(cwd, 'app') gae_path = os.path.join(cwd, 'etc/parts/google_appengine') extra_paths = [ app_path, gae_path, # These paths are required by the SDK. os.path.join(gae_path, 'lib', 'antlr3'), os.path.join(gae_path, 'lib', 'django'), os.path.join(gae_path, 'lib', 'ipaddr'), os.path.join(gae_path, 'lib', 'webob'), os.path.join(gae_path, 'lib', 'yaml', 'lib'), ] sys.path = extra_paths + sys.path from config import config app = make_wsgi_app(config) template_path = get_config('tipfy.ext.jinja2', 'templates_dir') compiled_path = get_config('tipfy.ext.jinja2', 'templates_compiled_target') if compiled_path is None: raise ValueError('Missing configuration key to compile templates.') if isinstance(template_path, basestring): # A single path. source = os.path.join(app_path, template_path) else: # A list of paths. source = [os.path.join(app_path, p) for p in template_path] target = os.path.join(app_path, compiled_path) # Set templates dir and deactivate compiled dir to use normal loader to # find the templates to be compiled. app.config['tipfy.ext.jinja2']['templates_dir'] = source app.config['tipfy.ext.jinja2']['templates_compiled_target'] = None if target.endswith('.zip'): zip_cfg = 'deflated' else: zip_cfg = None old_list_templates = FileSystemLoader.list_templates FileSystemLoader.list_templates = list_templates env = get_env() env.compile_templates(target, extensions=None, filter_func=filter_templates, zip=zip_cfg, log_function=logger, ignore_errors=False, py_compile=False) FileSystemLoader.list_templates = old_list_templates
# Add /lib as primary libraries directory, with fallback to /distlib # and optionally to distlib loaded using zipimport. sys.path[0:0] = ['lib', 'distlib', 'distlib.zip'] import config import tipfy from google.appengine.dist import use_library os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' use_library('django', '0.96') # Is this the development server? debug = os.environ.get('SERVER_SOFTWARE', '').startswith('Dev') sys.path.append(os.path.join(os.path.dirname(__file__), 'apps')) env_config = config.configs['development'] if debug else config.configs['production'] # Instantiate the application. app = tipfy.make_wsgi_app(config=env_config, debug=debug) def main(): app.run() if __name__ == '__main__': main()
# -*- coding: utf-8 -*- import os import sys if 'lib' not in sys.path: # Add /lib as primary libraries directory, with fallback to /distlib # and optionally to distlib loaded using zipimport. sys.path[0:0] = ['lib', 'distlib', 'distlib.zip'] import config import tipfy # Is this the development server? debug = os.environ.get('SERVER_SOFTWARE', '').startswith('Dev') # Instantiate the application. app = tipfy.make_wsgi_app(config=config.config, debug=debug) def main(): app.run() if __name__ == '__main__': main()
Run Tipfy apps. :copyright: 2009 by tipfy.org. :license: BSD, see LICENSE for more details. """ import os import sys if 'lib' not in sys.path: # Add /lib as primary libraries directory, with fallback to /distlib # and optionally to distlib loaded using zipimport. sys.path[0:0] = ['lib', 'distlib', 'distlib.zip'] import config import tipfy # Is this the development server? debug = os.environ.get('SERVER_SOFTWARE', '').startswith('Dev') # Instantiate the application. application = tipfy.make_wsgi_app(config=config.config, debug=debug) def main(): # Run it! tipfy.run_wsgi_app(application) if __name__ == '__main__': main()
# -*- coding: utf-8 -*- """ main ~~~~ Run Tipfy apps. :copyright: 2009 by tipfy.org. :license: BSD, see LICENSE for more details. """ import sys if 'lib' not in sys.path: sys.path.insert(0, 'lib') import config import tipfy # Instantiate the application. application = tipfy.make_wsgi_app(config.config) def main(): # Run it! tipfy.run_wsgi_app(application) if __name__ == '__main__': main()
:license: BSD, see LICENSE for more details. """ import os import sys if 'lib' not in sys.path: # Add /lib as primary libraries directory, with fallback to /distlib # and optionally to distlib loaded using zipimport. sys.path[0:0] = ['lib', 'distlib', 'distlib.zip', 'shared'] import config import tipfy # Is this the development server? debug = os.environ.get('SERVER_SOFTWARE', '').startswith('Dev') # Instantiate the application. app = tipfy.make_wsgi_app(config=config.config, debug=debug) from tipfy.ext.jinja2 import get_jinja2_instance env=get_jinja2_instance() env.globals['app_version'] = os.environ['CURRENT_VERSION_ID'] or 'dev' def main(): app.run() if __name__ == '__main__': main()
if 'lib' not in sys.path: # Add /lib as primary libraries directory, with fallback to /distlib # and optionally to distlib loaded using zipimport. sys.path[0:0] = ['lib', 'distlib', 'distlib.zip'] import config import tipfy from google.appengine.dist import use_library os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' use_library('django', '0.96') # Is this the development server? debug = os.environ.get('SERVER_SOFTWARE', '').startswith('Dev') sys.path.append(os.path.join(os.path.dirname(__file__), 'apps')) env_config = config.configs['development'] if debug else config.configs[ 'production'] # Instantiate the application. app = tipfy.make_wsgi_app(config=env_config, debug=debug) def main(): app.run() if __name__ == '__main__': main()
def test_make_wsgi_app(self): app = make_wsgi_app(config={'tipfy': { }}) assert isinstance(app, Tipfy)