Skip to content

Commit

Permalink
Organized imports.
Browse files Browse the repository at this point in the history
--HG--
branch : 1.0
  • Loading branch information
moraes committed Apr 17, 2011
1 parent d7fd837 commit 09e3769
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions tipfy/routing.py
Expand Up @@ -8,13 +8,21 @@
:copyright: 2011 by tipfy.org.
:license: BSD, see LICENSE.txt for more details.
"""
from werkzeug import import_string, url_quote
from werkzeug.routing import (BaseConverter, EndpointPrefix, Map,
Rule as BaseRule, RuleFactory, Subdomain, Submount)
from werkzeug.wrappers import BaseResponse
from werkzeug import routing
from werkzeug import urls
from werkzeug import utils
from werkzeug import wrappers

from .local import get_request, local

# For export.
BaseConverter = routing.BaseConverter
EndpointPrefix = routing.EndpointPrefix
Map = routing.Map
RuleFactory = routing.RuleFactory
Subdomain = routing.Subdomain
Submount = routing.Submount


class Router(object):
def __init__(self, app, rules=None):
Expand Down Expand Up @@ -86,12 +94,13 @@ def dispatch(self, request):
handler = rule.handler
if isinstance(handler, basestring):
if handler not in self.handlers:
self.handlers[handler] = import_string(handler)
self.handlers[handler] = utils.import_string(handler)

rule.handler = handler = self.handlers[handler]

rv = local.current_handler = handler(request)
if not isinstance(rv, BaseResponse) and hasattr(rv, '__call__'):
if not isinstance(rv, wrappers.BaseResponse) and \
hasattr(rv, '__call__'):
# If it is a callable but not a response, we call it again.
rv = rv()

Expand Down Expand Up @@ -137,7 +146,7 @@ def url_for(self, request, name, kwargs):
url = '%s://%s%s' % (scheme or 'http', netloc or request.host, url)

if anchor:
url += '#%s' % url_quote(anchor)
url += '#%s' % urls.url_quote(anchor)

return url

Expand Down Expand Up @@ -178,7 +187,7 @@ def get_server_name(self, request):
build = url_for


class Rule(BaseRule):
class Rule(routing.Rule):
"""A Rule represents one URL pattern. Tipfy extends Werkzeug's Rule
to support handler and name definitions. Handler is the
:class:`tipfy.RequestHandler` class that will handle the request and name
Expand Down Expand Up @@ -300,7 +309,7 @@ def foo_with_slug(adapter, id):
self.handler_method = handler_method
if isinstance(handler, basestring) and handler.rfind(':') != -1:
if handler_method:
raise ValueError(
raise BadArgumentError(
"If handler_method is defined in a Rule, handler "
"can't have a colon (got %r)." % handler)
else:
Expand Down

0 comments on commit 09e3769

Please sign in to comment.