Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #42815

Re: HTTPserver: how to access variables of a higher class?

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news-1.dfn.de!news.dfn.de!news.informatik.hu-berlin.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From Tom P <werotizy@freent.dd>
Newsgroups comp.lang.python
Subject Re: HTTPserver: how to access variables of a higher class?
Date Fri, 05 Apr 2013 15:21:12 +0200
Lines 50
Message-ID <as81e9Fu028U1@mid.individual.net> (permalink)
References <as7paeFs5e9U1@mid.individual.net> <mailman.135.1365164884.3114.python-list@python.org>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Trace individual.net hmxHXrFh0YvZZl/XPoRVOgjkZ1aUM1VHvaIf659nLodv+ws3Q=
Cancel-Lock sha1:cdtcT2PClJZDqhtSq6euWfOG6wI=
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121011 Thunderbird/16.0.1
In-Reply-To <mailman.135.1365164884.3114.python-list@python.org>
Xref csiph.com comp.lang.python:42815

Show key headers only | View raw


On 04/05/2013 02:27 PM, Dylan Evans wrote:
> On 05/04/2013 9:09 PM, "Tom P" <werotizy@freent.dd> wrote:
>>
>> First, here's a sample test program:
>> <code>
>> import sys
>> from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
>>
>> class MyRequestHandler(BaseHTTPRequestHandler, object):
>>      def do_GET(self):
>>          top_self = super(MyRequestHandler, self) # try to access
> MyWebServer instance
>>          self.send_response(200)
>>          self.send_header('Content-type',        'text/html')
>>          self.end_headers()
>>          self.wfile.write("thanks for trying, but I'd like to get at
> self.foo and self.bar")
>>          return
>>
>> class MyWebServer(object):
>>      def __init__(self):
>>          self.foo = "foo"  # these are what I want to access from inside
> do_GET
>>          self.bar = "bar"
>>          self.httpd = HTTPServer(('127.0.0.1', 8000), MyRequestHandler)
>>          sa = self.httpd.socket.getsockname()
>>          print "Serving HTTP on", sa[0], "port", sa[1], "..."
>>
>>      def runIt(self):
>>          self.httpd.serve_forever()
>>
>> server = MyWebServer()
>> server.runIt()
>>
>> </code>
>>
>> I want to access the foo and bar variables from do_GET, but I can't
> figure out how. I suppose this is something to do with new-style vs.
> old-style classes, but I lost for a solution.
>
> Consider inheriting HTTPServer in MyWebServer which is passed to the
> request handler.
>

That was the next thing I was going to try, thanks.

>> --
>> http://mail.python.org/mailman/listinfo/python-list
>

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

HTTPserver: how to access variables of a higher class? Tom P <werotizy@freent.dd> - 2013-04-05 13:02 +0200
  Re: HTTPserver: how to access variables of a higher class? Dave Angel <davea@davea.name> - 2013-04-05 07:54 -0400
    Re: HTTPserver: how to access variables of a higher class? Tom P <werotizy@freent.dd> - 2013-04-05 15:26 +0200
    Re: HTTPserver: how to access variables of a higher class? Tom P <werotizy@freent.dd> - 2013-04-05 23:41 +0200
      Re: HTTPserver: how to access variables of a higher class? Dave Angel <davea@davea.name> - 2013-04-05 23:19 -0400
  Re: HTTPserver: how to access variables of a higher class? Dylan Evans <dylan@dje.me> - 2013-04-05 22:27 +1000
    Re: HTTPserver: how to access variables of a higher class? Tom P <werotizy@freent.dd> - 2013-04-05 15:21 +0200
    Re: HTTPserver: how to access variables of a higher class? Tom P <werotizy@freent.dd> - 2013-04-06 17:05 +0200
      Re: HTTPserver: how to access variables of a higher class? Dylan Evans <dylan@dje.me> - 2013-04-07 11:51 +1000
  Re: The SOLUTION HTTPserver: how to access variables of a higher class Tom P <werotizy@freent.dd> - 2013-04-06 23:38 +0200

csiph-web