[Python-checkins] r42089 - python/trunk/Doc/lib/libasyncore.tex

fredrik.lundh python-checkins at python.org
Tue Jan 17 22:31:31 CET 2006


Author: fredrik.lundh
Date: Tue Jan 17 22:31:31 2006
New Revision: 42089

Modified:
   python/trunk/Doc/lib/libasyncore.tex
Log:
fixed example:
adding missing import, handle_close, test code, etc.



Modified: python/trunk/Doc/lib/libasyncore.tex
==============================================================================
--- python/trunk/Doc/lib/libasyncore.tex	(original)
+++ python/trunk/Doc/lib/libasyncore.tex	Tue Jan 17 22:31:31 2006
@@ -222,29 +222,37 @@
 
 \subsection{asyncore Example basic HTTP client \label{asyncore-example}}
 
-As a basic example, below is a very basic HTTP client that uses the 
-\class{dispatcher} class to implement its socket handling:
+Here is a very basic HTTP client that uses the \class{dispatcher}
+class to implement its socket handling:
 
 \begin{verbatim}
+import asyncore, socket
+
 class http_client(asyncore.dispatcher):
-    def __init__(self, host,path):
+
+    def __init__(self, host, path):
         asyncore.dispatcher.__init__(self)
-        self.path = path
         self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
         self.connect( (host, 80) )
-        self.buffer = 'GET %s HTTP/1.0\r\n\r\n' % self.path
-        
+        self.buffer = 'GET %s HTTP/1.0\r\n\r\n' % path
+
     def handle_connect(self):
         pass
-        
+
+    def handle_close(self):
+        self.close()
+
     def handle_read(self):
-        data = self.recv(8192)
-        print data
-        
+        print self.recv(8192)
+
     def writable(self):
         return (len(self.buffer) > 0)
-    
+
     def handle_write(self):
         sent = self.send(self.buffer)
         self.buffer = self.buffer[sent:]
+
+c = http_client('www.python.org', '/')
+
+asyncore.loop()
 \end{verbatim}


More information about the Python-checkins mailing list