Damn I'm rusty. I wouldn't access __dict__ directly here but use getattr instead. Also, I would equip it with a factory function to create instances. All it has to do is pass its arguments to the constructor for socket and wrap the result before it returns it.
Code:
class IrcSocket: #No need to extend object because this is p3k
def __init__(self, id, socket):
self.id = id
self._socket = socket
def send(self, bytes):
log(bytes)
socket.socket.sendall(self._socket, bytes)
def accept(self, *args, **kwargs):
tmp_socket = self._socket.accept(*args, **kwargs)
return type(self)(some_id*args, tmp_socket)
def __getattr__(self, attr):
return getattr(self._socket, attr)
@classmethod
def new(cls, *args, **kwargs):
return cls(socket.socket(*args, **kwargs))
The classmethod is called on the class and not on instances. So you would call it like IrcSocket.new(*args, **kwargs) where args and kwargs are the arguments that you would use to construct the normal socket. If you need custom arguments, then let me know and I can show you how to do that.
@ninja. I don't reallty want to debate this. The assertion that c++ is "the most strongly typed language behind only ada" is laughable. Python is much more strongly typed than c++. Haskell is even more so (and avoids the annoying type declarations in many cases). Arbitrary casting is weak typing as you implied a few posts ago. Granted, it's not as bad as PHP or Javascript (otherwise a great language) but it's still a weakly typed language. It's also a statically typed language. So it gets you all the inconvenience of a statically typed language with only a few of the benefits of strong typing. As I said though, it's possible to program in a strongly typed subset of it. If you do so, then great.
At any rate, your whole argument is cast in terms of absolutes that are just wrong. This is typical of your thinking. I have not a shred of respect for you and am not interested in debating this point with you. Please GTFO my thread. Thanks.
Bookmarks