Skip to content

Instantly share code, notes, and snippets.

Avatar

Vladimir Kozlovsky vkozlovski

View GitHub Profile
View files_twisted.py
from twisted.web import server, resource
from twisted.web.static import File
from twisted.internet import reactor
resource = File('/home/uploads/')
reactor.listenTCP(8080, server.Site(resource))
reactor.run()
View text_twisted.py
from twisted.web import server, resource
from twisted.internet import reactor
class HelloResource(resource.Resource):
isLeaf = True
def render_GET(self, request):
request.setHeader("content-type", "text/plain")
return "I am a stupid HTTP server!"
View text_eventmachine.rb
require 'rubygems'
require 'eventmachine'
require 'evma_httpserver'
class MyHttpServer < EM::Connection
include EM::HttpServer
def post_init
super
no_environment_strings
View files_tornado.py
import tornado.httpserver
import tornado.ioloop
import tornado.options
import tornado.web
from tornado.options import define, options
define("port", default=8080, help="run on the given port", type=int)
def main():
tornado.options.parse_command_line()
View text_tornado.py
import tornado.httpserver
import tornado.ioloop
import tornado.options
import tornado.web
from tornado.options import define, options
define("port", default=8080, help="run on the given port", type=int)
class MainHandler(tornado.web.RequestHandler):
View files_eventlet.py
import eventlet
from eventlet import wsgi
import os.path
upload_dir = '/home/uploads/'
def application(environ, start_response):
path = environ['PATH_INFO']
if not os.path.isfile(upload_dir + path):
start_response("404 Not Found", [('Content-type', 'text/plain')])
View text_eventlet.py
import eventlet
from eventlet import wsgi
def application(environ, start_response):
start_response('200 OK', [('Content-Type', 'text/plain')])
return ['I am a stupid HTTP server!']
wsgi.server(eventlet.listen(('', 8080)), application, log_output=None, debug=False, max_size=10000)
View gridfs_gevent.py
from gevent import monkey; monkey.patch_all()
from gevent.pywsgi import WSGIServer
from pymongo import MongoClient
from gridfs import GridFS
from gridfs.errors import NoFile
#from bson import ObjectId
import sys
db = MongoClient(max_pool_size=15).example
fs = GridFS(db)
View files_gevent.py
from gevent import monkey; monkey.patch_all()
from gevent.pywsgi import WSGIServer
import os.path
upload_dir = '/home/uploads/'
def application(environ, start_response):
path = environ['PATH_INFO']
if not os.path.isfile(upload_dir + path):
start_response("404 Not Found", [('Content-type', 'text/plain')])
View text_gevent.py
from gevent import monkey; monkey.patch_all()
from gevent.pywsgi import WSGIServer
def application(environ, start_response):
start_response('200 OK', [('Content-Type', 'text/plain')])
return [b'I am a stupid HTTP server!']
if __name__ == '__main__':
WSGIServer(('', 8080), application, log=None).serve_forever()
You can’t perform that action at this time.