Skip to content

Commit

Permalink
Remove built-in routes support, this can now be implemented through _…
Browse files Browse the repository at this point in the history
…dispatch and is provided in tgext.routes
  • Loading branch information
amol- committed Feb 11, 2016
1 parent 1527560 commit a4ef502
Show file tree
Hide file tree
Showing 9 changed files with 8 additions and 126 deletions.
4 changes: 1 addition & 3 deletions setup.py
Expand Up @@ -20,15 +20,13 @@
'Genshi >= 0.5.1',
'Mako',
'WebTest < 2.0',
'routes',
'backlash >= 0.0.7',
'sqlalchemy',
'raven < 4.1.0',
'formencode>=1.3.0a1',
'tw2.forms',
'Beaker',
'Kajiki >= 0.4.4',
'routes']
'Kajiki >= 0.4.4']

if py_version == (3, 2):
# jinja2 2.7 is incompatible with Python 3.2
Expand Down
5 changes: 1 addition & 4 deletions tests/base.py
Expand Up @@ -25,7 +25,7 @@
from tg.wsgiapp import TemplateContext, TGApp, RequestLocals
from tg.controllers import TGController

from .test_stack.baseutils import ControllerWrap, FakeRoutes, default_config
from .test_stack.baseutils import ControllerWrap, default_config

data_dir = os.path.dirname(os.path.abspath(__file__))
session_dir = os.path.join(data_dir, 'session')
Expand Down Expand Up @@ -70,7 +70,6 @@ def make_app(controller_klass=None, environ=None, config_options=None, with_erro
app = TGApp(config=config)
app.controller_classes['root'] = ControllerWrap(controller_klass)

app = FakeRoutes(app)
app = RegistryManager(app)
return TestApp(app)

Expand Down Expand Up @@ -103,8 +102,6 @@ def tearDown(self):

def get_response(self, **kargs):
url = kargs.pop('_url', '/')
self.environ['tg.routes_dict'].update(kargs)

return self.app.get(url, extra_environ=self.environ)

def post_response(self, **kargs):
Expand Down
11 changes: 0 additions & 11 deletions tests/test_configuration.py
Expand Up @@ -288,17 +288,6 @@ def init_model(engine):
conf['ming.url'] = 'mim://'
app = conf.make_wsgi_app()

def test_enable_routes(self):
conf = AppConfig(minimal=True)
conf.enable_routes = True
app = conf.make_wsgi_app()

a = TGApp()
assert a.enable_routes == True

config.pop('routes.map')
config.pop('enable_routes')

def test_create(self):
pass

Expand Down
9 changes: 0 additions & 9 deletions tests/test_stack/baseutils.py
Expand Up @@ -26,15 +26,6 @@ class FakePackage(object):
'i18n.lang': None
}

class FakeRoutes(object):
def __init__(self, app):
self.app = app

def __call__(self, environ, start_response):
environ['wsgiorg.routing_args'] = [None, {'controller':'root'}]
environ['routes.url'] = None
return self.app(environ, start_response)


class ControllerWrap(object):
def __init__(self, controller):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_stack/test_authz.py
Expand Up @@ -28,7 +28,7 @@
from tg.support.middlewares import CacheMiddleware, SessionMiddleware, StatusCodeRedirect
from tg.decorators import Decoration

from .baseutils import ControllerWrap, FakeRoutes, default_config
from .baseutils import ControllerWrap, default_config
from ..base import make_app as base_make_app

from tg.configuration.auth import setup_auth, TGAuthMetadata
Expand Down
60 changes: 3 additions & 57 deletions tg/configuration/app_config.py
Expand Up @@ -158,8 +158,8 @@ class AppConfig(Bunch):
overridden by users who wish to have finer grained control over
the setup of the WSGI environment in which their application is run.
This is the place to configure custom routes, transaction handling,
error handling, etc.
This is the place to configure your application, database,
transaction handling, error handling, etc.
Configuration Options provided:
Expand Down Expand Up @@ -244,7 +244,6 @@ def __init__(self, minimal=False, root_controller=None):
self.rendering_engines_without_vars = set()
self.rendering_engines_options = {}

self.enable_routes = False
self.enable_routing_args = False
self.disable_request_extensions = minimal

Expand Down Expand Up @@ -651,52 +650,6 @@ def after_init_config(self):
"""

def setup_routes(self):
"""Setup the default TG2 routes
Override this and setup your own routes maps if you want to use
custom routes.
It is recommended that you keep the existing application routing in
tact, and just add new connections to the mapper above the routes_placeholder
connection. Lets say you want to add a tg controller SamplesController,
inside the controllers/samples.py file of your application. You would
augment the app_cfg.py in the following way::
from routes import Mapper
from tg.configuration import AppConfig
class MyAppConfig(AppConfig):
def setup_routes(self):
map = Mapper(directory=config['paths']['controllers'],
always_scan=config['debug'])
# Add a Samples route
map.connect('/samples/', controller='samples', action=index)
# Setup a default route for the root of object dispatch
map.connect('*url', controller='root', action='routes_placeholder')
config['routes.map'] = map
base_config = MyAppConfig()
"""
if not self.enable_routes:
return None

from routes import Mapper

map = Mapper(directory=config['paths']['controllers'],
always_scan=config['debug'])

# Setup a default route for the root of object dispatch
map.connect('*url', controller='root', action='routes_placeholder')

config['routes.map'] = map
return map

def setup_helpers_and_globals(self):
"""Add helpers and globals objects to the config.
Expand Down Expand Up @@ -956,7 +909,6 @@ def load_environment(global_conf, app_conf):
tg.hooks.notify('initialized_config', args=(self, app_config))
tg.hooks.notify('startup', trap_exceptions=True)

self.setup_routes()
self.setup_helpers_and_globals()
self.setup_auth()
self._setup_renderers()
Expand Down Expand Up @@ -1082,17 +1034,11 @@ def add_auth_middleware(self, app, skip_authentication):
return app

def add_core_middleware(self, app):
"""Add support for routes dispatch, sessions, and caching middlewares
"""Add support for sessions, and caching middlewares
Those are all deprecated middlewares and will be removed in future TurboGears
versions as they have been replaced by other tools.
"""
if self.enable_routes:
warnings.warn("Internal routes support will be deprecated soon, please "
"consider using tgext.routes instead", DeprecationWarning)
from routes.middleware import RoutesMiddleware
app = RoutesMiddleware(app, config['routes.map'])

if getattr(self, 'use_session_middleware', False):
warnings.warn('SessionMiddleware is deprecated and will be removed soon, '
'please consider using SessionApplicationWrapper instead.',
Expand Down
8 changes: 0 additions & 8 deletions tg/controllers/dispatcher.py
Expand Up @@ -111,14 +111,6 @@ def _perform_call(self, context):

return r

def routes_placeholder(self, url='/', start_response=None, **kwargs): #pragma: no cover
"""Routes placeholder.
This function does not do anything. It is a placeholder that allows
Routes to accept this controller as a target for its routing.
"""
pass

def __call__(self, environ, context):
py_response = context.response

Expand Down
3 changes: 1 addition & 2 deletions tg/controllers/tgcontroller.py
Expand Up @@ -14,8 +14,7 @@ class TGController(DecoratedController, CoreDispatcher, ObjectDispatcher):
This controller can be used as a baseclass for anything in the
object dispatch tree, but it MUST be used in the Root controller
and any controller which you intend to do object dispatch from
using Routes.
and any controller which you intend to do object dispatch.
This controller has a few reserved method names which provide special functionality.
Expand Down
32 changes: 1 addition & 31 deletions tg/wsgiapp.py
Expand Up @@ -51,7 +51,6 @@ def __init__(self, config=None, **kwargs):
# Cache some options for use during requests
self.strict_tmpl_context = self.config['tg.strict_tmpl_context']
self.pylons_compatible = self.config.get('tg.pylons_compatible', True)
self.enable_routes = self.config.get('enable_routes', False)

self.resp_options = config.get('tg.response_options',
dict(content_type='text/html',
Expand Down Expand Up @@ -98,10 +97,6 @@ def setup_pylons_compatibility(self, environ, controller): #pragma: no cover
pylons.translator = request_local.translator
pylons.response = request_local.response
pylons.tmpl_context = request_local.tmpl_context

if self.enable_routes:
environ['pylons.routes_dict'] = environ['tg.routes_dict']
pylons.url = request_local.url
except ImportError:
pass

Expand All @@ -118,7 +113,7 @@ def __call__(self, environ, start_response):
start_response('200 OK', [('Content-type', 'text/plain')])
return ['DONE'.encode('utf-8')]

controller = self.resolve(environ, context)
controller = self.get_controller_instance('root')
response = self.wrapped_dispatch(controller, environ, context)

if testmode is True:
Expand Down Expand Up @@ -180,10 +175,6 @@ def setup_app_env(self, environ):
locals.session = environ.get('beaker.session') # Usually None, unless middleware in place
locals.cache = environ.get('beaker.cache') # Usually None, unless middleware in place

if self.enable_routes: #pragma: no cover
url = environ.get('routes.url')
locals.url = url

environ['tg.locals'] = locals

# Register Global objects
Expand All @@ -204,27 +195,6 @@ def setup_app_env(self, environ):

return testing, locals, registry

def resolve(self, environ, context):
"""Uses dispatching information found in
``environ['wsgiorg.routing_args']`` to retrieve a controller
name and return the controller instance from the appropriate
controller module.
Override this to change how the controller name is found and
returned.
"""
if self.enable_routes: #pragma: no cover
match = environ['wsgiorg.routing_args'][1]
environ['tg.routes_dict'] = match
controller = match.get('controller')
if not controller:
return None
else:
controller = 'root'

return self.get_controller_instance(controller)

def class_name_from_module_name(self, module_name):
words = module_name.replace('-', '_').split('_')
return ''.join(w.title() for w in words)
Expand Down

0 comments on commit a4ef502

Please sign in to comment.