Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes | Private Attributes
MoinMoin.support.werkzeug.routing.Map Class Reference

List of all members.

Public Member Functions

def __init__
def is_endpoint_expecting
def iter_rules
def add
def bind
def bind_to_environ
def update

Public Attributes

 default_subdomain
 charset
 strict_slashes
 redirect_defaults
 converters
 sort_parameters
 sort_key

Private Attributes

 _rules
 _rules_by_endpoint
 _remap

Detailed Description

The map class stores all the URL rules and some configuration
parameters.  Some of the configuration values are only stored on the
`Map` instance since those affect all rules, others are just defaults
and can be overridden for each rule.  Note that you have to specify all
arguments besides the `rules` as keywords arguments!

:param rules: sequence of url rules for this map.
:param default_subdomain: The default subdomain for rules without a
                          subdomain defined.
:param charset: charset of the url. defaults to ``"utf-8"``
:param strict_slashes: Take care of trailing slashes.
:param redirect_defaults: This will redirect to the default rule if it
                          wasn't visited that way. This helps creating
                          unique URLs.
:param converters: A dict of converters that adds additional converters
                   to the list of converters. If you redefine one
                   converter this will override the original one.
:param sort_parameters: If set to `True` the url parameters are sorted.
                        See `url_encode` for more details.
:param sort_key: The sort key function for `url_encode`.

.. versionadded:: 0.5
    `sort_parameters` and `sort_key` was added.

Definition at line 887 of file routing.py.


Constructor & Destructor Documentation

def MoinMoin.support.werkzeug.routing.Map.__init__ (   self,
  rules = None,
  default_subdomain = '',
  charset = 'utf-8',
  strict_slashes = True,
  redirect_defaults = True,
  converters = None,
  sort_parameters = False,
  sort_key = None 
)

Definition at line 915 of file routing.py.

00915 
00916                  converters=None, sort_parameters=False, sort_key=None):
00917         self._rules = []
00918         self._rules_by_endpoint = {}
00919         self._remap = True
00920 
00921         self.default_subdomain = default_subdomain
00922         self.charset = charset
00923         self.strict_slashes = strict_slashes
00924         self.redirect_defaults = redirect_defaults
00925 
00926         self.converters = DEFAULT_CONVERTERS.copy()
00927         if converters:
00928             self.converters.update(converters)
00929 
00930         self.sort_parameters = sort_parameters
00931         self.sort_key = sort_key
00932 
00933         for rulefactory in rules or ():
00934             self.add(rulefactory)


Member Function Documentation

def MoinMoin.support.werkzeug.routing.Map.add (   self,
  rulefactory 
)
Add a new rule or factory to the map and bind it.  Requires that the
rule is not bound to another map.

:param rulefactory: a :class:`Rule` or :class:`RuleFactory`

Definition at line 966 of file routing.py.

00966 
00967     def add(self, rulefactory):
00968         """Add a new rule or factory to the map and bind it.  Requires that the
00969         rule is not bound to another map.
00970 
00971         :param rulefactory: a :class:`Rule` or :class:`RuleFactory`
00972         """
00973         for rule in rulefactory.get_rules(self):
00974             rule.bind(self)
00975             self._rules.append(rule)
00976             self._rules_by_endpoint.setdefault(rule.endpoint, []).append(rule)
00977         self._remap = True

Here is the call graph for this function:

def MoinMoin.support.werkzeug.routing.Map.bind (   self,
  server_name,
  script_name = None,
  subdomain = None,
  url_scheme = 'http',
  default_method = 'GET',
  path_info = None 
)
Return a new :class:`MapAdapter` with the details specified to the
call.  Note that `script_name` will default to ``'/'`` if not further
specified or `None`.  The `server_name` at least is a requirement
because the HTTP RFC requires absolute URLs for redirects and so all
redirect exceptions raised by Werkzeug will contain the full canonical
URL.

If no path_info is passed to :meth:`match` it will use the default path
info passed to bind.  While this doesn't really make sense for
manual bind calls, it's useful if you bind a map to a WSGI
environment which already contains the path info.

`subdomain` will default to the `default_subdomain` for this map if
no defined. If there is no `default_subdomain` you cannot use the
subdomain feature.

Definition at line 979 of file routing.py.

00979 
00980              url_scheme='http', default_method='GET', path_info=None):
00981         """Return a new :class:`MapAdapter` with the details specified to the
00982         call.  Note that `script_name` will default to ``'/'`` if not further
00983         specified or `None`.  The `server_name` at least is a requirement
00984         because the HTTP RFC requires absolute URLs for redirects and so all
00985         redirect exceptions raised by Werkzeug will contain the full canonical
00986         URL.
00987 
00988         If no path_info is passed to :meth:`match` it will use the default path
00989         info passed to bind.  While this doesn't really make sense for
00990         manual bind calls, it's useful if you bind a map to a WSGI
00991         environment which already contains the path info.
00992 
00993         `subdomain` will default to the `default_subdomain` for this map if
00994         no defined. If there is no `default_subdomain` you cannot use the
00995         subdomain feature.
00996         """
00997         if subdomain is None:
00998             subdomain = self.default_subdomain
00999         if script_name is None:
01000             script_name = '/'
01001         return MapAdapter(self, server_name, script_name, subdomain,
01002                           url_scheme, path_info, default_method)

Here is the caller graph for this function:

def MoinMoin.support.werkzeug.routing.Map.bind_to_environ (   self,
  environ,
  server_name = None,
  subdomain = None 
)
Like :meth:`bind` but you can pass it an WSGI environment and it
will fetch the information from that directory.  Note that because of
limitations in the protocol there is no way to get the current
subdomain and real `server_name` from the environment.  If you don't
provide it, Werkzeug will use `SERVER_NAME` and `SERVER_PORT` (or
`HTTP_HOST` if provided) as used `server_name` with disabled subdomain
feature.

If `subdomain` is `None` but an environment and a server name is
provided it will calculate the current subdomain automatically.
Example: `server_name` is ``'example.com'`` and the `SERVER_NAME`
in the wsgi `environ` is ``'staging.dev.example.com'`` the calculated
subdomain will be ``'staging.dev'``.

If the object passed as environ has an environ attribute, the value of
this attribute is used instead.  This allows you to pass request
objects.  Additionally `PATH_INFO` added as a default ot the
:class:`MapAdapter` so that you don't have to pass the path info to
the match method.

.. versionchanged:: 0.5
    previously this method accepted a bogus `calculate_subdomain`
    parameter that did not have any effect.  It was removed because
    of that.

:param environ: a WSGI environment.
:param server_name: an optional server name hint (see above).
:param subdomain: optionally the current subdomain (see above).

Definition at line 1003 of file routing.py.

01003 
01004     def bind_to_environ(self, environ, server_name=None, subdomain=None):
01005         """Like :meth:`bind` but you can pass it an WSGI environment and it
01006         will fetch the information from that directory.  Note that because of
01007         limitations in the protocol there is no way to get the current
01008         subdomain and real `server_name` from the environment.  If you don't
01009         provide it, Werkzeug will use `SERVER_NAME` and `SERVER_PORT` (or
01010         `HTTP_HOST` if provided) as used `server_name` with disabled subdomain
01011         feature.
01012 
01013         If `subdomain` is `None` but an environment and a server name is
01014         provided it will calculate the current subdomain automatically.
01015         Example: `server_name` is ``'example.com'`` and the `SERVER_NAME`
01016         in the wsgi `environ` is ``'staging.dev.example.com'`` the calculated
01017         subdomain will be ``'staging.dev'``.
01018 
01019         If the object passed as environ has an environ attribute, the value of
01020         this attribute is used instead.  This allows you to pass request
01021         objects.  Additionally `PATH_INFO` added as a default ot the
01022         :class:`MapAdapter` so that you don't have to pass the path info to
01023         the match method.
01024 
01025         .. versionchanged:: 0.5
01026             previously this method accepted a bogus `calculate_subdomain`
01027             parameter that did not have any effect.  It was removed because
01028             of that.
01029 
01030         :param environ: a WSGI environment.
01031         :param server_name: an optional server name hint (see above).
01032         :param subdomain: optionally the current subdomain (see above).
01033         """
01034         if hasattr(environ, 'environ'):
01035             environ = environ.environ
01036         if server_name is None:
01037             if 'HTTP_HOST' in environ:
01038                 server_name = environ['HTTP_HOST']
01039             else:
01040                 server_name = environ['SERVER_NAME']
01041                 if (environ['wsgi.url_scheme'], environ['SERVER_PORT']) not \
01042                    in (('https', '443'), ('http', '80')):
01043                     server_name += ':' + environ['SERVER_PORT']
01044         elif subdomain is None:
01045             cur_server_name = environ.get('HTTP_HOST',
01046                 environ['SERVER_NAME']).split(':', 1)[0].split('.')
01047             real_server_name = server_name.split(':', 1)[0].split('.')
01048             offset = -len(real_server_name)
01049             if cur_server_name[offset:] != real_server_name:
01050                 raise ValueError('the server name provided (%r) does not '
01051                                  'match the server name from the WSGI '
01052                                  'environment (%r)' %
01053                                  (environ['SERVER_NAME'], server_name))
01054             subdomain = '.'.join(filter(None, cur_server_name[:offset]))
01055         return Map.bind(self, server_name, environ.get('SCRIPT_NAME'),
01056                         subdomain, environ['wsgi.url_scheme'],
01057                         environ['REQUEST_METHOD'], environ.get('PATH_INFO'))

def MoinMoin.support.werkzeug.routing.Map.is_endpoint_expecting (   self,
  endpoint,
  arguments 
)
Iterate over all rules and check if the endpoint expects
the arguments provided.  This is for example useful if you have
some URLs that expect a language code and others that do not and
you want to wrap the builder a bit so that the current language
code is automatically added if not provided but endpoints expect
it.

:param endpoint: the endpoint to check.
:param arguments: this function accepts one or more arguments
          as positional arguments.  Each one of them is
          checked.

Definition at line 935 of file routing.py.

00935 
00936     def is_endpoint_expecting(self, endpoint, *arguments):
00937         """Iterate over all rules and check if the endpoint expects
00938         the arguments provided.  This is for example useful if you have
00939         some URLs that expect a language code and others that do not and
00940         you want to wrap the builder a bit so that the current language
00941         code is automatically added if not provided but endpoints expect
00942         it.
00943 
00944         :param endpoint: the endpoint to check.
00945         :param arguments: this function accepts one or more arguments
00946                           as positional arguments.  Each one of them is
00947                           checked.
00948         """
00949         self.update()
00950         arguments = set(arguments)
00951         for rule in self._rules_by_endpoint[endpoint]:
00952             if arguments.issubset(rule.arguments):
00953                 return True
00954         return False

Here is the call graph for this function:

def MoinMoin.support.werkzeug.routing.Map.iter_rules (   self,
  endpoint = None 
)
Iterate over all rules or the rules of an endpoint.

:param endpoint: if provided only the rules for that endpoint
         are returned.
:return: an iterator

Definition at line 955 of file routing.py.

00955 
00956     def iter_rules(self, endpoint=None):
00957         """Iterate over all rules or the rules of an endpoint.
00958 
00959         :param endpoint: if provided only the rules for that endpoint
00960                          are returned.
00961         :return: an iterator
00962         """
00963         if endpoint is not None:
00964             return iter(self._rules_by_endpoint[endpoint])
00965         return iter(self._rules)

Called before matching and building to keep the compiled rules
in the correct order after things changed.

Definition at line 1058 of file routing.py.

01058 
01059     def update(self):
01060         """Called before matching and building to keep the compiled rules
01061         in the correct order after things changed.
01062         """
01063         if self._remap:
01064             self._rules.sort(lambda a, b: a.match_compare(b))
01065             for rules in self._rules_by_endpoint.itervalues():
01066                 rules.sort(lambda a, b: a.build_compare(b))
01067             self._remap = False
01068 

Here is the caller graph for this function:


Member Data Documentation

Definition at line 918 of file routing.py.

Definition at line 916 of file routing.py.

Definition at line 917 of file routing.py.

Definition at line 921 of file routing.py.

Definition at line 925 of file routing.py.

Definition at line 920 of file routing.py.

Definition at line 923 of file routing.py.

Definition at line 930 of file routing.py.

Definition at line 929 of file routing.py.

Definition at line 922 of file routing.py.


The documentation for this class was generated from the following file: