WebKit.URLParser | index /usr/local/share/webware/WebKit/URLParser.py

`URLParser
URL parsing is done through objects which are subclasses of the `URLParser`
class. `Application` delegates most of the URL parsing to these objects.
Application has a single "root" URL parser, which is used to parse all URLs.
This parser then can pass the request on to other parsers, usually taking off
parts of the URL with each step.
This root parser is generally `ContextParser`, which is instantiated and set
up by `Application` (accessible through `Application.rootURLParser`).`

Modules

``

os | re | sys |

Classes

``

__builtin__.object
  ServletFactoryManagerClass
  URLParser
    ContextParser
    URLParameterParser

class ContextParser(URLParser)

``

`Find the context of a request.
ContextParser uses the ``Application.config`` context settings to find
the context of the request. It then passes the request to a FileParser
rooted in the context path.
The context is the first element of the URL, or if no context matches
that then it is the ``default`` context (and the entire URL is passed
to the default context's FileParser).
There is generally only one ContextParser, which can be found as
``application.rootURLParser()``.
`

Method resolution order:
  ContextParser
  URLParser
  __builtin__.object

Methods defined here:

__init__(self, app)
  `Create ContextParser.
  ContextParser is usually created by Application, which
  passes all requests to it.
  In __init__ we take the ``Contexts`` setting from
  Application.config and parse it slightly.`

absContextPath(self, path)
  `Get absolute context path.
  Resolves relative paths, which are assumed to be relative to the
  Application's serverSidePath (the working directory).`

addContext(self, name, dir)
  `Add a context to the system.
  The context will be imported as a package, going by `name`,
  from the given directory. The directory doesn't have to match
  the context name.`

parse(self, trans, requestPath)
  `Parse request.
  Get the context name, and dispatch to a FileParser rooted
  in the context's path.
  The context name and file path are stored in the request (accessible
  through `Request.serverSidePath` and `Request.contextName`).`

resolveDefaultContext(self, name, dest)
  `Find default context.
  Figure out if the default context refers to an existing context,
  the same directory as an existing context, or a unique directory.
  Returns the name of the context that the default context refers to,
  or 'default' if the default context is unique.`

Methods inherited from URLParser:

findServletForTransaction(self, trans)
  `Returns a servlet for the transaction.
  This is the top-level entry point, below it `parse` is used.`

Data descriptors inherited from URLParser:

__dict__
  `dictionary for instance variables (if defined)`

__weakref__
  `list of weak references to the object (if defined)`

class ServletFactoryManagerClass(__builtin__.object)
`` | `Manage servlet factories. This singleton (called `ServletFactoryManager`) collects and manages all the servlet factories that are installed. See `addServletFactory` for adding new factories, and `servletForFile` for getting the factories back.`

Methods defined here:

__init__(self)

addServletFactory(self, factory)
  `Add a new servlet factory.
  Servlet factories can add themselves with::
  ServletFactoryManager.addServletFactory(factory)
  The factory must have an `extensions` method, which should
  return a list of extensions that the factory handles (like
  ``['.ht']``). The special extension ``.*`` will match any
  file if no other factory is found. See `ServletFactory`
  for more information.`

factoryForFile(self, path)
  `Get a factory for a filename.`

reset(self)

servletForFile(self, trans, path)
  `Get a servlet for a filename and transaction.
  Uses `factoryForFile` to find the factory, which
  creates the servlet.`

Data descriptors defined here:

__dict__
  `dictionary for instance variables (if defined)`

__weakref__
  `list of weak references to the object (if defined)`

class URLParameterParser(URLParser)

``

`Strips named parameters out of the URL.
E.g. in ``/path/SID=123/etc`` the ``SID=123`` will be removed from the URL,
and a field will be set in the request (so long as no field by that name
already exists -- if a field does exist the variable is thrown away).
These are put in the place of GET or POST variables.
It should be put in an __init__, like::
from WebKit.URLParser import URLParameterParser
urlParserHook = URLParameterParser()
Or (slightly less efficient):
from WebKit.URLParser import URLParameterParser as SubParser
`

Method resolution order:
  URLParameterParser
  URLParser
  __builtin__.object

Methods defined here:

__init__(self, fileParser=None)

parse(self, trans, requestPath)
  `Delegates to `parseHook`.`

Static methods defined here:

parseHook(trans, requestPath, hook)
  `Munges the path.
  The `hook` is the FileParser object that originally called this --
  we just want to strip stuff out of the URL and then give it back to
  the FileParser instance, which can actually find the servlet.`

Methods inherited from URLParser:

findServletForTransaction(self, trans)
  `Returns a servlet for the transaction.
  This is the top-level entry point, below it `parse` is used.`

Data descriptors inherited from URLParser:

__dict__
  `dictionary for instance variables (if defined)`

__weakref__
  `list of weak references to the object (if defined)`

class URLParser(__builtin__.object)

``

`URLParser is the base class for all URL parsers.
Though its functionality is sparse, it may be expanded in the future.
Subclasses should implement a `parse` method, and may also want to
implement an `__init__` method with arguments that control how the
parser works (for instance, passing a starting path for the parser)
The `parse` method is where most of the work is done. It takes two
arguments -- the transaction and the portion of the URL that is still to
be parsed. The transaction may (and usually is) modified along the way.
The URL is passed through so that you can take pieces off the front,
and then pass the reduced URL to another parser. The method should return
a servlet (never None).
If you cannot find a servlet, or some other (somewhat) expected error
occurs, you should raise an exception. HTTPNotFound probably being the
most interesting.
`

Methods defined here:

__init__(self)

findServletForTransaction(self, trans)
  `Returns a servlet for the transaction.
  This is the top-level entry point, below it `parse` is used.`

Data descriptors defined here:

__dict__
  `dictionary for instance variables (if defined)`

__weakref__
  `list of weak references to the object (if defined)`

Functions

``

application()
  `Returns the global Application.`

initApp(app)
  `Initialize the application.
  Installs the proper servlet factories, and gets some settings from
  Application.config. Also saves the application in _globalApplication
  for future calls to the application() function.
  This needs to be called before any of the URLParser-derived classes
  are instantiated.`

initParser(app)
  `Initialize the FileParser Class.`

warn(...)
  `Issue a warning, or maybe ignore it or raise an exception.`

Data
`` |  | FileParser = <MiscUtils.ParamFactory.ParamFactory object> ServletFactoryManager = <WebKit.URLParser.ServletFactoryManagerClass object> debug = False