• Lucid Dreaming - Dream Views




    Results 1 to 25 of 28
    Like Tree2Likes

    Thread: Ask me about Python

    Threaded View

    1. #23
      Rational Spiritualist DrunkenArse's Avatar
      Join Date
      May 2009
      Gender
      Location
      Da Aina
      Posts
      2,941
      Likes
      1092
      It's kinda tough for me to help with this as I'm limited to coding in javascript at the moment. Hence I can't post running code.

      It seems like it would be best to make IrcSocket a wrapper class that provides the necessary functionality using parasitic inheritance instead of classical inheritance. IIRC, socket.socket is a c class and things can get pretty hair extending those. Something like

      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)
      Then you can get your hands on one with something like

      Code:
       
        ircsocket = IrcSocket(some_id, socket.socket(socket.AF_INET, socket.SOCK_STREAM))
      This just instantiates the socket inline and immiediately passes it to the IrcSocket class constructor.

      You can just do

      Code:
       
      wrapped_socket =  IrcSocket(some_id, socket.accept(*args))
      to wrap the regular socket that socket.accept returns. Again, you're just making the call inline and passing it to the constructor.

      Like I said, that's psuedocode because I can't run it and I don't have the library memorized but that's the basic idea.
      Last edited by PhilosopherStoned; 07-19-2011 at 11:35 PM.
      Previously PhilosopherStoned

    Similar Threads

    1. Pass Variables Between JavaScript and C++/Python?
      By youssarian in forum Tech Talk
      Replies: 6
      Last Post: 01-12-2010, 04:27 AM
    2. Halp! (Python)
      By ThreeLetterSyndrom in forum Tech Talk
      Replies: 5
      Last Post: 06-23-2009, 09:43 PM
    3. Tell me about Python
      By DuB in forum Tech Talk
      Replies: 9
      Last Post: 04-29-2009, 04:55 PM
    4. Python Reality Check Tester
      By Wesley_Gray in forum Lucid Aids
      Replies: 10
      Last Post: 08-01-2008, 02:16 AM
    5. Fav Python Quotes
      By Mystical_Journey in forum The Lounge
      Replies: 20
      Last Post: 05-12-2005, 09:50 PM

    Bookmarks

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •