To simplify comparison between CoAP and HTTP, these classes are provided to support resources with an HTTP interface.
copyright: | Copyright 2013, Peter A. Bigot |
---|---|
license: | Apache-2.0 |
Bases: BaseHTTPServer.HTTPServer
Modifications required to provide the server development interface we want.
Bases: BaseHTTPServer.BaseHTTPRequestHandler
Modifications required to provide the server development interface we want.
This version inverts control relative to the Python standard web server hierarchy: Rather than have the supported methods defined by the generic handler, we follow REST principles and delegate the selection of supported methods to the resources. A HTTPRequestHandler class retains in _Resources a map from path prefixes to instances of HTTPResource which in turn provide the methods that are appropriate to that resource. Processing is delegated to the registered resource whose HTTPResource.path is the longest segment prefix of the request URI path.
Add resource to the registry for this class at resource.path. This function is automatically invoked in the constructor for HTTPResource.
Handle a single HTTP request.
Replace parts of BaseHTTPServer.BaseHTTPRequestHandler.handle_one_request() to identify a HTTPResource instance using the path part of the URI, and delegate all processing (including checking for supported methods) to that resource. If no segment prefix of path is associated with a registered resource a 404 error is returned to the client.
This function assigns split_uri.
Note
Resource lookup uses the the path part of the URI, exclusive of any query or fragment components that may also be present in path.
Find the best registered resource at path.
path is a slash-separated hierarchy of path segments. The registered resource for which HTTPResource.path matches a segmented prefix of path is returned. If no prefix matches, None is returned.
The results of invoking urlparse.urlsplit() on path.
Bases: object
Class supporting a resource with specific methods.
Instances of this class are delegates from HTTPRequestHandler (or a subclass). The appropriate resource is identified by a segment prefix of the path. do_FOO methods are implemented in the resource rather than in the request handler.
path is the absolute path to the resource. handler_class is (the subclass of) HTTPRequestHandler into which the created resource will be registered at path.
Note that the architectural model supports multiple instances of a resource class at different paths.
Stub for a GET method.
request is the instance of HTTPRequestHandler that has the request-specific data and ability to communicate results to the client. head_only is False normally, but may be set to True to allow this function to also implement the HEAD method: the implementation is responsible for eliding the body of the response in that case.
Process a single request.
The command from the request is append to do_ and the resulting method is invoked to execute the operation. If the command is not implemented, a 501 Unsupported Method error is returned to the client.
A read-only property providing the subclass of HTTPRequestHandler within which this resource is registered.
A read-only property specifying the prefix under which this resource is registered within handler_class.