[Twisted-web] HTTPChannel class attributes

exarkun at twistedmatrix.com exarkun at twistedmatrix.com
Sat Oct 6 09:30:08 EDT 2012

On 06:46 am, ardesai at yahoo.com wrote:
>Should http.py :: HTTPChannel.__first_line be an instance attribute 
>instead of a class attribute?

It doesn't matter.  It "becomes" an "instance attribute" as soon as it 
is assigned a value.  This is probably covered in the Python 
documentation somewhere, but I can't find it.
>I have a custom scenario where I sub-classed HTTPChannel for my sub- 
>classed HTTPFactory.  In the DerivedHTTPChannel class I overrode the 
>allContentReceived() method.

The problem is that you cannot set __first_line to 1 in a subclass named 
`DerivedHTTPChannel`.  __first_line is a mangled attribute.  See 9.6 on:


Additionally, anything starting with "_" is private and if you use it, 
your code is more likely to be broken by a future release of Twisted.

See http://twistedmatrix.com/trac/wiki/CompatibilityPolicy

What are you trying to accomplish with your HTTPChannel subclass?

>I recently enabled persistent connections, but setting 
>self.__first_line = 1 in the DerivedHTTPChannel was ineffective, and 
>the first line of the next request threw an exception when it got 
>parsed as an http header.  Similar question "probably" apply to other 
>class attributes.
>Should such attributes be instance attributes instead of class 
>attributes? Or is it anticipated that any class who derives from 
>HTTPChannel should override almost all the methods of the base class?

More information about the Twisted-web mailing list