[Twisted-Python] What the hell?

From tcp.py: ============ class Client(Connection): """A client for TCP (and similiar) sockets. """ def __init__(self, host, port, protocol): """Initialize the client, setting up its socket, and request to connect. """ if host == 'unix': # "port" in this case is really a filename ... ============ That is sooo wrong. What if my computer is named 'unix'? Why does the TCP code deal with files?

From: Itamar <twisted@itamarst.org> Subject: [Twisted-Python] What the hell? Date: Fri, 31 Aug 2001 13:15:16 -0400
From tcp.py:
============ class Client(Connection): """A client for TCP (and similiar) sockets. """ def __init__(self, host, port, protocol): """Initialize the client, setting up its socket, and request to connect. """ if host == 'unix': # "port" in this case is really a filename ... ============
That is sooo wrong. What if my computer is named 'unix'? Why does the TCP code deal with files?
if you're adding xfstt to your fontpath, the url to use is unix:7101/ xfs is at unix:7100/ so I'd assume is specific to some kind of IPC. Therefore, I bet yer system will act strangely if you make your hostname 'unix' ---- Shae Matijs Erisson - http://www.webwitches.com/~shae/ bRing mE fIve sQuirrels aNd nO oNe wIll gEt hUrt 13:00pm up 1 season, 1 squirrel, load average: 1+1j 0.5+2j 0.2+0.5j

Right, but only part of the explanation :-). This has previously been discussed a little, and my initial this answer is here: http://twistedmatrix.com/pipermail/twisted-python/2001-July/000139.html On Fri, Aug 31, 2001 at 08:40:03PM +0300, Shae Erisson wrote:
if you're adding xfstt to your fontpath, the url to use is unix:7101/ xfs is at unix:7100/
so I'd assume is specific to some kind of IPC. Therefore, I bet yer system will act strangely if you make your hostname 'unix'
-- ______ __ __ _____ _ _ | ____ | \_/ |_____] |_____| |_____| |_____ | | | | @ t w i s t e d m a t r i x . c o m http://twistedmatrix.com/users/glyph

Glyph Lefkowitz wrote:
Right, but only part of the explanation :-). This has previously been discussed a little, and my initial this answer is here:
http://twistedmatrix.com/pipermail/twisted-python/2001-July/000139.html
OK. But checking by host == 'unix' is still pretty bad, IMHO. Maybe check for the port being a string instead? (and have the tcp.py docstrings document this.)

On Sun, 02 Sep 2001 10:00:11 -0400, Itamar wrote:
OK. But checking by host == 'unix' is still pretty bad, IMHO. Maybe check for the port being a string instead? (and have the tcp.py docstrings document this.)
If you want polymrphic addressing, you should use a class per address family. i.e. tuple -> socket (servername, port) class UnixFile -> an instance holding the filename ...

I agree. The transport for a client or server should probally not be generalized to a socket at all. Maybe this call for the creation of twisted.transport ? I am not familiar much with the twisted codebase, so excuse me if something like this already exists :) On Fri, Aug 31, 2001 at 01:15:16PM -0400, Itamar wrote:
From tcp.py:
============ class Client(Connection): """A client for TCP (and similiar) sockets. """ def __init__(self, host, port, protocol): """Initialize the client, setting up its socket, and request to connect. """ if host == 'unix': # "port" in this case is really a filename ... ============
That is sooo wrong. What if my computer is named 'unix'? Why does the TCP code deal with files?
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
-- python -c "print reduce(lambda x,y: x+y,map(lambda x: chr((23069453891\ 36636418523668102630431981680355427L>>(x*8))&0xFF),xrange(0,19)))"

I agree. The transport for a client or server should probally not be generalized to a socket at all. Maybe this calls for the creation of twisted.transport ? I am not familiar much with the twisted codebase, so please dont flame me if something like this already exists :) On Fri, Aug 31, 2001 at 01:15:16PM -0400, Itamar wrote:
From tcp.py:
============ class Client(Connection): """A client for TCP (and similiar) sockets. """ def __init__(self, host, port, protocol): """Initialize the client, setting up its socket, and request to connect. """ if host == 'unix': # "port" in this case is really a filename ... ============
That is sooo wrong. What if my computer is named 'unix'? Why does the TCP code deal with files?
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
-- python -c "print reduce(lambda x,y: x+y,map(lambda x: chr((23069453891\ 36636418523668102630431981680355427L>>(x*8))&0xFF),xrange(0,19)))"

I agree. The transport for a client or server should probally not be generalized to a socket at all. Maybe this calls for the creation of twisted.transport ? I am not familiar much with the twisted codebase, so don't kill me if something like this already exists :) On Fri, Aug 31, 2001 at 01:15:16PM -0400, Itamar wrote:
From tcp.py:
============ class Client(Connection): """A client for TCP (and similiar) sockets. """ def __init__(self, host, port, protocol): """Initialize the client, setting up its socket, and request to connect. """ if host == 'unix': # "port" in this case is really a filename ... ============
That is sooo wrong. What if my computer is named 'unix'? Why does the TCP code deal with files?
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
-- python -c "print reduce(lambda x,y: x+y,map(lambda x: chr((23069453891\ 36636418523668102630431981680355427L>>(x*8))&0xFF),xrange(0,19)))"

OOPS! I just switched ISPs and was figuring out my mail relay and the message got sent three times! /me curses exim. On Fri, Aug 31, 2001 at 11:51:45AM -0700, Chris Clearwater wrote:
I agree. The transport for a client or server should probally not be generalized to a socket at all. Maybe this calls for the creation of twisted.transport ? I am not familiar much with the twisted codebase, so don't kill me if something like this already exists :)
On Fri, Aug 31, 2001 at 01:15:16PM -0400, Itamar wrote:
From tcp.py:
============ class Client(Connection): """A client for TCP (and similiar) sockets. """ def __init__(self, host, port, protocol): """Initialize the client, setting up its socket, and request to connect. """ if host == 'unix': # "port" in this case is really a filename ... ============
That is sooo wrong. What if my computer is named 'unix'? Why does the TCP code deal with files?
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
-- python -c "print reduce(lambda x,y: x+y,map(lambda x: chr((23069453891\ 36636418523668102630431981680355427L>>(x*8))&0xFF),xrange(0,19)))"
-- python -c "print reduce(lambda x,y: x+y,map(lambda x: chr((23069453891\ 36636418523668102630431981680355427L>>(x*8))&0xFF),xrange(0,19)))"

On Fri, 31 Aug 2001, Chris Clearwater <chris@detriment.org> wrote:
I agree. The transport for a client or server should probally not be generalized to a socket at all. Maybe this calls for the creation of twisted.transport ? I am not familiar much with the twisted codebase, so don't kill me if something like this already exists :)
I'd like (at least) Port to be able to take a bound socket, instead of binding it itself. Then have a couple of convinience routines def InetPort(factory, port, interface='', backlog=5): sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.bind( (interface, port) ) sock.listen(backlog) return Port(factory, socket, 'INET') def UnixPort(factory, port, interface='', backlog=5): ... return Port(factory, socket, 'UNIX') The third argument is passed to the Server class, which puts it in .getPeer() -- The Official Moshe Zadka FAQ: http://moshez.geek The Official Moshe Zadka FAQ For Dummies: http://moshez.org Read the FAQ

On Sun, Sep 02, 2001 at 01:05:08AM +0300, Moshe Zadka wrote:
I'd like (at least) Port to be able to take a bound socket, instead of binding it itself. Then have a couple of convinience routines
def InetPort(factory, port, interface='', backlog=5): sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.bind( (interface, port) ) sock.listen(backlog) return Port(factory, socket, 'INET')
def UnixPort(factory, port, interface='', backlog=5): ... return Port(factory, socket, 'UNIX')
That would make the Port instance impossible to persist, and adds no value, unless there's some particular external API we need to interact with that speaks in terms of sockets... -- ______ __ __ _____ _ _ | ____ | \_/ |_____] |_____| |_____| |_____ | | | | @ t w i s t e d m a t r i x . c o m http://twistedmatrix.com/users/glyph

On Sat, 1 Sep 2001, Glyph Lefkowitz <glyph@twistedmatrix.com> wrote:
That would make the Port instance impossible to persist
Good point
, and adds no value, unless there's some particular external API we need to interact with that speaks in terms of sockets...
This would make it possible to bind() as root in a seperate C program and then to drop privs and execute Twisted. Also, that would help if you get the socket from another process over a UNIX domain socket. -- The Official Moshe Zadka FAQ: http://moshez.geek The Official Moshe Zadka FAQ For Dummies: http://moshez.org Read the FAQ

On Sun, Sep 02, 2001 at 08:02:12PM +0300, Moshe Zadka wrote:
On Sat, 1 Sep 2001, Glyph Lefkowitz <glyph@twistedmatrix.com> wrote:
unless there's some particular external API we need to interact with that speaks in terms of sockets...
This would make it possible to bind() as root in a seperate C program and then to drop privs and execute Twisted. Also, that would help if you get the socket from another process over a UNIX domain socket.
OK. First time we see one of these as an actual requirement, let's do it. 'Til then I think it's best to put it off. -- ______ __ __ _____ _ _ | ____ | \_/ |_____] |_____| |_____| |_____ | | | | @ t w i s t e d m a t r i x . c o m http://twistedmatrix.com/users/glyph
participants (6)
-
Chris Clearwater
-
Glyph Lefkowitz
-
Itamar
-
j.her@t-online.de
-
Moshe Zadka
-
Shae Erisson