Mercurial > p > roundup > code
comparison roundup/scripts/roundup_server.py @ 2674:18a23afb1f89
replace "from module import *" with "import module"...
...for win32event and win32file: both export class 'error'
overriding error function defined in this script.
thanks pychecker for finding names to resolve!
| author | Alexander Smishlajev <a1s@users.sourceforge.net> |
|---|---|
| date | Tue, 21 Sep 2004 08:01:15 +0000 |
| parents | 11811b313459 |
| children | 52e679309217 |
comparison
equal
deleted
inserted
replaced
| 2673:63f8b13ba85f | 2674:18a23afb1f89 |
|---|---|
| 15 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. | 15 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
| 16 # | 16 # |
| 17 | 17 |
| 18 """Command-line script that runs a server over roundup.cgi.client. | 18 """Command-line script that runs a server over roundup.cgi.client. |
| 19 | 19 |
| 20 $Id: roundup_server.py,v 1.59 2004-07-27 01:59:28 richard Exp $ | 20 $Id: roundup_server.py,v 1.60 2004-09-21 08:01:15 a1s Exp $ |
| 21 """ | 21 """ |
| 22 __docformat__ = 'restructuredtext' | 22 __docformat__ = 'restructuredtext' |
| 23 | 23 |
| 24 # python version check | 24 # python version check |
| 25 from roundup import version_check | 25 from roundup import version_check |
| 230 else: | 230 else: |
| 231 | 231 |
| 232 # allow the win32 | 232 # allow the win32 |
| 233 import win32service | 233 import win32service |
| 234 import win32event | 234 import win32event |
| 235 from win32event import * | 235 import win32file |
| 236 from win32file import * | |
| 237 | 236 |
| 238 SvcShutdown = "ServiceShutdown" | 237 SvcShutdown = "ServiceShutdown" |
| 239 | 238 |
| 240 class RoundupService(win32serviceutil.ServiceFramework, | 239 class RoundupService(win32serviceutil.ServiceFramework, |
| 241 BaseHTTPServer.HTTPServer): | 240 BaseHTTPServer.HTTPServer): |
| 277 except SvcShutdown: | 276 except SvcShutdown: |
| 278 pass | 277 pass |
| 279 | 278 |
| 280 def get_request(self): | 279 def get_request(self): |
| 281 # Call WSAEventSelect to enable self.socket to be waited on. | 280 # Call WSAEventSelect to enable self.socket to be waited on. |
| 282 WSAEventSelect(self.socket, self.hevConn, FD_ACCEPT) | 281 win32file.WSAEventSelect(self.socket, self.hevConn, |
| 282 win32file.FD_ACCEPT) | |
| 283 while 1: | 283 while 1: |
| 284 try: | 284 try: |
| 285 rv = self.socket.accept() | 285 rv = self.socket.accept() |
| 286 except socket.error, why: | 286 except socket.error, why: |
| 287 if why[0] != WSAEWOULDBLOCK: | 287 if why[0] != win32file.WSAEWOULDBLOCK: |
| 288 raise | 288 raise |
| 289 # Use WaitForMultipleObjects instead of select() because | 289 # Use WaitForMultipleObjects instead of select() because |
| 290 # on NT select() is only good for sockets, and not general | 290 # on NT select() is only good for sockets, and not general |
| 291 # NT synchronization objects. | 291 # NT synchronization objects. |
| 292 rc = WaitForMultipleObjects((self.hevSvcStop, self.hevConn), | 292 rc = win32event.WaitForMultipleObjects( |
| 293 0, INFINITE) | 293 (self.hevSvcStop, self.hevConn), |
| 294 if rc == WAIT_OBJECT_0: | 294 0, win32event.INFINITE) |
| 295 if rc == win32event.WAIT_OBJECT_0: | |
| 295 # self.hevSvcStop was signaled, this means: | 296 # self.hevSvcStop was signaled, this means: |
| 296 # Stop the service! | 297 # Stop the service! |
| 297 # So we throw the shutdown exception, which gets | 298 # So we throw the shutdown exception, which gets |
| 298 # caught by self.SvcDoRun | 299 # caught by self.SvcDoRun |
| 299 raise SvcShutdown | 300 raise SvcShutdown |
| 300 # Otherwise, rc == WAIT_OBJECT_0 + 1 which means | 301 # Otherwise, rc == win32event.WAIT_OBJECT_0 + 1 which means |
| 301 # self.hevConn was signaled, which means when we call | 302 # self.hevConn was signaled, which means when we call |
| 302 # self.socket.accept(), we'll have our incoming connection | 303 # self.socket.accept(), we'll have our incoming connection |
| 303 # socket! | 304 # socket! |
| 304 # Loop back to the top, and let that accept do its thing... | 305 # Loop back to the top, and let that accept do its thing... |
| 305 else: | 306 else: |
| 311 # WSAEventSelect, and whether its a blocking socket or not.) | 312 # WSAEventSelect, and whether its a blocking socket or not.) |
| 312 # | 313 # |
| 313 # So if you yank the following line, the setblocking() call | 314 # So if you yank the following line, the setblocking() call |
| 314 # will be useless. The socket will still be in non-blocking | 315 # will be useless. The socket will still be in non-blocking |
| 315 # mode. | 316 # mode. |
| 316 WSAEventSelect(rv[0], self.hevConn, 0) | 317 win32file.WSAEventSelect(rv[0], self.hevConn, 0) |
| 317 rv[0].setblocking(1) | 318 rv[0].setblocking(1) |
| 318 break | 319 break |
| 319 return rv | 320 return rv |
| 320 | 321 |
| 321 def usage(message=''): | 322 def usage(message=''): |
