[Zope-dev] Constant values defined in interfaces

Wichert Akkerman wichert at wiggy.net
Fri Apr 3 19:21:14 EDT 2009


Previously Chris Rossi wrote:
> I was wondering if the Zope collective had given any consideration to
> allowing constants to be defined in interfaces.  To be clear, these are
> constant values that make up the protocol defined by the interface.  Just to
> have a concrete example, let's say we're modeling an http response:
> 
> class IHttpResponse(Interface):
>     """Models an HTTP 1.1 response.
>     """
>     status = Attribute("HTTP status code for this response.")
> 
> It might be useful to include in our interface spec what some proper values
> for status code might be and make them available to applications as static
> constants on the interface class.  A naive implementer might do something
> like this:
> 
> class IHttpResponse(Interface):
>     """Models an HTTP 1.1 response.
>     """
>     HTTP_OK = "200 Ok"
>     HTTP_NOT_FOUND = "404 Not Found"
> 
>     status = Attribute("HTTP status code for this response.")

This looks like a poor man's enum. I'ld prefer to have a proper enum
like thing.

Wichert.

-- 
Wichert Akkerman <wichert at wiggy.net>    It is simple to make things.
http://www.wiggy.net/                   It is hard to make things simple.


More information about the Zope-Dev mailing list