def setUp(self): meep_example_app.initialize() app = meep_example_app.MeepExampleApp() self.app = app u = meeplib.User('foo', 'bar',-1) v = meeplib.User('foo2', 'bar2',-1) m = meeplib.Message('my title', 'lol', u,-1)
def process_request(request): environ = {} for line in request: line = line.strip() #print (line,) if line == '': continue if line.startswith('get') or line.startswith('post'): line = line.split() environ['REQUEST_METHOD'] = line[0] environ['PATH_INFO'] = line[1] else: line = line.split(':', 1) try: environ[headers_to_environ[line[0]]] = line[1].strip() except KeyError: pass initialize() app = MeepExampleApp() response_fn_callable = ResponseFunctionHolder() appResponse = app(environ, response_fn_callable) response = [] response.append('HTTP/1.0 ' + response_fn_callable.status) response.extend([x+': '+y for x,y in response_fn_callable.headers]) response.append('Date: ' + time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime())) response.append('Server: WSGIServer/0.1 Python/2.7') response.append('\r\n') response.extend(a for a in appResponse) return '\r\n'.join(response)
def setUp(self): meep_example_app.initialize() app = meep_example_app.MeepExampleApp() self.app = app u = meeplib.User('foo', 'bar', -1) v = meeplib.User('foo2', 'bar2', -1) m = meeplib.Message('my title', 'lol', u, -1)
def setUp(self): #the backup data causes some of the tests to fail - not sure why #remove the backup data before every test cur.execute("DELETE FROM MESSAGE") cur.execute("DELETE FROM SESSION") cur.execute("DELETE FROM USER") con.commit() meep_example_app.meeplib._users = {} meep_example_app.meeplib._messages = {} meep_example_app.meeplib._user_ids= {} meep_example_app.initialize() app = meep_example_app.MeepExampleApp() self.app = app cur.execute("INSERT INTO SESSION(ID, USER_ID) VALUES('studentx',%d)" % (meep_example_app.meeplib.get_user('studentx').id)) con.commit()
def setUp(self): #the backup data causes some of the tests to fail - not sure why #remove the backup data before every test cur.execute("DELETE FROM MESSAGE") cur.execute("DELETE FROM SESSION") cur.execute("DELETE FROM USER") con.commit() meep_example_app.meeplib._users = {} meep_example_app.meeplib._messages = {} meep_example_app.meeplib._user_ids = {} meep_example_app.initialize() app = meep_example_app.MeepExampleApp() self.app = app cur.execute("INSERT INTO SESSION(ID, USER_ID) VALUES('studentx',%d)" % (meep_example_app.meeplib.get_user('studentx').id)) con.commit()
def buildResponse(webRequest): #parse request requestMap = {'wsgi.input' : ''} for line in webRequest: line = line.strip() #remove leading and trailing whitespace if (line.startswith('GET') or line.startswith('POST')): line = line.split() requestMap['REQUEST_METHOD'] = line[0] if line[1].find('?') == -1: requestMap['PATH_INFO'] = line[1] else: tmpPath = line[1].split('?') requestMap['PATH_INFO'] = tmpPath[0] requestMap['QUERY_STRING'] = tmpPath[1] else: try: line = line.split(':',1) requestMap[environMap[line[0].lower()]] = line[1].strip() except: pass #build response initialize() app = MeepExampleApp() response = app(requestMap, fake_start_response) output = [] output.append('HTTP/1.0 ' + _status) currentTime = datetime.datetime.now() output.append('Date: ' + currentTime.strftime('%a, %d %b %Y %H:%M:%S EST')) output.append('Server: WSGIServer/0.1 Python/2.5') for tmpHeader in _headers: output.append(tmpHeader[0] + ': ' + tmpHeader[1]) output.append('\r\n') for r in response: output.append(r) return '\r\n'.join(output)
def buildResponse(webRequest): #parse request requestMap = {'wsgi.input': ''} for line in webRequest: line = line.strip() #remove leading and trailing whitespace if (line.startswith('GET') or line.startswith('POST')): line = line.split() requestMap['REQUEST_METHOD'] = line[0] if line[1].find('?') == -1: requestMap['PATH_INFO'] = line[1] else: tmpPath = line[1].split('?') requestMap['PATH_INFO'] = tmpPath[0] requestMap['QUERY_STRING'] = tmpPath[1] else: try: line = line.split(':', 1) requestMap[environMap[line[0].lower()]] = line[1].strip() except: pass #build response initialize() app = MeepExampleApp() response = app(requestMap, fake_start_response) output = [] output.append('HTTP/1.0 ' + _status) currentTime = datetime.datetime.now() output.append('Date: ' + currentTime.strftime('%a, %d %b %Y %H:%M:%S EST')) output.append('Server: WSGIServer/0.1 Python/2.5') for tmpHeader in _headers: output.append(tmpHeader[0] + ': ' + tmpHeader[1]) output.append('\r\n') for r in response: output.append(r) return '\r\n'.join(output)
from meep_example_app import MeepExampleApp, initialize from wsgiref.simple_server import make_server initialize() app = MeepExampleApp() httpd = make_server("", 8000, app) print "Serving HTTP on port 8000..." # Respond to requests until process is killed httpd.serve_forever() # Alternative: serve one request, then exit httpd.handle_request() # updated 11/18/2011
from meep_example_app import MeepExampleApp, initialize from wsgiref.simple_server import make_server initialize() app = MeepExampleApp() httpd = make_server('', 8000, app) print "Serving HTTP on port 8000..." # Respond to requests until process is killed httpd.serve_forever() # Alternative: serve one request, then exit httpd.handle_request() #updated 11/18/2011
import cgi, meep_example_app, time, meepcookie, sys, socket, StringIO, urllib, ResponseBuilder if __name__ == '__main__': meep_example_app.initialize() interface, port = sys.argv[1:3] port = int(port) print 'Binding', interface, port sock = socket.socket() sock.bind((interface, port)) sock.listen(5) while 1: print 'Waiting for HTTP Request...' (client_sock, client_address) = sock.accept() print 'got connection', client_address ResponseBuilder.handle_connection(client_sock)
def setUp(self): meep_example_app.initialize() app = meep_example_app.MeepExampleApp() self.app = app
sock.sendall(data) print "data sent" else: print 'No data' sock.close() print "Done" if __name__ == '__main__': #interface, port = sys.argv[1:3] port = 80 interface = 'localhost' meep_example_app.initialize() print 'binding', interface, port sock = socket.socket() sock.bind( (interface, port) ) sock.listen(5) #threads = [] while 1: print 'waiting...' (client_sock, client_address) = sock.accept() print 'got connection', client_address #print client_sock #t1 = threading.Thread(target=handle_connection, args=(client_sock,)); #t1.start() handle_connection(client_sock)
def setUp(self): meep_example_app.initialize() app = meep_example_app.MeepExampleApp() self.app = app meep_example_app.meeplib.delete_curr_user()