<s> __version__ = '<STR_LIT>' <EOL> import sys <EOL> import logging <EOL> from SocketServer import ThreadingMixIn <EOL> from wsgiref . simple_server import WSGIServer , make_server <EOL> import flask <EOL> import pymongo <EOL> from regenwolken import views , mongonic <EOL> class ThreadedWSGIServer ( ThreadingMixIn , WSGIServer ) : <EOL> pass <EOL> class Regenwolken ( flask . Flask ) : <EOL> def __init__ ( self ) : <EOL> flask . Flask . __init__ ( self , __name__ ) <EOL> self . config . from_object ( '<STR_LIT>' ) <EOL> self . config . from_envvar ( '<STR_LIT>' , silent = True ) <EOL> if len ( sys . argv ) > <NUM_LIT:1> : <EOL> path = sys . argv [ <NUM_LIT:1> ] if sys . argv [ <NUM_LIT:1> ] . startswith ( '<STR_LIT:/>' ) else '<STR_LIT>' + sys . argv [ <NUM_LIT:1> ] <EOL> self . config . from_pyfile ( path , silent = True ) <EOL> self . setup_routes ( ) <EOL> self . setup_mongodb ( ) <EOL> self . setup_extensions ( ) <EOL> if '<STR_LIT>' in sys . argv : <EOL> self . config [ '<STR_LIT>' ] = True <EOL> if not self . config [ '<STR_LIT>' ] : <EOL> self . setup_logger ( ) <EOL> def setup_routes ( self ) : <EOL> for endpoint , rule , methods in [ <EOL> ( '<STR_LIT:index>' , '<STR_LIT:/>' , [ '<STR_LIT:GET>' , '<STR_LIT:POST>' ] ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , [ '<STR_LIT:GET>' ] ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , [ '<STR_LIT>' , '<STR_LIT:GET>' ] ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , [ '<STR_LIT:GET>' , ] ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , [ '<STR_LIT:POST>' , ] ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , [ '<STR_LIT:GET>' , ] ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , [ '<STR_LIT:GET>' , ] ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , [ '<STR_LIT:POST>' , ] ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , [ '<STR_LIT>' , '<STR_LIT:GET>' ] ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , [ '<STR_LIT:POST>' , ] ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , [ '<STR_LIT:GET>' ] ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , [ '<STR_LIT:GET>' ] ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , [ '<STR_LIT:GET>' , ] ) <EOL> ] : <EOL> self . add_url_rule ( rule , endpoint , view_func = getattr ( views , endpoint ) , methods = methods ) <EOL> def setup_mongodb ( self ) : <EOL> con = pymongo . Connection ( <EOL> self . config [ '<STR_LIT>' ] , <EOL> self . config [ '<STR_LIT>' ] <EOL> ) [ self . config [ '<STR_LIT>' ] ] <EOL> con . items . create_index ( '<STR_LIT>' ) <EOL> con . accounts . create_index ( '<STR_LIT:email>' ) <EOL> self . db = con <EOL> self . fs = mongonic . GridFS ( con ) <EOL> self . sessions = mongonic . Sessions ( con , size = self . config [ '<STR_LIT>' ] ) <EOL> def setup_logger ( self ) : <EOL> path = self . config . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> file_handler = logging . FileHandler ( path ) <EOL> file_handler . setLevel ( logging . WARNING ) <EOL> file_handler . setFormatter ( logging . Formatter ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) ) <EOL> self . logger . addHandler ( file_handler ) <EOL> def setup_extensions ( self ) : <EOL> try : <EOL> import pygments <EOL> except ImportError : <EOL> if self . config [ '<STR_LIT>' ] : <EOL> print >> sys . stderr , "<STR_LIT>" <EOL> self . config [ '<STR_LIT>' ] = False <EOL> try : <EOL> import markdown <EOL> except ImportError : <EOL> if self . config [ '<STR_LIT>' ] : <EOL> print >> sys . stderr , "<STR_LIT>" <EOL> self . config [ '<STR_LIT>' ] = False <EOL> try : <EOL> import PIL <EOL> except ImportError : <EOL> if self . config [ '<STR_LIT>' ] : <EOL> print >> sys . stderr , "<STR_LIT>" <EOL> self . config [ '<STR_LIT>' ] = False <EOL> def main ( ) : <EOL> app = Regenwolken ( ) <EOL> httpd = make_server ( <EOL> app . config [ '<STR_LIT>' ] , app . config [ '<STR_LIT>' ] , <EOL> app , server_class = ThreadedWSGIServer ) <EOL> httpd . serve_forever ( ) <EOL> try : <EOL> import uwsgi <EOL> except ImportError : <EOL> pass <EOL> else : <EOL> application = Regenwolken ( ) </s>
