summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorFredrik Lundh <fredrik@pythonware.com>2006-01-17 21:31:31 (GMT)
committerFredrik Lundh <fredrik@pythonware.com>2006-01-17 21:31:31 (GMT)
commitd790a7b596585a5726b8e7aa3e5c437944532bc0 (patch)
tree9bf6993a66dbcd98abb1cdacdac77d40b5c7ae19 /Doc
parent615320127428bc97c1e1dd96cf4ac5c8f407554c (diff)
downloadcpython-d790a7b596585a5726b8e7aa3e5c437944532bc0.zip
cpython-d790a7b596585a5726b8e7aa3e5c437944532bc0.tar.gz
cpython-d790a7b596585a5726b8e7aa3e5c437944532bc0.tar.bz2
fixed example:
adding missing import, handle_close, test code, etc.
Diffstat (limited to 'Doc')
-rw-r--r--Doc/lib/libasyncore.tex30
1 files changed, 19 insertions, 11 deletions
diff --git a/Doc/lib/libasyncore.tex b/Doc/lib/libasyncore.tex
index 65de1e4..4425da7 100644
--- a/Doc/lib/libasyncore.tex
+++ b/Doc/lib/libasyncore.tex
@@ -222,29 +222,37 @@ Most of these are nearly identical to their socket partners.
\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}