<s> """<STR_LIT>""" <EOL> from flask import request , current_app <EOL> from functools import wraps <EOL> from settings import USERS as users <EOL> from app import auth <EOL> @ auth . get_password <EOL> def get_pw ( username ) : <EOL> """<STR_LIT>""" <EOL> if username in users : <EOL> return users . get ( username ) <EOL> return None <EOL> class conditional ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , dec , condition ) : <EOL> self . decorator = dec <EOL> self . condition = condition <EOL> def __call__ ( self , func ) : <EOL> if not self . condition : <EOL> return func <EOL> return self . decorator ( func ) <EOL> def obj_to_dict ( obj ) : <EOL> """<STR_LIT>""" <EOL> rv = { '<STR_LIT>' : str ( type ( obj ) ) } <EOL> if type ( obj ) in ( bool , int , long , float , str , unicode ) : <EOL> return obj <EOL> if type ( obj ) in ( list , tuple ) : <EOL> return [ obj_to_dict ( item ) for item in obj ] <EOL> if type ( obj ) == dict : <EOL> return dict ( ( str ( k ) , obj_to_dict ( v ) ) for k , v in obj . iteritems ( ) ) <EOL> return obj_to_dict ( obj . __dict__ ) <EOL> def get_server_conf ( meta , server , key ) : <EOL> """<STR_LIT>""" <EOL> val = server . getConf ( key ) <EOL> if '<STR_LIT>' == val : <EOL> val = meta . getDefaultConf ( ) . get ( key , '<STR_LIT>' ) <EOL> return val <EOL> def get_server_port ( meta , server , val = None ) : <EOL> """<STR_LIT>""" <EOL> val = server . getConf ( '<STR_LIT:port>' ) if val == None else val <EOL> if '<STR_LIT>' == val : <EOL> val = meta . getDefaultConf ( ) . get ( '<STR_LIT:port>' , <NUM_LIT:0> ) <EOL> val = int ( val ) + server . id ( ) - <NUM_LIT:1> <EOL> return int ( val ) <EOL> def get_all_users_count ( meta ) : <EOL> """<STR_LIT>""" <EOL> user_count = <NUM_LIT:0> <EOL> for s in meta . getAllServers ( ) : <EOL> user_count += ( s . isRunning ( ) and len ( s . getUsers ( ) ) ) or <NUM_LIT:0> <EOL> return user_count <EOL> def support_jsonp ( f ) : <EOL> """<STR_LIT>""" <EOL> @ wraps ( f ) <EOL> def decorated_function ( * args , ** kwargs ) : <EOL> callback = request . args . get ( '<STR_LIT>' , False ) <EOL> if callback : <EOL> content = str ( callback ) + '<STR_LIT:(>' + str ( f ( * args , ** kwargs ) . data ) + '<STR_LIT:)>' <EOL> return current_app . response_class ( content , mimetype = '<STR_LIT>' ) <EOL> else : <EOL> return f ( * args , ** kwargs ) <EOL> return decorated_function </s>
