def handleRequest(self): verbose = self._server._verbose self._startTime = time.time() if verbose: print '%5i %s ' % (self._requestID, timestamp()['pretty']), data = [] dict = self.receiveDict() if dict and verbose and dict.has_key('environ'): requestURI = Funcs.requestURI(dict['environ']) print requestURI else: requestURI = None dict['input'] = self.makeInput() streamOut = TASASStreamOut(self._sock) transaction = self._server._app.dispatchRawRequest(dict, streamOut) streamOut.close() try: self._sock.shutdown(1) self._sock.close() except: pass if self._server._verbose: duration = '%0.2f secs' % (time.time() - self._startTime) duration = string.ljust(duration, 19) print '%5i %s %s' % (self._requestID, duration, requestURI) print transaction._application = None transaction.die() del transaction
def testTimestamp(self): d = timestamp() self.assertIsInstance(d, dict) self.assertEqual(','.join(sorted(d)), 'condensed,dashed,pretty,tuple') self.assertEqual(len(d['tuple']), 6) self.assertEqual(len(d['condensed']), 14) self.assertEqual(len(d['pretty']), 19) self.assertEqual(len(d['dashed']), 19) t = time.time() d = timestamp(t) t = time.localtime(t)[:6] self.assertEqual(d['tuple'], t) self.assertEqual(d['condensed'], '{:4d}{:02d}{:02d}{:02d}{:02d}{:02d}'.format(*t)) self.assertEqual( d['condensed'], d['pretty'].replace('-', '').replace(':', '').replace(' ', '')) self.assertEqual(d['condensed'], d['dashed'].replace('-', ''))
def handleRequest(self): """Handle a request. Actually performs the request, creating the environment and calling self.doTransaction(env, input) to perform the response. """ self.server_version = 'Webware/' + self._server.version() env = {} if self.headers.has_key('Content-Type'): env['CONTENT_TYPE'] = self.headers['Content-Type'] del self.headers['Content-Type'] if self.headers.has_key('Content-Length'): env['CONTENT_LENGTH'] = self.headers['Content-Length'] del self.headers['Content-Length'] key = 'If-Modified-Since' if self.headers.has_key(key): env[key] = self.headers[key] del self.headers[key] self.headersToEnviron(self.headers, env) env['REMOTE_ADDR'], env['REMOTE_PORT'] = map(str, self.client_address) env['REQUEST_METHOD'] = self.command path = self.path if path.find('?') != -1: env['REQUEST_URI'], env['QUERY_STRING'] = path.split('?', 1) else: env['REQUEST_URI'] = path env['QUERY_STRING'] = '' env['SCRIPT_NAME'] = '' env['PATH'] = os.getenv('PATH', '') env['PATH_INFO'] = env['REQUEST_URI'] env['SERVER_ADDR'], env['SERVER_PORT'] = map(str, self._serverAddress) env['SERVER_SOFTWARE'] = self.server_version env['SERVER_PROTOCOL'] = self.protocol_version env['GATEWAY_INTERFACE'] = 'CGI/1.1' if self._server._verbose: uri = requestURI(env) startTime = time.time() sys.stdout.write('%5i %s %s\n' % (self._requestID, timestamp()['pretty'], uri)) self.doTransaction(env, self.rfile) if self._server._verbose: duration = ('%0.2f secs' % (time.time() - startTime)).ljust(19) sys.stdout.write('%5i %s %s\n\n' % (self._requestID, duration, uri))
def handleRequest(self): """Handle request. Creates the request dictionary, and creates a `TASStreamOut` object for the response, then calls `Application.dispatchRawRequest`, which does the rest of the work (here we just clean up after). """ verbose = self._server._verbose self._startTime = time.time() requestDict = self.receiveDict() if not requestDict: return if verbose: uri = requestDict.has_key('environ') \ and requestURI(requestDict['environ']) or '-' sys.stdout.write('%5i %s %s\n' % (self._requestID, timestamp()['pretty'], uri)) requestDict['input'] = self.makeInput() requestDict['requestID'] = self._requestID streamOut = TASStreamOut(self._sock, bufferSize=self._server._responseBufferSize) transaction = self._server._app.dispatchRawRequest(requestDict, streamOut) try: streamOut.close() aborted = False except ConnectionAbortedError: aborted = True try: self._sock.shutdown(1) self._sock.close() except Exception: pass if verbose: duration = ('%0.2f secs' % (time.time() - self._startTime)).ljust(19) sys.stdout.write('%5i %s %s\n\n' % (self._requestID, duration, aborted and '*connection aborted*' or uri)) transaction._application = None transaction.die() del transaction
def handleRequest(self): verbose = self.server._verbose startTime = time.time() if verbose: print '%5i %s ' % (self._number, timestamp()['pretty']), conn = self.sock # @@ 2001-05-30 ce: Ack! Look at this hard coding. BUFSIZE = 8 * 1024 data = [] chunk = '' missing = int_length while missing > 0: block = conn.recv(missing) if not block: conn.close() if len(chunk) == 0: # We probably awakened due to awakeSelect being called. return 0 else: # We got a partial request -- something went wrong. raise NotEnoughDataError, 'received only %d out of %d bytes when receiving dict_length' % ( len(chunk), int_length) chunk = chunk + block missing = int_length - len(chunk) dict_length = loads(chunk) if type(dict_length) != type(1): conn.close() print print "Error: Invalid AppServer protocol" return 0 chunk = '' missing = dict_length while missing > 0: block = conn.recv(missing) if not block: conn.close() raise NotEnoughDataError, 'received only %d out of %d bytes when receiving dict' % ( len(chunk), dict_length) chunk = chunk + block missing = dict_length - len(chunk) dict = loads(chunk) #if verbose: print "Comm Delay=%s" % (time.time() - dict['time']) if dict: if verbose: if dict.has_key('environ'): requestURI = Funcs.requestURI(dict['environ']) else: requestURI = None print requestURI dict['input'] = conn.makefile("rb", 8012) strmOut = TASASStreamOut(self.sock) transaction = self.server._app.dispatchRawRequest(dict, strmOut) strmOut.close() try: conn.shutdown(1) conn.close() except: pass if verbose: duration = '%0.2f secs' % (time.time() - startTime) duration = string.ljust(duration, 19) print '%5i %s %s' % (self._number, duration, requestURI) print transaction._application = None transaction.die() del transaction