Re: why () is () and [] is [] work in other way?

2012-04-20 Thread john . tantalo
On Friday, April 20, 2012 12:34:46 PM UTC-7, Rotwang wrote:

> I believe it says somewhere in the Python docs that it's undefined and 
> implementation-dependent whether two identical expressions have the same 
> identity when the result of each is immutable

I was curious where that might be on my system, and found the disagreement with 
the ((),) case and up.

(Python 2.7.1, Darwin 11.3.0, GCC 4.2.1)
-- 
http://mail.python.org/mailman/listinfo/python-list


parameterized classes

2008-07-24 Thread John Tantalo
Is there is a better way to create parameterized classes than defining and
returning a class in a closure? I ask because I want to create arbitrary
BaseRequestHandler subclasses that delegate line handling to a given line
handler, as in this example:
  from SocketServer import *

  class ThreadingTCPServer(ThreadingMixIn, TCPServer): pass

  def LineRequestHandler(handler):
class __LineRequestHandler(BaseRequestHandler):
  def handle(self):
for line in self.lines():
  handler.handle(line)

  def lines(self):
line = self.line()
while line:
  yield line
  line = self.line()

  def line(self):
parts = []
while not parts or parts[-1] and not parts[-1][-1] == "\n":
  parts.append(self.request.recv(2**10))
if parts:
  return ''.join(parts)[0:-1]

return __LineRequestHandler

  class SomeLineHandler:
def handle(self, line):
  print "I got a line: %s" % line

  if __name__ == '__main__':
s = ThreadingTCPServer(("", 2005),
LineRequestHandler(SomeLineHandler()))
s.serve_forever()

I really wish I could create a class whose instances were classes that
subclassed BaseRequestHandler. Is this possible, or is there a better way
than my approach here? Or am I crazy?

And I may be dense, so if there is an easier way to stream sockets as line
streams, please let me know. I honestly don't think it should be this
difficult to implement a socket handler this simple.
--
http://mail.python.org/mailman/listinfo/python-list